Skip to main content

A unified framework that turns any PraisonAI Python package into a web service on Azure

Project description

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 a handlers.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 --package praisonaippt
cd my-service

Implement Your Handler

Edit handlers.py:

import io
from praisonai_svc import ServiceApp
from praisonaippt import build_ppt

app = ServiceApp("PraisonAI PPT")

@app.job
def generate_ppt(payload: dict) -> tuple[bytes, str, str]:
    """Generate PowerPoint from YAML."""
    buf = io.BytesIO()
    build_ppt(payload, out=buf)
    return (
        buf.getvalue(),
        "application/vnd.openxmlformats-officedocument.presentationml.presentation",
        "slides.pptx",
    )

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app.get_app(), 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 Locally

python handlers.py

Test the API

# Create a job
curl -X POST http://localhost:8080/jobs \
  -H "Content-Type: application/json" \
  -d '{"payload": {"title": "My Presentation"}}'

# Check job status
curl http://localhost:8080/jobs/{job_id}

# Download result
curl http://localhost:8080/jobs/{job_id}/download

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

See deployment guide for full instructions.

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 defensive packages for common typos:

  • praisonaisvc → redirects to praisonai-svc
  • praisonai_svc → redirects to praisonai-svc
  • praisonai-svcs → redirects to praisonai-svc

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/

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
├── defensive-packages/         # Typosquatting protection
├── 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>      # Create new service
praisonai-svc run              # Run locally
praisonai-svc deploy           # Deploy to Azure
praisonai-svc logs             # Tail logs

Testing

# Run all tests
pytest

# Run with coverage
pytest --cov=praisonai_svc

# Run specific test file
pytest tests/test_integration.py -v

Test Results: 20/20 tests passing ✅

Examples

See examples/ directory:

  • examples/ppt-service/ - PowerPoint generation example

Documentation

License

MIT License - see LICENSE file

Contributing

Contributions welcome! See CONTRIBUTING.md

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

praisonai_svc-1.0.0.tar.gz (137.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

praisonai_svc-1.0.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file praisonai_svc-1.0.0.tar.gz.

File metadata

  • Download URL: praisonai_svc-1.0.0.tar.gz
  • Upload date:
  • Size: 137.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for praisonai_svc-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2b8e433fed2bd12968247b9b63dca81d912913ad5eccc8ad64b1eecb638aec0f
MD5 68335332e56adc03668ab398ee98923a
BLAKE2b-256 44b3ecbb03f9ccd403a70ff22538294d7302833fd069160481081a17b9303ecc

See more details on using hashes here.

File details

Details for the file praisonai_svc-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for praisonai_svc-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9528bab9ff3fc4146de7a0eec0b55a956fd86d5dc0da3ebe1f2e9eeb202bae6b
MD5 100487daae1f35d5331ec0fca4fdffdb
BLAKE2b-256 1d3faf4fd899706b0b8d087e1dc7e46dfd6f901c5049f12f77fe25b20cbb4389

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page