https://github.com/wronai/shapi
from shell to api
https://github.com/wronai/shapi
api bash cline cursor generator llm mistral ollama rest script shell windsurf
Last synced: about 2 months ago
JSON representation
from shell to api
- Host: GitHub
- URL: https://github.com/wronai/shapi
- Owner: wronai
- License: apache-2.0
- Created: 2025-06-08T10:56:52.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-08T19:26:43.000Z (about 1 year ago)
- Last Synced: 2026-03-15T08:19:43.592Z (3 months ago)
- Topics: api, bash, cline, cursor, generator, llm, mistral, ollama, rest, script, shell, windsurf
- Language: HTML
- Homepage: https://wronai.github.io/shapi/
- Size: 677 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
โจ shapi
Transform shell scripts into production-ready APIs with REST, WebRTC, and gRPC support
[](https://pypi.org/project/shapi/)
[](https://pypi.org/project/shapi/)
[](https://github.com/wronai/shapi/blob/main/LICENSE)
[](https://github.com/psf/black)
[](https://wronai.github.io/shapi/)
[](https://github.com/wronai/shapi/actions)
[](https://codecov.io/gh/wronai/shapi)
[๐ Quick Start](#-quick-start) |
[๐ Documentation](https://wronai.github.io/shapi/) |
[๐ก Examples](#-examples) |
[๐ค Contributing](#-contributing) |
[๐ License](#-license)
## โจ Features
- ๐ **Instant API Generation**: Convert any shell script into a REST API with a single command
- ๐ค **AI-Powered**: Leverage local LLM (Mistral:7b) for intelligent API generation
- ๐ณ **Container Ready**: Automatic Dockerfile and docker-compose.yml generation
- ๐ **Multi-Protocol**: Support for REST, WebRTC, and gRPC APIs
- ๐งช **Testing Included**: Generated test suites and Ansible playbooks
- ๐ **Monitoring**: Built-in health checks and status endpoints
- ๐ง **Service Management**: Start, stop, and manage multiple services
- ๐ฆ **Port Management**: Automatic port conflict resolution
- ๐ฏ **Daemon Mode**: Run services in the background
- ๐ **Service Discovery**: List and manage running services
## ๐ฆ Installation
```bash
# Install using pip
pip install shapi
# Or install from source
git clone https://github.com/wronai/shapi.git
cd shapi
pip install -e .
```
## ๐ Quick Start
### Serve a Script
```bash
# Serve a script directly
shapi serve ./examples/echo.sh --port 8000
# Or run it as a daemon
shapi serve ./examples/echo.sh --name echo-service --port 8000 --daemon
# List running services
shapi service list
```
### Manage Services
```bash
# List all running services
shapi service list
# Stop a service
shapi service stop service-name
# Restart a service
shapi service restart service-name
# Force stop if port is in use
shapi serve ./script.sh --port 8000 --force
```
### Generate Service Structure
```bash
# Generate complete service structure with Docker and tests
shapi generate /path/to/your/script.sh --name my-service
# Navigate to the generated service
cd my-service
# Install dependencies and run
pip install -r requirements.txt
python main.py
```
## ๐ Documentation
- [Examples](./examples/README.md) - Detailed documentation of example scripts
- [API Reference](https://wronai.github.io/shapi/) - Complete API documentation
- [Development Guide](./CONTRIBUTING.md) - How to contribute to ShAPI
## ๐ Examples
ShAPI comes with several example scripts that demonstrate its capabilities:
1. `ls.sh` - List directory contents
2. `ps.sh` - Show running processes
3. `df.sh` - Display disk usage
4. `free.sh` - Show memory usage
5. `whoami.sh` - Display current user information
6. `date.sh` - Show current date/time with formatting
7. `echo.sh` - Echo back input text
See the [examples documentation](./examples/README.md) for detailed usage and API examples.
## ๐ ๏ธ Project Structure
```
my-service/
โโโ main.py # FastAPI service
โโโ Dockerfile # Container configuration
โโโ docker-compose.yml # Multi-service setup
โโโ Makefile # Build and deployment commands
โโโ requirements.txt # Python dependencies
โโโ test_service.py # Test suite
โโโ ansible/ # Infrastructure tests
โ โโโ test.yml
โโโ script.sh # Your original script
```
## Usage Examples
### Basic Script Conversion
```bash
#!/bin/bash
# hello.sh
echo "Hello, $1!"
```
Generate the service:
```bash
shapi generate hello.sh --name greeting-service
cd greeting-service
python main.py
```
Access your API:
- **Health Check**: `GET http://localhost:8000/health`
- **Documentation**: `GET http://localhost:8000/docs`
- **Execute Script**: `POST http://localhost:8000/run`
### API Endpoints
Every generated service includes:
- `GET /health` - Service health check
- `GET /info` - Script information
- `POST /run` - Execute script (sync/async)
- `GET /status/{task_id}` - Check async task status
- `GET /docs` - Interactive API documentation
## Service Management
### Managing Multiple Services
```bash
# Start multiple services on different ports
shapi serve ./service1.sh --name service1 --port 8000 --daemon
shapi serve ./service2.sh --name service2 --port 8001 --daemon
# List all running services
shapi service list
# Output:
# โโโโโโโโโโโโโณโโโโโโโโโณโโโโโโโณโโโโโโโโโโณโโโโโโโโโโโณโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# โ Name โ PID โ Port โ Status โ Uptime โ Script โ
# โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
# โ service1 โ 12345 โ 8000 โ running โ 00:05:32 โ /path/to/service1.sh โ
# โ service2 โ 12346 โ 8001 โ running โ 00:02:15 โ /path/to/service2.sh โ
# โโโโโโโโโโโโโดโโโโโโโโโดโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
# Stop a service
shapi service stop service1
# Force stop a service if it's not responding
shapi service stop service2 --force
# Restart a service
shapi service restart service1
```
### Port Management
```bash
# Start a service with automatic port conflict resolution
shapi serve ./service.sh --port 8000 --force
# The --force flag will automatically stop any service using port 8000
```
### Example API Request
```json
POST /run
{
"parameters": {
"name": "World",
"verbose": true
},
"async_execution": false
}
```
### Docker Deployment
```bash
# Build and run with Docker
make docker-build
make docker-run
# Or use docker-compose
docker-compose up -d
```
### Testing
```bash
# Run tests
make test
# Or directly
python -m pytest test_service.py -v
```
## Configuration
Create a `config.yaml` file for advanced configuration:
```yaml
service:
name: "my-advanced-service"
description: "Advanced shell script API"
version: "1.0.0"
protocols:
rest: true
grpc: true
webrtc: true
security:
auth_required: false
cors_enabled: true
monitoring:
health_check_interval: 30
metrics_enabled: true
```
## CLI Commands
```bash
# Generate service structure
shapi generate hello.sh --name service-name --output ./output
# Serve script directly
shapi serve hello.sh --host 0.0.0.0 --port 8008
# Test generated service
shapi test ./generated/service-name
# Build Docker image
shapi build ./generated/service-name
```
## Advanced Features
### Async Execution
```python
# Enable async execution for long-running scripts
response = requests.post("/run", json={
"parameters": {"input": "data"},
"async_execution": True
})
task_id = response.json()["task_id"]
# Check status
status = requests.get(f"/status/{task_id}")
```
### Multiple Protocols
The generated service supports multiple communication protocols:
- **REST API**: Standard HTTP endpoints
- **WebRTC**: Real-time data streaming
- **gRPC**: High-performance RPC calls
### Production Deployment
```bash
# Using Makefile
make deploy
# Manual deployment
docker-compose up -d
```
## Requirements
- Python 3.8+
- Docker (optional, for containerization)
- Bash (for shell script execution)
## Contributing
Contributions are welcome! Please see our [Contributing Guidelines](CONTRIBUTING.md).
## License
Apache License 2.0 - see [LICENSE](LICENSE) file for details.
## Support
- ๐ [Documentation](https://wronai.github.io/shapi)
- ๐ [Issue Tracker](https://github.com/wronai/shapi/issues)
- ๐ฌ [Discussions](https://github.com/wronai/shapi/discussions)
---
**shapi** - From shell to service in seconds! ๐
# Contributing Guidelines
# CONTRIBUTING.md
"""
# Contributing to shapi
We welcome contributions to shapi! This document provides guidelines for contributing.
## Development Setup
1. Clone the repository:
```bash
git clone https://github.com/wronai/shapi.git
cd shapi
```
2. Create virtual environment:
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. Install in development mode:
```bash
pip install -e .[dev]
```
## Running Tests
```bash
# Run all tests
pytest
# Run with coverage
pytest --cov=shapi
# Run specific test file
pytest tests/test_core.py -v
```
## Code Style
We use black for code formatting and flake8 for linting:
```bash
# Format code
black shapi/
# Check linting
flake8 shapi/
```
## Submitting Changes
1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Add tests for new functionality
5. Ensure all tests pass
6. Submit a pull request
## Reporting Issues
Please use the GitHub issue tracker to report bugs or request features.
"""