castellum
AI pipeline orchestration with automatic async I/O, CPU, and GPU management.
Install
pip install castellum
# With OpenAI support:
pip install "castellum[openai]"
# With Anthropic support:
pip install "castellum[anthropic]"
# Everything:
pip install "castellum[all]"
Quick start
from castellum import ai_task, pipeline, Runtime
from castellum.backends.remote.openai import OpenAIClient
client = OpenAIClient()
@ai_task(kind="preprocess")
def chunk_docs(docs: list[str]) -> list[str]:
return [c for doc in docs for c in doc.split("\n\n")]
@ai_task(kind="embedding", device="cuda", batchable=True, max_batch_size=128)
def embed_chunks(chunks: list[str]) -> list[list[float]]:
return local_embedder.encode(chunks)
@ai_task(kind="llm_remote", model="gpt-4.1-mini")
async def answer(question: str, context: str) -> str:
return await client.chat(
model="gpt-4.1-mini",
messages=[{"role": "user", "content": f"{context}\n\n{question}"}],
)
@pipeline
async def rag_pipeline(docs: list[str], question: str) -> str:
chunks = chunk_docs(docs)
vecs = await embed_chunks.map(chunks, preferred_batch_size=64)
context = "\n".join(str(v) for v in vecs[:5])
return await answer(question, context)
runtime = Runtime(
max_cpu_workers=8,
max_gpu_workers=2,
max_concurrent_remote_calls=10,
tokens_per_minute_limit=80_000,
)
result = await runtime.run(rag_pipeline, docs, question)
await runtime.aclose()
# Or stream tokens from an LLM task:
@ai_task(kind="llm_remote", model="gpt-4.1-mini", stream=True)
async def stream_answer(question: str, context: str):
async for chunk in client.stream_chat(...):
yield chunk
@pipeline
async def streaming_pipeline(docs: list[str], question: str):
chunks = chunk_docs(docs)
vecs = await embed_chunks.map(chunks, preferred_batch_size=64)
async for token in stream_answer(question, str(vecs[:5])):
yield token
async with Runtime() as runtime:
gen = await runtime.run(streaming_pipeline, docs, "What?")
async for token in gen:
print(token, end="", flush=True)
Core concepts
| Concept | Description |
|---|---|
@ai_task |
Decorates a function with scheduling metadata (kind, device, batchable, stream, etc.) |
@pipeline |
Decorates an async function or async generator as an orchestrated flow |
task.map(items) |
Fan-out a task over a collection with automatic batching |
stream=True |
Tasks that yield tokens bypass the scheduler — callers consume via async for |
Runtime |
Wires the event loop, thread pool, GPU workers, rate limiters, and retry policy |
Running tests
# Install with dev dependencies
pip install "castellum[dev]"
# Run all tests
pytest
# Run remote backend tests (requires API endpoint)
export OPENAI_BASE_URL=http://localhost:20128/v1
export OPENAI_API_KEY=sk-...
pytest tests/backends/
License
Unlicense — public domain. See LICENSE.
Metadata
Release files for castellum 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| castellum-0.3.0.tar.gz | 74.4 kB | Without provenance | Details for castellum-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| castellum-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for castellum-0.3.0-py3-none-any.whl |
Total release size: 93.6 kB
Release files / castellum-0.3.0.tar.gz
| Download URL | castellum-0.3.0.tar.gz |
|---|---|
| Size | 74.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
23a10b51e6efc3a4a5d3640b89e66519d8db026ff7c7d5317d0377e5faaafe56
|
|
BLAKE2b-256 checksum How to use checksums |
27f884bb6cee0f842ec2352a36463efe642500bc26d86eb32b10da4b922980fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / castellum-0.3.0-py3-none-any.whl
| Download URL | castellum-0.3.0-py3-none-any.whl |
|---|---|
| Size | 19.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ab6aa00327d0f4be406d73c4827bf0c316a766025444ad4723138020584926ae
|
|
BLAKE2b-256 checksum How to use checksums |
7dc0f213f629d515cc36ce3c56eb721d6a076ccaa5fa131c4ee06d2b9fdfeff6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for castellum 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.