Skip to main content

citrate-sdk-python

Part of the Citrate Network — own the means of computation. · Docs · Run a node · Contribute → free membership

The Python SDK and citrate CLI for the Citrate Network (chain 40204) — connect to the chain, deploy/run models, encrypt inference inputs, and call the inference gateway.

What it is

citrate-labs-sdk is the Python client for the Citrate distributed-AI network: a JSON-RPC CitrateClient, managers for compute/learning/staking/treasury/farming, an AES-GCM/HKDF crypto envelope for encrypted inference, an OpenAI-compatible GatewayClient, and a citrate command-line tool. Chain id 40204 is bound from a vendored federation-contract artifact and enforced at signing time (a hostile RPC cannot make you sign for another chain). It mirrors the canonical TypeScript SDK (@citratelabs/sdk) and may lag it.

See the concepts in the docs: https://docs.citrate.ai. Depends on a running chain node (citrate-chain) and, for inference, the gateway (citrate-inference-gateway).

Prerequisites

python3 --version   # >= 3.10 (3.10/3.11/3.12 supported)
python3 -m pip --version
# Optional: uv (a uv.lock is committed for reproducible installs)
#   pipx install uv   # or: curl -LsSf https://astral.sh/uv/install.sh | sh
# Optional, only for "Connect it locally": a local Citrate devnet node on :8545

Build from source

git clone https://github.com/CitrateNetwork/citrate-sdk-python.git
cd citrate-sdk-python

# pip (editable install with dev extras)
python3 -m venv .venv && source .venv/bin/activate
pip install -e '.[dev]'

# --- or with uv (uses the committed uv.lock) ---
# uv sync

pytest                 # run the test suite
citrate contract       # smoke-test the CLI: prints the federation contract table

pyproject.toml is the single source of truth for dependencies (requests, cryptography, eth-account, web3, numpy). The install exposes the citrate console script.

Run locally

This is a library plus a CLI. Install it into your environment, then either import it or use the CLI:

pip install citrate-labs-sdk        # from PyPI (published as citrate-labs-sdk)
citrate --help                      # subcommands: contract, wallet, entitlement, gateway

30-second Quickstart (against the public testnet, chain 40204):

import os
from citrate_sdk import CitrateClient

client = CitrateClient(
    rpc_url="https://rpc.citrate.ai",             # testnet default (chain 40204)
    private_key=os.getenv("CITRATE_PRIVATE_KEY"), # optional; required to sign
)
print("chain id:", client.get_chain_id())          # 40204

Call the inference gateway (OpenAI-compatible; needs a cgk_ key):

from citrate_sdk.gateway import GatewayClient

gw = GatewayClient(api_key=os.environ["CITRATE_GATEWAY_API_KEY"])
print(gw.chat_completions(
    model="gemma-4-E4B-it-Q4_K_M",
    messages=[{"role": "user", "content": "Say hi from Citrate"}],
))

Runnable examples live in examples/ (basic_usage.py, encrypted_inference.py, marketplace_demo.py). Verify it's up: get_chain_id() returning 40204 confirms the RPC.

Security: the client warns/fails on a remote plaintext http:// RPC (keys and signed transactions would go out in cleartext). Loopback http:// is always allowed; pass allow_insecure_http=True for a trusted TLS-less internal host.

Connect it locally ← the differentiator

Point the SDK at a local Citrate stack on one machine instead of the public testnet.

  1. Local chain — run a Citrate devnet node (chain 40204) from citrate-chain and deploy its contract book. It exposes JSON-RPC on http://localhost:8545.
  2. Point the SDK at it (loopback needs no opt-in):
    from citrate_sdk import CitrateClient
    client = CitrateClient(
        rpc_url="http://localhost:8545",
        private_key="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",  # anvil acct #0
    )
    assert client.get_chain_id() == 40204
    
    The client refuses to sign if the RPC's eth_chainId does not match the expected 40204; pass chain_id= to override for a custom local chain.
  3. Local inference gateway (optional) — run citrate-inference-gateway and point the gateway client at it:
    gw = GatewayClient(api_key="cgk_...", base_url="http://localhost:8080")
    
  4. End-to-end check — run the basic example against your local node:
    CITRATE_RPC_URL=http://localhost:8545 python examples/basic_usage.py
    

For the full multi-repo bring-up (chain → identity → bundler → gateway → SDKs), see the LOCAL_STACK guide at https://docs.citrate.ai.

Configuration

Env var Default Purpose
CITRATE_RPC_URL http://localhost:8545 chain JSON-RPC endpoint
CITRATE_PRIVATE_KEY — signer key (examples generate an ephemeral one if unset)
CITRATE_GATEWAY_API_KEY — cgk_ bearer key for the inference gateway

CitrateClient(rpc_url, private_key=None, timeout=..., allow_insecure_http=False, chain_id=None). The expected chain id (40204) and gateway base URL come from the vendored federation artifact; citrate contract prints the full table.

License

Licensed under the Apache License, Version 2.0 (see LICENSE). This is the open-source infrastructure tier of Citrate's open-core model. The commercial application layer is source-available under BUSL-1.1. Licensor: Citrate Inc.

Release files for citrate-labs-sdk 0.6.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for citrate-labs-sdk 0.6.2
File Size Uploaded
citrate_labs_sdk-0.6.2.tar.gz 111.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for citrate-labs-sdk 0.6.2
File Interpreter ABI Platform
citrate_labs_sdk-0.6.2-py3-none-any.whl Python 3 none any Details

Total release size: 227.0 kB

Release files / citrate_labs_sdk-0.6.2.tar.gz

Download URL citrate_labs_sdk-0.6.2.tar.gz
Size 111.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6ab7d8091fbe9671e2eb893bc45ad42c59d79e120b86ea49c4e37078a9f54cc3
BLAKE2b-256 checksum
How to use checksums
e097b41595305e592300c3204ecda64416ba52f7f89c99f5808ba99c54436f05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.

Transparency log

Release files / citrate_labs_sdk-0.6.2-py3-none-any.whl

Download URL citrate_labs_sdk-0.6.2-py3-none-any.whl
Size 115.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7256a6d4ac3458e923dcbe58f4a9036e2518270e95ed0e07388744cf29e9ae7
BLAKE2b-256 checksum
How to use checksums
6c1068d245c7f868b779460f21e400f643813445fad4e73751658ee0d3725d44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.6.2 This release

2 release files

0.6.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page