✨ shapi
Transform shell scripts into production-ready APIs with REST, WebRTC, and gRPC support
🚀 Quick Start | 📖 Documentation | 💡 Examples | 🤝 Contributing | 📄 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
# 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
# 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
# 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
# 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 - Detailed documentation of example scripts
- API Reference - Complete API documentation
- Development Guide - How to contribute to ShAPI
🔍 Examples
ShAPI comes with several example scripts that demonstrate its capabilities:
ls.sh- List directory contentsps.sh- Show running processesdf.sh- Display disk usagefree.sh- Show memory usagewhoami.sh- Display current user informationdate.sh- Show current date/time with formattingecho.sh- Echo back input text
See the examples documentation 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
#!/bin/bash
# hello.sh
echo "Hello, $1!"
Generate the service:
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 checkGET /info- Script informationPOST /run- Execute script (sync/async)GET /status/{task_id}- Check async task statusGET /docs- Interactive API documentation
Service Management
Managing Multiple Services
# 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
# 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
POST /run
{
"parameters": {
"name": "World",
"verbose": true
},
"async_execution": false
}
Docker Deployment
# Build and run with Docker
make docker-build
make docker-run
# Or use docker-compose
docker-compose up -d
Testing
# Run tests
make test
# Or directly
python -m pytest test_service.py -v
Configuration
Create a config.yaml file for advanced configuration:
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
# 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
# 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
# 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.
License
Apache License 2.0 - see LICENSE file for details.
Support
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
- Clone the repository:
git clone https://github.com/wronai/shapi.git
cd shapi
- Create virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install in development mode:
pip install -e .[dev]
Running Tests
# 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:
# Format code
black shapi/
# Check linting
flake8 shapi/
Submitting Changes
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
Reporting Issues
Please use the GitHub issue tracker to report bugs or request features. """
Metadata
Release files for shapi 0.2.14
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| shapi-0.2.14.tar.gz | 25.2 kB | Without provenance | Details for shapi-0.2.14.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| shapi-0.2.14-py3-none-any.whl | Python 3 | none | any | Details for shapi-0.2.14-py3-none-any.whl |
Total release size: 51.1 kB
Release files / shapi-0.2.14.tar.gz
| Download URL | shapi-0.2.14.tar.gz |
|---|---|
| Size | 25.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
94881c63ab4cd0520ea19ab31411f4dd69fc2da8400a21d2a56053166fa903e6
|
|
BLAKE2b-256 checksum How to use checksums |
f1c1d282ca5b99c8265c6c1580e821a6f4f4136d22004bd55e662d48172e435b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.9 Linux/6.14.9-300.fc42.x86_64
|
Release files / shapi-0.2.14-py3-none-any.whl
| Download URL | shapi-0.2.14-py3-none-any.whl |
|---|---|
| Size | 25.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a662ef6bb6909cded9b3e75a0aa47a0a72d49e49547e5b8f0a38046d28185fa9
|
|
BLAKE2b-256 checksum How to use checksums |
365b1495420497826ffe1a4e3769f2a6d6bdcccd86cb237a4d6dc9799b485b27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.9 Linux/6.14.9-300.fc42.x86_64
|
Security for shapi 0.2.14
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.