cairnq (Python)
SQLite-first, cross-language, storage-centered durable task runtime. The Python SDK. API and worker processes coordinate only through a shared SQLite file.
from cairnq import CairnQ, Worker
# Worker side — a handler always receives (ctx, payload).
worker = Worker.sqlite("tasks.db")
@worker.task # registered under the function name, "create_summary"
async def create_summary(ctx, payload):
await ctx.progress(0.2, "reading")
return {"summary": await llm.summarize(payload["text"])}
worker.serve() # blocking entry point; Ctrl-C closes cleanly
# API side (in your server) — submit returns immediately.
tasks = CairnQ.sqlite("tasks.db")
task = await tasks.submit("create_summary", {"text": text}, key=f"summary:{aid}")
@worker.task defaults the task name to the function's name. Pass a string for a
dotted/namespaced name: @worker.task("summary.create").
Synchronous call (submit + wait):
from cairnq import TaskFailed, TaskTimeout
try:
result = await tasks.call("create_summary", {"text": text}, wait_timeout_ms=10_000)
except TaskFailed as e:
log(e.code, e.message, e.retryable) # envelope fields, no e.error["code"] digging
except TaskTimeout as e:
... # e.task_id keeps running
Inspect a task by id/key without memorizing status strings:
task = await tasks.get_by_key(key)
if task and task.succeeded: # also .failed / .canceled / .running / .queued / .is_terminal
use(task.result)
Optionally define a task once and share the symbol across both ends — the name
lives in one place (no string drift), and call() is typed as the task's result:
from cairnq import TaskDef
summarize = TaskDef[dict, dict]("summarize")
@worker.task(summarize) # registered under summarize.name
async def handle(ctx, payload): ...
result = await tasks.call(summarize, {"text": text})
Opt-in: every API still accepts a plain name string (cross-language callers use it).
Running it in production
worker = Worker.sqlite(
"tasks.db",
concurrency=4,
retry_backoff_ms=1_000, # doubles per attempt, capped by retry_backoff_max_ms (30s); 0 disables
on_error=lambda exc, info: log.warning("worker survived %s: %s", info, exc),
)
# Nothing else deletes rows. Sweep terminal tasks on a schedule.
await tasks.purge(older_than_ms=7 * 24 * 3600_000)
A handler that does real side effects should bail out when it loses its lease — the task is already running on another worker and nothing it writes is recorded:
@worker.task("long.job")
async def long_job(ctx, payload):
for chunk in chunks:
if ctx.lost_lease or await ctx.canceled():
return
await process(chunk)
Multi-host
Same code, Postgres instead of the file — CairnQ.postgres(dsn) /
Worker.postgres(dsn). Install with pip install cairnq[postgres].
The protocol (schema + canonical SQL) lives in ../cairnq-protocol and is shared
verbatim with the TypeScript SDK. See ../cairnq-protocol/PROTOCOL.md.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 cairnq-0.2.0.tar.gz.
File metadata
- Download URL: cairnq-0.2.0.tar.gz
- Upload date:
- Size: 73.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
546e537b3ddd8b5c9c4dd37c2a4b37cd938bc79cc76f438f28a1a9073eca8bf7
|
|
| MD5 |
a66f661d470192cd3096ef28ecb9f4a8
|
|
| BLAKE2b-256 |
50c18bd497a480d8e0dd94fbd411a485e558c8f90d5ce1f723a4ca1f535699e2
|
Provenance
The following attestation bundles were made for cairnq-0.2.0.tar.gz:
Publisher:
publish.yml on Jannchie/cairnq
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cairnq-0.2.0.tar.gz -
Subject digest:
546e537b3ddd8b5c9c4dd37c2a4b37cd938bc79cc76f438f28a1a9073eca8bf7 - Sigstore transparency entry: 2285764451
- Sigstore integration time:
-
Permalink:
Jannchie/cairnq@569f73b745a05da2c07c6dd8ad8e66aaf8657f6c -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Jannchie
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@569f73b745a05da2c07c6dd8ad8e66aaf8657f6c -
Trigger Event:
push
-
Statement type:
File details
Details for the file cairnq-0.2.0-py3-none-any.whl.
File metadata
- Download URL: cairnq-0.2.0-py3-none-any.whl
- Upload date:
- Size: 62.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e24204e2c1ac6b9a125a152e96a8083d970fcfc9771d337337e114954a62107d
|
|
| MD5 |
4527695db8721604c6c2cdaa744ad167
|
|
| BLAKE2b-256 |
05a66d5532c4729a2f26e97b2b04bc34273c0dba0ae5d100af6b0f462e3ef68e
|
Provenance
The following attestation bundles were made for cairnq-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on Jannchie/cairnq
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cairnq-0.2.0-py3-none-any.whl -
Subject digest:
e24204e2c1ac6b9a125a152e96a8083d970fcfc9771d337337e114954a62107d - Sigstore transparency entry: 2285764564
- Sigstore integration time:
-
Permalink:
Jannchie/cairnq@569f73b745a05da2c07c6dd8ad8e66aaf8657f6c -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Jannchie
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@569f73b745a05da2c07c6dd8ad8e66aaf8657f6c -
Trigger Event:
push
-
Statement type: