Python SDK for building Alavida platform components
Project description
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 |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
alavida_sdk-0.1.0.tar.gz
(3.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file alavida_sdk-0.1.0.tar.gz.
File metadata
- Download URL: alavida_sdk-0.1.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7d66ec71837eea0be9a83832303e37f1bbe28946434a75221dbbdbc23100949
|
|
| MD5 |
4fc1d382236ec67fec5bacae5ca067be
|
|
| BLAKE2b-256 |
9a507e00adad6cd5aa70f12ba1130798c00ed8f9a0a70ae5836e77f02b2d6463
|
File details
Details for the file alavida_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: alavida_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2253a9c36a6f77c4968dc83fb5f2f77cd14887b35b2d2ad8c49ae9a8129fea69
|
|
| MD5 |
e540b01cfd1468735eaffa2e1c59ce2d
|
|
| BLAKE2b-256 |
bce4f7e80b18f4cce73b6ace8ec570076e116b97d9ddbd45ecc333fb75b9581b
|