PraisonAI Service Framework
A unified framework that turns any PraisonAI Python package into a web service on Azure using just one file per package.
Features
✅ One-file service creation - Only an app.py file needed
✅ Azure-native - Uses Container Apps, Blob Storage, Queue, Table Storage
✅ Cost-predictable - Scale-to-zero, hard-capped replicas (£15-25/month)
✅ Production-ready - Retry logic, idempotency, monitoring
✅ Secure - API keys, rate limiting, CORS
✅ Fast - Built with FastAPI and async/await
Quick Start
Installation
# Using uv (recommended)
uv pip install praisonai-svc
# Using pip
pip install praisonai-svc
Create a New Service
praisonai-svc new my-service
cd my-service
Implement Your Application
Edit app.py - customize the job processing logic:
from dotenv import load_dotenv
from praisonai_svc import ServiceApp
# Load environment variables from .env file
load_dotenv()
app = ServiceApp("My Service")
@app.job
def process_job(payload: dict) -> tuple[bytes, str, str]:
"""Process job and return file data."""
# Your processing logic here
title = payload.get('title', 'Untitled')
content = f"Processed: {title}\n\nFull payload:\n{payload}"
return (
content.encode(), # File content as bytes
"text/plain", # Content type
"result.txt" # Filename
)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8080)
Configure Environment
Create .env:
PRAISONAI_AZURE_STORAGE_CONNECTION_STRING=your_connection_string
PRAISONAI_API_KEY=your_secret_key
Run the Service
Test the API
# Create a job
curl -X POST http://localhost:8080/jobs \
-H "Content-Type: application/json" \
-d '{"payload": {"title": "My First Job", "data": "test"}}'
# Check job status (replace {job_id} with actual ID from response)
curl http://localhost:8080/jobs/{job_id}
# Get download URL
curl http://localhost:8080/jobs/{job_id}/download
# Download the result file
curl "$(curl -s http://localhost:8080/jobs/{job_id}/download | jq -r .download_url)"
Local Testing
Test locally in 4 simple steps:
1. Install
pip install praisonai-svc
2. Create Service
praisonai-svc new my-service
cd my-service
3. Set Up Azure (Choose One)
Option A: Local Testing (No Azure Account)
# Install and start Azurite
npm install -g azurite
azurite --silent
# Use this in .env:
PRAISONAI_AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;"
Option B: Real Azure
# Get from Azure Portal → Storage Account → Access Keys
PRAISONAI_AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=https;..."
4. Run & Test
# Start service
python app.py
# Test (in another terminal)
curl http://localhost:8080/health
curl -X POST http://localhost:8080/jobs \
-H "Content-Type: application/json" \
-d '{"payload": {"title": "Test"}}'
That's it! ✅
Architecture
┌─────────────┐
│ WordPress │
│ Chatbot │
└──────┬──────┘
│ POST /jobs
▼
┌─────────────────────────────────────┐
│ Azure Container App (FastAPI) │
│ ┌──────────┐ ┌──────────┐ │
│ │ API │ │ Worker │ │
│ └────┬─────┘ └─────┬────┘ │
└───────┼──────────────────┼──────────┘
│ │
▼ ▼
┌─────────┐ ┌─────────┐
│ Table │ │ Queue │
│ Storage │ │ Storage │
└─────────┘ └─────────┘
│
▼
┌─────────┐
│ Blob │
│ Storage │
└─────────┘
API Endpoints
| Method |
Path |
Description |
| POST |
/jobs |
Create new job |
| GET |
/jobs/{id} |
Get job status |
| GET |
/jobs/{id}/download |
Get fresh download URL |
| GET |
/health |
Health check |
Configuration
All configuration via environment variables with PRAISONAI_ prefix:
# Required
PRAISONAI_AZURE_STORAGE_CONNECTION_STRING=...
# Optional
PRAISONAI_API_KEY=secret
PRAISONAI_CORS_ORIGINS=["https://example.com"]
PRAISONAI_MAX_JOB_DURATION_MINUTES=10
PRAISONAI_MAX_RETRY_COUNT=3
Deployment
Azure Container Apps
Quick deploy:
# Build and push image
docker build -t myregistry.azurecr.io/my-service:latest .
docker push myregistry.azurecr.io/my-service:latest
# Deploy to Azure Container Apps
az containerapp create \
--name my-service \
--resource-group my-rg \
--environment my-env \
--image myregistry.azurecr.io/my-service:latest \
--target-port 8080 \
--ingress external \
--min-replicas 0 \
--max-replicas 3
Security
Official Package
⚠️ The only official package is: praisonai-svc
Install via:
pip install praisonai-svc
Typosquatting Protection
We maintain a defensive package for common typo:
praisonai-svcs (plural) → redirects to praisonai-svc
PyPI's built-in name similarity protection prevents other typosquatting attempts.
Report Security Issues
GitHub Issues: https://github.com/MervinPraison/PraisonAI-SVC/issues
Development
# Clone repository
git clone https://github.com/MervinPraison/PraisonAI-SVC.git
cd praisonai-svc
# Install with dev dependencies
uv pip install -e ".[dev]"
# Run tests
pytest
# Format code
black src/
ruff check src/ --fix
# Type check
mypy src/
Version Management
When incrementing the version, update these files:
pyproject.toml - Line 3: version = "X.Y.Z"
src/praisonai_svc/cli.py - Line 7: @click.version_option(version="X.Y.Z")
tests/AUTOTESTING.md - Lines 445-447: Update version references
Version numbering (Semantic Versioning):
- Patch (X.Y.Z) - Bug fixes only:
1.2.0 → 1.2.1
- Minor (X.Y.0) - New features, backward compatible:
1.2.0 → 1.3.0
- Major (X.0.0) - Breaking changes:
1.2.0 → 2.0.0
Example:
# For a new feature (minor version bump)
# 1. Update pyproject.toml: version = "1.3.0"
# 2. Update cli.py: @click.version_option(version="1.3.0")
# 3. Update AUTOTESTING.md: Framework Version: 1.3.0
# 4. Commit and tag
git commit -am "Bump version to 1.3.0"
git tag v1.3.0
Project Structure
praisonai-svc/
├── src/praisonai_svc/ # Main package
│ ├── __init__.py # Package exports
│ ├── app.py # ServiceApp class
│ ├── worker.py # Worker with exponential backoff
│ ├── cli.py # CLI commands
│ ├── models/ # Data models
│ └── azure/ # Azure integrations
├── tests/ # Test suite (20 tests)
├── examples/ # Example services
├── pyproject.toml # Package configuration
├── Dockerfile # Container image
└── LICENSE # MIT License
Key Features
Core Framework
- ServiceApp class - FastAPI app factory
- @app.job decorator - Simple handler registration
- Automatic API generation - 4 endpoints created automatically
- CORS middleware - Configurable cross-origin support
- Idempotency - SHA256 JobHash prevents duplicate processing
Azure Integration
- Blob Storage - File storage with retry logic (3 attempts)
- Queue Storage - Job queue with poison queue for failures
- Table Storage - Job state tracking with retry logic
- SAS URLs - On-demand secure download links (1h expiry)
Reliability
- Exponential backoff - Worker polling (1s → 30s)
- Retry logic - Max 3 attempts before poison queue
- Timeout detection - 10 minute job timeout
- Error handling - Comprehensive error messages
CLI Commands
praisonai-svc new <name>
Purpose: Create a new service from template
Usage:
praisonai-svc new my-service
# or with package integration
praisonai-svc new my-service --package praisonaippt
What it does:
- Creates a new directory with your service name
- Generates
app.py with ServiceApp boilerplate
- Creates
.env.example with required configuration
- Creates
README.md with setup instructions
- Generates
pyproject.toml with dependencies
Output:
✅ Service created: my-service/
├── app.py
├── .env.example
├── README.md
└── pyproject.toml
Next steps after creation:
cd my-service
cp .env.example .env
# Edit .env with your Azure credentials
# Edit app.py to implement your logic
praisonai-svc run
Purpose: Run the service locally for development
Usage:
cd my-service
praisonai-svc run
What it does:
- Loads environment variables from
.env
- Starts FastAPI server on
http://localhost:8080
- Starts worker process for job processing
- Enables hot-reload for development
Output:
INFO: Started server process [12345]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8080
Test it:
# Health check
curl http://localhost:8080/health
# Create a job
curl -X POST http://localhost:8080/jobs \
-H "Content-Type: application/json" \
-d '{"payload": {"title": "Test"}}'
praisonai-svc deploy
Purpose: Deploy service to Azure Container Apps
Usage:
cd my-service
praisonai-svc deploy
What it does:
- Validates Azure CLI is installed and authenticated
- Builds Docker image from your service
- Pushes image to Azure Container Registry
- Creates/updates Azure Container App
- Configures environment variables
- Sets up scaling rules (min 0, max 3 replicas)
Prerequisites:
- Azure CLI installed:
brew install azure-cli
- Logged in:
az login
- Resource group and container registry created
Output:
🔨 Building Docker image...
✅ Image built: myregistry.azurecr.io/my-service:latest
📤 Pushing to Azure Container Registry...
✅ Image pushed
🚀 Deploying to Azure Container Apps...
✅ Deployed: https://my-service.azurecontainerapps.io
📊 Service URL: https://my-service.azurecontainerapps.io
What happens:
- Service is deployed with scale-to-zero (no cost when idle)
- Auto-scales based on HTTP requests (0-3 replicas)
- Environment variables from
.env are configured
- HTTPS endpoint is automatically provisioned
praisonai-svc logs
Purpose: View real-time logs from deployed service