Skip to main content

The Python client for TensorZero

Project description

TensorZero Python Client

Website · Docs · Twitter · Slack · Discord

Quick Start (5min) · Deployment Guide · API Reference · Configuration Reference

The tensorzero package provides a Python client for the TensorZero Gateway. This client allows you to easily make inference requests and assign feedback to them via the gateway.

See our API Reference for more information.

Installation

pip install tensorzero

Basic Usage

Initialization

The TensorZero client offers synchronous (TensorZeroGateway) and asynchronous (AsyncTensorZeroGateway) variants. Additionally, the client can launch an embedded (in-memory) gateway (build_embedded) or connect to an external HTTP gateway (build_http) - both of these methods return a gateway instance.

By default, the asynchronous client returns a Future when you call build_http or build_embedded, so you must await it. If you prefer to avoid the await, you can set async_setup=False to initialize the client in a blocking way.

Synchronous HTTP Gateway

from tensorzero import TensorZeroGateway

with TensorZeroGateway.build_http(gateway_url="http://localhost:3000") as client:
    # ...

Asynchronous HTTP Gateway

import asyncio

from tensorzero import AsyncTensorZeroGateway


async def run():
    async with await AsyncTensorZeroGateway.build_http(
        gateway_url="http://localhost:3000",
        # async_setup=False  # optional: skip the `await` and run `build_http` synchronously (blocking)
    ) as client:
        # ...


if __name__ == "__main__":
    asyncio.run(run())

Synchronous Embedded Gateway

from tensorzero import TensorZeroGateway

with TensorZeroGateway.build_embedded(
    config_file="/path/to/tensorzero.toml",
    clickhouse_url="http://chuser:chpassword@localhost:8123/tensorzero"
) as client:
    # ...

Asynchronous Embedded Gateway

import asyncio

from tensorzero import AsyncTensorZeroGateway


async def run():
    async with await AsyncTensorZeroGateway.build_embedded(
        config_file="/path/to/tensorzero.toml",
        clickhouse_url="http://chuser:chpassword@localhost:8123/tensorzero"
        # async_setup=False  # optional: skip the `await` and run `build_embedded` synchronously (blocking)
    ) as client:
        # ...


if __name__ == "__main__":
    asyncio.run(run())

Inference

Non-Streaming Inference with Synchronous Client

with TensorZeroGateway.build_http(gateway_url="http://localhost:3000") as client:
    response = client.inference(
        model_name="openai::gpt-4o-mini",
        input={
            "messages": [
                {"role": "user", "content": "What is the capital of Japan?"},
            ],
        },
    )

    print(response)

Non-Streaming Inference with Asynchronous Client

async with await AsyncTensorZeroGateway.build_http(gateway_url="http://localhost:3000") as client:
    response = await client.inference(
        model_name="openai::gpt-4o-mini",
        input={
            "messages": [
                {"role": "user", "content": "What is the capital of Japan?"},
            ],
        },
    )

    print(response)

Streaming Inference with Synchronous Client

with TensorZeroGateway.build_http(gateway_url="http://localhost:3000") as client:
    stream = client.inference(
        model_name="openai::gpt-4o-mini",
        input={
            "messages": [
                {"role": "user", "content": "What is the capital of Japan?"},
            ],
        },
        stream=True,
    )

    for chunk in stream:
        print(chunk)

Streaming Inference with Asynchronous Client

async with await AsyncTensorZeroGateway.build_http(gateway_url="http://localhost:3000") as client:
    stream = await client.inference(
        model_name="openai::gpt-4o-mini",
        input={
            "messages": [{"role": "user", "content": "What is the capital of Japan?"}],
        },
        stream=True,
    )

    async for chunk in stream:
        print(chunk)

Feedback

Synchronous

with TensorZeroGateway.build_http(gateway_url="http://localhost:3000") as client:
    response = client.feedback(
        metric_name="thumbs_up",
        inference_id="00000000-0000-0000-0000-000000000000",
        value=True,  # 👍
    )

    print(response)

Asynchronous

async with await AsyncTensorZeroGateway.build_http(gateway_url="http://localhost:3000") as client:
    response = await client.feedback(
        metric_name="thumbs_up",
        inference_id="00000000-0000-0000-0000-000000000000",
        value=True,  # 👍
    )

    print(response)

Stubtest

Run uv run stubtest tensorzero.tensorzero to confirm that the stub tensorzero.pyi file matches PyO3 compilation.

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

tensorzero-2026.3.4.tar.gz (2.0 MB view details)

Uploaded Source

Built Distributions

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

tensorzero-2026.3.4-cp310-abi3-win_amd64.whl (37.3 MB view details)

Uploaded CPython 3.10+Windows x86-64

tensorzero-2026.3.4-cp310-abi3-musllinux_1_2_x86_64.whl (42.0 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

tensorzero-2026.3.4-cp310-abi3-musllinux_1_2_aarch64.whl (41.1 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tensorzero-2026.3.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (41.7 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

tensorzero-2026.3.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (40.9 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tensorzero-2026.3.4-cp310-abi3-macosx_11_0_arm64.whl (38.0 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file tensorzero-2026.3.4.tar.gz.

File metadata

  • Download URL: tensorzero-2026.3.4.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.8.3

File hashes

Hashes for tensorzero-2026.3.4.tar.gz
Algorithm Hash digest
SHA256 3b1e7a00a238f0f2dd9cee878f481bdf20999c73da0d3fecb600887a525927e4
MD5 edffb608a91a4e11b7818efe1741eb7a
BLAKE2b-256 fbe1c5ece5fdd3c5c13a7e1710564d7c96b4174fba12a2f4b1116f9ce7ff886e

See more details on using hashes here.

File details

Details for the file tensorzero-2026.3.4-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tensorzero-2026.3.4-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 449e56f2aa2ba048b451b6b03ba24ee8a2331bf4846029745c929e2a586e47bf
MD5 5653cd743a5ecefb94de183d7df97b46
BLAKE2b-256 d3a1c7b53e046736f70b4e368a48d45483ed7adb1b2f6f67e4a8567cd3738ec0

See more details on using hashes here.

File details

Details for the file tensorzero-2026.3.4-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tensorzero-2026.3.4-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b2e3f803d52ca68528880150bccb8c77995af9da920fbc034425ffc799a922ca
MD5 38547e5dc9c02635e7bcd4a02a21ccd1
BLAKE2b-256 c3104acdf13f620bbf3f06ca3109769df569c042a4aa3c4e5e398a8069006f4f

See more details on using hashes here.

File details

Details for the file tensorzero-2026.3.4-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for tensorzero-2026.3.4-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 a868f6f13320423988701a4e56f1860834e298d681df973fcfae5e21a4864368
MD5 421c9d5c391ef302c9ed5e3bf1fb1411
BLAKE2b-256 8b2bd06954e1ee1d74d9f2e2451e2ac7c1b6c6caa669c6edfb2f069ce3634f61

See more details on using hashes here.

File details

Details for the file tensorzero-2026.3.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tensorzero-2026.3.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 18a91b4d6cccbc1f9e92d9a552f52e049a9a5192524044fe182da5abdef69cd1
MD5 98da91a7082bfac56690eeda7bd80071
BLAKE2b-256 a903c7e6bdb545a04ec995187955797f79dd7f32a1748be269108483b1b9af33

See more details on using hashes here.

File details

Details for the file tensorzero-2026.3.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tensorzero-2026.3.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4149f49c622196a641ec53b7c54260698b06ab9aa64336eca182d70a16be229f
MD5 228672d48ecb73c8ce5d28044f681005
BLAKE2b-256 155aba7d05a09e48ae8316ee6d75834e7fb3fa098081c5bb3149de768e8a7a54

See more details on using hashes here.

File details

Details for the file tensorzero-2026.3.4-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tensorzero-2026.3.4-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f928c5afe7dbdc58ed1532c1d21c0d9db70daf859016a7ed80ea5f7851edd4e2
MD5 7fbb6d489b6c2cc87a5bc63b07bce20b
BLAKE2b-256 11b186d3bda47fd2ce862afaf198757335ac7277a79e37fd4e719f16d0084857

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