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.2.2.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.2.2-cp310-abi3-win_amd64.whl (37.1 MB view details)

Uploaded CPython 3.10+Windows x86-64

tensorzero-2026.2.2-cp310-abi3-musllinux_1_2_x86_64.whl (41.5 MB view details)

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

tensorzero-2026.2.2-cp310-abi3-musllinux_1_2_aarch64.whl (40.7 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tensorzero-2026.2.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (41.1 MB view details)

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

tensorzero-2026.2.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (40.5 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tensorzero-2026.2.2-cp310-abi3-macosx_11_0_arm64.whl (37.4 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tensorzero-2026.2.2.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.2.2.tar.gz
Algorithm Hash digest
SHA256 19dbb88a973de3aad8275c0bc776d1b78ebcf7e8f4513f1aaa7b4a981ac7b4cf
MD5 ce4cab659fa0d13f087c9a1aff7b66a9
BLAKE2b-256 4c9076b560451f8a4bdf645ab6431bff9b70bba78d09f668fd865ce4ed3beec8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.2.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 92653fd61b30f1d48f13ec5d89ddfdc45d7bd90104b526258bef2074633a8755
MD5 f03066fff7fdd0ae9a4620b823451dab
BLAKE2b-256 8585a4e2894f2b7aca1f96919068e90db7f6febaf2264d8494367e88c87acb29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.2.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 80a81e90aec883447b039ab6c3e0ea808f41c8d8159225522ad001fd7cf2db36
MD5 644da7add3368fdc049a9a7b40724113
BLAKE2b-256 3741d0a7a00a7cfec18513fde856d01e33626a361e4a9facd829c49c8f866f75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.2.2-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 581293799f4fedc230e1aad2060a400a797b33b86b8fcf6701dad0e79faf7373
MD5 29b86a078a5755f1d79cbe3ae1b06246
BLAKE2b-256 a271d2cf0bc7d3ffb3a233a6e20e2a6668bd1bbfac5bbdaa4fc8c6e917dd40df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.2.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5087a9b481a71cb179ae337b62261fd223bb26bd2ccee4e32e746a2da7232428
MD5 62379b07b10325e701814ce8400ce0f2
BLAKE2b-256 a5c4e4947de266cabaf92515ed5de880b5dc8af304a871fd337dc18b5756f179

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.2.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 17abbff24bdc7e84a165b6517822bace178003c902fd654b3bc9996c6bad581e
MD5 0de611f17807d18aee9aeae7ce2cc477
BLAKE2b-256 5049863069bcf3cc25054eb2bd0d5e41e9caa154bfa33c418a69ba1ee44711b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.2.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1a40efb0c9be5f57bf0d3f019c1bd4e29414828785e6e82529cae5e6d269b025
MD5 2b62c741ffec76bd1ecf8da762596719
BLAKE2b-256 4442a7fb70106bbab41df60765ee4e2309fd52969c544c82457e1281017bdf49

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