Skip to main content

A Python library for building task-based workflows with scheduling, webhooks, artifact management, and observability

Project description

Task Framework

A Python library for building and executing task-based workflows with built-in support for scheduling, webhooks, artifact management, and observability.

Features

  • Multi-Task Server: Deploy multiple task definitions to a single server, each with isolated execution environments
  • Thread Execution: Run tasks synchronously or asynchronously with full state management
  • Artifact Management: Track inputs and outputs with support for JSON, text, and file artifacts
  • File Storage: Pluggable file storage interface with local filesystem and pre-signed URL support
  • Scheduling: Cron-based scheduling with APScheduler integration
  • Webhooks: Event-driven notifications with automatic retry and delivery tracking
  • Observability: Built-in Prometheus metrics and structured logging
  • OpenAPI 3.1.0: Auto-generated API documentation at /docs

Installation

pip install task-framework

Or with uv:

uv add task-framework

Quick Start

Multi-Task Server

The Task Framework runs as a server that can host multiple task definitions. Each task is packaged as a zip file with its code and metadata.

Start a task server:

# Start server with auto-discovery from task_definitions/ directory
task-framework serve --host 0.0.0.0 --port 3000

# Or for development, load a task from source
task-framework serve --dev-task /path/to/my-task/

Deploy a task via API:

curl -X POST http://localhost:3000/admin/tasks \
  -H "X-API-Key: your-admin-key" \
  -F "file=@my-task-1.0.0.zip"

Task Zip Structure:

my-task-1.0.0.zip/
  task_metadata.json    # Task metadata and schemas
  task.py              # Task implementation
  pyproject.toml       # Dependencies (optional)

Example Task Function:

async def my_task(context):
    # Get input artifacts
    inputs = await context.get_input_artifacts()
    
    # Process inputs
    result = {"message": "Task completed", "input_count": len(inputs)}
    
    # Publish output
    from task_framework.models.artifact import Artifact
    await context.publish_output_artifacts([
        Artifact(kind="json", value=result, media_type="application/json")
    ])

## API Usage

### Create a Thread (Execute Task)

```bash
curl -X POST http://localhost:3000/threads \
  -H "X-API-Key: your-api-key" \
  -H "X-User-Id: user123" \
  -H "X-App-Id: app456" \
  -H "Content-Type: application/json" \
  -d '{
    "mode": "sync",
    "inputs": [{"kind": "json", "value": {"data": "test"}}]
  }'

In multi-task mode, add ?task_id=my-task&version=1.0.0 query parameters.

List Threads

curl http://localhost:3000/threads \
  -H "X-API-Key: your-api-key" \
  -H "X-User-Id: user123" \
  -H "X-App-Id: app456"

Health Check

curl http://localhost:3000/health

Task Package Format

A task package is a zip file containing:

my-task-1.0.0.zip/
  task_metadata.json    # Task metadata
  task.py              # Task implementation
  pyproject.toml       # Dependencies

Example task_metadata.json:

{
  "name": "my-task",
  "version": "1.0.0",
  "description": "My task description",
  "entry_point": "task:my_task_function",
  "input_schemas": [
    {"kind": "json", "media_type": "application/json", "required": true}
  ],
  "output_schemas": [
    {"kind": "json", "media_type": "application/json"}
  ]
}

Documentation

  • API Documentation: Start the server and visit /docs for interactive Swagger UI
  • User Guide: See docs/user/ for getting started guides
  • Architecture: See docs/architecture/ for system design documentation
  • Feature Documentation: See docs/features/ for detailed feature documentation

Authentication

The framework uses API key authentication via the X-API-Key header:

  • Regular API Keys: Require user_id and app_id metadata for access control
  • Admin API Keys: Full access to all endpoints including /admin/* routes

Public endpoints (no authentication required):

  • GET /health - Health check
  • GET /metrics - Prometheus metrics
  • GET /task/metadata - Task metadata discovery

Requirements

  • Python 3.13+
  • FastAPI
  • Pydantic 2.x
  • uvicorn

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please see the development documentation in docs/developer/ for setup instructions.

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

task_framework_py-0.0.4b0.tar.gz (310.6 kB view details)

Uploaded Source

Built Distribution

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

task_framework_py-0.0.4b0-py3-none-any.whl (410.2 kB view details)

Uploaded Python 3

File details

Details for the file task_framework_py-0.0.4b0.tar.gz.

File metadata

  • Download URL: task_framework_py-0.0.4b0.tar.gz
  • Upload date:
  • Size: 310.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for task_framework_py-0.0.4b0.tar.gz
Algorithm Hash digest
SHA256 8ecac580782137ef4951647bb3bbfab904ec20143dda570ed9ee66ce7baa1ab1
MD5 8e6e8628d237e5230ae563b15b466fcf
BLAKE2b-256 a802a7e1b10850c0108d6417b33b968be6e378dae25d5ad7d434d587161801c6

See more details on using hashes here.

File details

Details for the file task_framework_py-0.0.4b0-py3-none-any.whl.

File metadata

File hashes

Hashes for task_framework_py-0.0.4b0-py3-none-any.whl
Algorithm Hash digest
SHA256 312d52bc4a5daf956564ad3a9e21c2e05c6e22f9f0ff4e0845cbdd87a60a803f
MD5 d5d73b47b4f6d86fc9046f834ad9d901
BLAKE2b-256 33191d277f6e394b9f804abc119a48b0facbf6fd788e4d873c62b4b9b7434e42

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