Skip to main content

Pythonic async client for the Akribes workflow server

Project description

akribes

Pythonic async client for the Akribes workflow server.

Requires Python 3.10+.

Install

pip install akribes
# or with optional OpenTelemetry support:
pip install 'akribes[otel]'

Quick start

import asyncio
from akribes_sdk import AkribesClient

async def main():
    async with AkribesClient("https://akribes.example.com", token="akribes_tk_...") as client:
        proj = client.project(2)
        output = await proj.script("summarize").run_and_await(brief="explain quantum")
        print(output.execution_id, output.result)

asyncio.run(main())

Construction

import os
from datetime import timedelta
from akribes_sdk import AkribesClient, RetryPolicy

client = AkribesClient(
    "https://akribes.example.com",
    token=os.environ["AKRIBES_TOKEN"],
    timeout=timedelta(seconds=30),
    retry=RetryPolicy(max_attempts=4),      # retries transients + 429 by default
    otel=True,                               # opt-in OTel auto-instrumentation
)

Project handles

proj = client.project(2)                              # sync, lazy
proj = await client.get_project("podesta-staging")    # async, resolves name → id
sandbox = await client.sandbox()                       # per-user sandbox project

Typed inputs (codegen)

Generate typed ScriptType[I, O] stubs from a live server:

akribes types pull --project podesta --lang python --out src/akribes_types/

Then:

from akribes_types.podesta import summarize   # ScriptType[I, O] with typed input/output

out = await proj.run(summarize, brief="hi", tone="formal")
# IDE knows brief: str, tone: Literal["formal","casual"]
print(out.execution_id, out.result)

Streaming

run = await proj.executions.run_stream("summarize", brief="hi")
async for evt in run:
    match evt.kind:
        case "agent_chunk": print(evt.chunk, end="")
        case "task_end":    print(f"\n[task {evt.task!r} done]")
        case "error":       print(f"\n[error {evt.message}]")
output = await run.output()

Document ingest

from pathlib import Path

# One-liner
result = await proj.documents.ingest_and_wait(Path("invoice.pdf"))

# With progress
handle = proj.documents.ingest(Path("invoice.pdf"))
async for evt in handle:
    print(evt)
result = await handle.result()

Subscribe (long-lived events)

async with proj.events.subscribe(interests=[{"script_name": "summarize"}]) as sub:
    async for evt in sub:
        print(evt)

Heartbeat runs for the lifetime of the subscription only — not automatically on client construction.

Pagination

async for script in proj.scripts.list():
    print(script.name)

# Or materialise
scripts = await proj.scripts.list().to_list()
first   = await proj.scripts.list().first()
top10   = await proj.scripts.list().take(10)

Error handling

from akribes_sdk import (
    AkribesError, AuthError, NotFoundError, TransientError,
    RateLimitError, ScriptError, AkribesTimeoutError,
)

try:
    output = await proj.run_and_await("summarize", brief="hi")
except AuthError:        # 401/403
    ...
except NotFoundError:    # 404
    ...
except TransientError:   # 502/503 (retried by default)
    ...
except RateLimitError:   # 429 (retried by default, respects Retry-After)
    ...
except ScriptError as e: # workflow failed; e.error_kind, e.execution_id
    ...

Tokens

from datetime import timedelta
minted = await client.tokens.mint(
    scopes={"projects": "*", "role": "admin"},
    expires_in=timedelta(hours=8),
    label="web-session",
    user_email="alice@acme.com",
)
print(minted.token)   # ship to the browser

Authentication

AkribesClient accepts either a service token (long-lived, set via AKRIBES_SERVICE_TOKEN_<NAME>=<scope>:<secret> on the server) or a scoped token (akribes_tk_... — legacy aura_tk_... still accepted — minted via client.tokens.mint(...)).

Prefer Authorization: Bearer over ?token=… (#789)

AkribesClient always sends the token in the Authorization header for HTTP requests and WebSocket upgrades. The ?token=… query-string form exists only because browser EventSource / WebSocket constructors cannot set arbitrary headers — treat it as a browser-only escape hatch.

For CLIs, scripts, and backend services, avoid ?token=… because:

  • Reverse proxies, ingress controllers, and CDNs log the full URL (including the token) in access logs by default.
  • CI runners (Forgejo Actions, GitHub Actions) echo curl commands into job logs.
  • Browsers leak ?token= in the Referer header on cross-origin sub-resource requests.

The server stamps X-Token-Source: query-param on responses to any request that used the query fallback so operators can chart adoption.


See examples/ for runnable end-to-end demos.

Upgrading from v0.20.x? See MIGRATION-0.21.md.

License

MIT

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

akribes-0.22.4.tar.gz (167.9 kB view details)

Uploaded Source

Built Distribution

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

akribes-0.22.4-py3-none-any.whl (111.8 kB view details)

Uploaded Python 3

File details

Details for the file akribes-0.22.4.tar.gz.

File metadata

  • Download URL: akribes-0.22.4.tar.gz
  • Upload date:
  • Size: 167.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","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}

File hashes

Hashes for akribes-0.22.4.tar.gz
Algorithm Hash digest
SHA256 b7c5a38e6957f3da7a1f97d0b04ce98de0572b3f8491d9661ddf5871b84fa50d
MD5 a33d014c8a90a0aeff609c77d3e0446a
BLAKE2b-256 1b7389fdb647f9e080b0df9c1ffe55339adac661e8a8b4a0f94e2b33d591f02a

See more details on using hashes here.

File details

Details for the file akribes-0.22.4-py3-none-any.whl.

File metadata

  • Download URL: akribes-0.22.4-py3-none-any.whl
  • Upload date:
  • Size: 111.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","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}

File hashes

Hashes for akribes-0.22.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d0705dab09847cbe71659f20d76cb5bc5776839df3b4430c99d424817b1649e3
MD5 29dbb582fd5a5c50611fbdc3ad721c55
BLAKE2b-256 461886c9eff5ea8beb190f97a9c4ef2ca00af15ebe9a80f62d038f46ed4280f0

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