Skip to main content

alavida-sdk

Python SDK for building Alavida platform components.

Install

pip install alavida-sdk

# With FastAPI helpers:
pip install "alavida-sdk[fastapi]"

Quick Start (FastAPI)

from fastapi import FastAPI, Depends
from alavida_sdk import (
    ComponentSchema, ActionSchema, define_schema,
    complete_job, fail_job, update_progress,
)
from alavida_sdk.fastapi import AlavidaMiddleware, require_auth
from alavida_sdk.types import AuthContext

app = FastAPI()
app.add_middleware(AlavidaMiddleware)  # rejects direct access, allows /health + /schema

# 1. Declare your schema
SCHEMA = ComponentSchema(
    slug="buying-signals",
    name="Buying Signals",
    type="workflow",
    version="1.0.0",
    actions={
        "run": ActionSchema(
            description="Detect buying signals for a list of companies",
            input_schema={
                "type": "object",
                "required": ["companies"],
                "properties": {
                    "companies": {"type": "array", "items": {"type": "object"}},
                },
            },
            output_schema={
                "type": "object",
                "properties": {
                    "companies": {"type": "array"},
                    "summary": {"type": "object"},
                },
            },
        ),
    },
)

@app.get("/health")
async def health():
    return {"status": "ok", "version": "1.0.0"}

@app.get("/schema")
async def schema():
    return define_schema(SCHEMA)

# 2. Handle execution — read auth context from gateway headers
@app.post("/run")
async def run(ctx: AuthContext = Depends(require_auth)):
    input_data = ...  # parse request body

    # Start background processing, return 202
    # When done, call complete_job()
    return {"status": "accepted"}

# 3. After background work finishes:
async def on_complete(callback_url: str, result: dict, credits: int):
    await complete_job(callback_url, result=result, credits_used=credits)

async def on_failure(callback_url: str, error: Exception):
    await fail_job(callback_url, error_code="processing_failed", error_message=str(error))

API Reference

Core (framework-agnostic)

Function Description
get_auth_context(headers) Extract AuthContext from any headers mapping
define_schema(schema) Convert ComponentSchema to JSON-serializable dict
complete_job(url, result=, credits_used=) Async — notify gateway of successful completion
fail_job(url, error_code=, error_message=) Async — notify gateway of failure
update_progress(url, progress=) Async — update job progress (0-100)

FastAPI Helpers (alavida_sdk.fastapi)

Export Description
AlavidaMiddleware Middleware — rejects requests without gateway headers (skips /health, /schema)
require_auth Depends() — injects AuthContext into route handlers

Types

Model Fields
ComponentSchema slug, name, type, version, actions
ActionSchema description, input_schema, output_schema
AuthContext team_id, user_id, job_id, callback_url?

Exceptions

Exception When
AlavidaAuthError Required X-Alavida-* headers are missing

Environment Variables

Variable Required Description
INTERNAL_SECRET For callbacks Shared secret for authenticating callback requests to the gateway

Release files for alavida-sdk 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for alavida-sdk 0.1.0
File Size Uploaded
alavida_sdk-0.1.0.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for alavida-sdk 0.1.0
File Interpreter ABI Platform
alavida_sdk-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.8 kB

Release files / alavida_sdk-0.1.0.tar.gz

Download URL alavida_sdk-0.1.0.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b7d66ec71837eea0be9a83832303e37f1bbe28946434a75221dbbdbc23100949
BLAKE2b-256 checksum
How to use checksums
9a507e00adad6cd5aa70f12ba1130798c00ed8f9a0a70ae5836e77f02b2d6463
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.9

Release files / alavida_sdk-0.1.0-py3-none-any.whl

Download URL alavida_sdk-0.1.0-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2253a9c36a6f77c4968dc83fb5f2f77cd14887b35b2d2ad8c49ae9a8129fea69
BLAKE2b-256 checksum
How to use checksums
bce4f7e80b18f4cce73b6ace8ec570076e116b97d9ddbd45ecc333fb75b9581b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page