Skip to main content

Official Python SDK for the Graphn API: custom-model lifecycle, secrets, and OpenAI-compatible inference.

Project description

graphn — Python SDK

Official Python SDK for the Graphn API: custom-model lifecycle, secrets management, and OpenAI-compatible inference (chat completions, model listing, text-to-speech) — all behind a single typed client.

The SDK is generated from the public OpenAPI 3.1 spec served at https://cp.graphn.ai/openapi.yaml. Inference calls delegate to the official openai Python SDK so you get full feature parity (tools, streaming, structured outputs, etc.) for free.

Install

pip install graphn

Requires Python 3.10+.

Quickstart

from graphn import Client

client = Client(api_key="gn_...", workspace_id="ws_abc")

secret = client.secrets.create(name="hf-token", value="hf_...")

model = client.custom_models.create(
    name="my-llama",
    huggingface_model_id="meta-llama/Llama-3-8B",
    hf_token_secret_id=secret.id,
)

client.custom_models.wait_until_ready(model.id, timeout=900)

resp = client.chat.completions.create(
    model=model.name,
    messages=[{"role": "user", "content": "Hello!"}],
)
print(resp.choices[0].message.content)

The async variant is identical:

import asyncio
from graphn import AsyncClient

async def main() -> None:
    async with AsyncClient(api_key="gn_...", workspace_id="ws_abc") as client:
        async for model in client.custom_models.list():
            print(model.id, model.status)

asyncio.run(main())

What's in here

Module Purpose
graphn.Client Sync entrypoint
graphn.AsyncClient Async entrypoint
client.custom_models Create / list / get / delete / wake / refresh / wait_until_ready
client.secrets CRUD for HuggingFace tokens and similar workspace secrets
client.chat.completions OpenAI-compatible chat completions (delegates to openai)
client.models List models available to the workspace
client.tts Text-to-speech
client.imported_models Discover and test connections to imported (BYO) inference hosts

Configuration

Argument Default Notes
api_key GRAPHN_API_KEY env var Bearer token starting with gn_. Required.
workspace_id GRAPHN_WORKSPACE_ID env var Injected into control-plane paths and X-Workspace-Id.
base_url https://cp.graphn.ai Control-plane host.
inference_url https://model.graphn.ai Inference host (passed to the underlying OpenAI client).
timeout 60.0 seconds Per-request HTTPX timeout.
max_retries 2 Retries on connect / 5xx / 429.

Generating clients in other languages

The OpenAPI spec is the source of truth. To generate a client in another language, point your favorite generator at:

https://cp.graphn.ai/openapi.yaml

We test compatibility with openapi-generator 6.0+, openapi-python-client 0.21+, and oapi-codegen 2.0+.

Development

python -m venv .venv && source .venv/bin/activate
pip install -e '.[dev]'
ruff check src tests
pytest

To regenerate the typed transport layer from the upstream spec:

./scripts/regenerate.sh

License

Apache 2.0 — see LICENSE.

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

graphn-0.1.0.tar.gz (47.5 kB view details)

Uploaded Source

Built Distribution

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

graphn-0.1.0-py3-none-any.whl (101.7 kB view details)

Uploaded Python 3

File details

Details for the file graphn-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for graphn-0.1.0.tar.gz
Algorithm Hash digest
SHA256 134bc63d585b450c1e200fd4dc9cdd59ed3f96205801dac57299fe99656702cb
MD5 6ea38d042e84cd6cce70f83d099ae113
BLAKE2b-256 2299bbb62fb3551605b45602d5ed0a21c68a63279add3c083b7ebfd16b5db9d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphn-0.1.0.tar.gz:

Publisher: release.yml on voltagepark/graphn-sdk-python

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

File details

Details for the file graphn-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for graphn-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a1b5226f1106f71bdb2a8fa7b59d80808784b93c1216699b202f063b6b45f3bc
MD5 5b5db36538c1806fe1430dd6f3a6aafe
BLAKE2b-256 50c686fc9a558580cef790436eec898646194797cba086b9eb727f988bf43daf

See more details on using hashes here.

Provenance

The following attestation bundles were made for graphn-0.1.0-py3-none-any.whl:

Publisher: release.yml on voltagepark/graphn-sdk-python

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