Skip to main content

Python SDK for fabric guest agents — originate v1.cap.* capability calls.

Project description

nexgenomics

The Python SDK for fabric guest agents. Agent authors originate v1.cap.* capability calls — model.generate, model.stream, dataset.search — without hand-rolling the wire protocol or ever touching the platform token.

Requires Python 3.11+. Async-native.

from nexgenomics import connect, PermissionDenied

async with connect() as agent:
    reply = await agent.generate(
        model="mistral-7b-instruct", version="v0.3",
        messages=[{"role": "user", "content": "hello"}],
        max_tokens=64,
    )
    print(reply.content, reply.usage)

    async for chunk in agent.stream(
        model="mistral-7b-instruct", version="v0.3",
        messages=[{"role": "user", "content": "write a haiku"}],
    ):
        print(chunk, end="", flush=True)

    try:
        hits = await agent.search(dataset="papers", space="v1", query="genomics")
    except PermissionDenied:
        ...

How it works

The SDK drives a small Go transport helper (cap-helper) as a subprocess over a length-prefixed-JSON stdio protocol. The helper owns the vsock framing, the credential handshake, per-call correlation, and the v1.1 stream-frame decode — one authority shared with the host, so the SDK cannot drift from the wire contract. The SDK owns the ergonomic surface: the call methods, the exception hierarchy, and the streaming async iterators.

Identity is ambient. The helper reads the credential from env (populated by the platform at boot); the SDK never sees or accepts the token. Your code does not change when the platform changes how the token is delivered.

Errors

Two disjoint branches under FabricSDKError:

  • FabricError — the host returned a verdict with a wire code: Unauthenticated, PermissionDenied, NotFound, InvalidArgument, AlreadyExists, FailedPrecondition, Unavailable, Internal. A denial on a stream is raised from the async for.
  • TransportError — the call never reached a verdict: NoReply (deadline — never a denial), SendFailed, ProtocolError, Draining, HelperExited.

Catch FabricError for "the platform said no", TransportError for "no answer".

Streaming and cancel

stream(...) returns an async iterator that yields text deltas; on normal completion it stops and exposes .finish_reason and .usage. Breaking out of the loop, or await stream.aclose() / leaving an async with stream, sends an advisory cancel for the in-flight generation.

The helper binary

At runtime the cap-helper binary is delivered by the platform image (it is version-locked to the deployed host and built in the monorepo), so in-guest the SDK finds it automatically. For off-platform development against the fake host, point the SDK at a local build:

export CAP_HELPER_BIN=/path/to/cap-helper

Development

pip install -e '.[test]'
pytest

The tests run the SDK against a fake helper (tests/_fakehelper.py) that speaks the same stdio protocol with an independent codec — no VM, no real host.

License

Apache-2.0. Releases from 0.4.0 onward are Apache-2.0 licensed; earlier 0.x releases were BSD-3-Clause.

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

nexgenomics-0.4.1.tar.gz (20.4 kB view details)

Uploaded Source

Built Distribution

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

nexgenomics-0.4.1-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file nexgenomics-0.4.1.tar.gz.

File metadata

  • Download URL: nexgenomics-0.4.1.tar.gz
  • Upload date:
  • Size: 20.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nexgenomics-0.4.1.tar.gz
Algorithm Hash digest
SHA256 4b043c8bff53a38375ace3fa6aca0f23acdfc18f6bbbeb5d76bdd6ac014a40e6
MD5 bc538b6ae2392a3dfab59ca887af4cee
BLAKE2b-256 5baef0c9a3b1404af6eab8baa31fa8f9eb7d0e8ec85cc9b0a20b1bb63c29e93a

See more details on using hashes here.

Provenance

The following attestation bundles were made for nexgenomics-0.4.1.tar.gz:

Publisher: publish.yml on nexgenomics/py-nexgenomics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nexgenomics-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: nexgenomics-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nexgenomics-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4722e4720203ad068f1eaab4731af08ec201bc2d1221e101e7ca272ae7d99c1d
MD5 925db5488f65303e8c5d1440973d1d91
BLAKE2b-256 b13d605087f7a6fd4e4fc85846f696d3f3aa25bc63e134cf15acc34427dbc29e

See more details on using hashes here.

Provenance

The following attestation bundles were made for nexgenomics-0.4.1-py3-none-any.whl:

Publisher: publish.yml on nexgenomics/py-nexgenomics

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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