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.1.tar.gz (1.9 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.1-cp310-abi3-win_amd64.whl (37.3 MB view details)

Uploaded CPython 3.10+Windows x86-64

tensorzero-2026.3.1-cp310-abi3-musllinux_1_2_x86_64.whl (41.8 MB view details)

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

tensorzero-2026.3.1-cp310-abi3-musllinux_1_2_aarch64.whl (40.8 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tensorzero-2026.3.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (41.3 MB view details)

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

tensorzero-2026.3.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (40.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tensorzero-2026.3.1-cp310-abi3-macosx_11_0_arm64.whl (37.6 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for tensorzero-2026.3.1.tar.gz
Algorithm Hash digest
SHA256 bd5f1b3aeaeae26ee52e7e4c87ff8aa2b5126711bbd008ec184d2fdc0bcc8e21
MD5 999e9f46200a8190e99a745ccbd5e47e
BLAKE2b-256 369e572fe1fcade08cee1f520f24266b9d0537885b4142407e9e9bc0c8f7d0f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 fe839989e1c1610e883aabdc2c8fb354480441e6c535e4ae69451d2149c06aa5
MD5 8e242040ff6faae6c1962c7b26cb6b4c
BLAKE2b-256 6576497bd18945dc8c78510c2f2e93e779c056380d3970213cc6f4c28ec9f6fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7a101772023a1493f0678caaf7c24b9e0ad234898fa96a072c74d81e45b3fc70
MD5 f6c81d8d1bb77074ece71f82b655a642
BLAKE2b-256 d53103a7626899df2da0b9f0d7ec4d7ad20e414fe513a38f442a77428c4eec29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 48665a3cf83c260d4900529586ca7ee37fa684e604c67be49b8d8f66ac4203d7
MD5 95ee0418aa4e360a20a21e482f18d809
BLAKE2b-256 545d40ab7f393c6eb01d92402f6fd502b4c45692d13f0ef3112a85b411862114

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 634ca36604086a8180c551751c9e8c7e5da73e4c2dd2db1ba30df326c570a8ad
MD5 fb35e8d70a451b5c7f013c895293c83e
BLAKE2b-256 0943bdd66700d16fac3cbd953bdd8451680bc14f676a6b9bbecd70513fe41c3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d221d84d0694badf9dcaecb95bf5c647e8e5c68fdad096d7072a207e53a06825
MD5 542843a8e9c0dbe6f22a6595b0763b1b
BLAKE2b-256 6c63308742e887635f9fe0ba672af38aa7dad831b5a5f903ca091d4031d72f50

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a5dfccfa8c635bd237cc6af2087439fb2cd07e75bbfa68519aa01b9a9749baeb
MD5 a24193d177250466b8afe50b7c1ce5c2
BLAKE2b-256 640418940454ab7b00b02c205ea8cf263813139cc9721c41cb895bbd2dd7f97a

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