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.5.2.tar.gz (2.2 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.5.2-cp310-abi3-win_amd64.whl (37.6 MB view details)

Uploaded CPython 3.10+Windows x86-64

tensorzero-2026.5.2-cp310-abi3-musllinux_1_2_x86_64.whl (42.5 MB view details)

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

tensorzero-2026.5.2-cp310-abi3-musllinux_1_2_aarch64.whl (41.6 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tensorzero-2026.5.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (42.2 MB view details)

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

tensorzero-2026.5.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (41.4 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tensorzero-2026.5.2-cp310-abi3-macosx_11_0_arm64.whl (38.4 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for tensorzero-2026.5.2.tar.gz
Algorithm Hash digest
SHA256 8df91476f9068087cacef31bc8c4d1dc7840593b9ff9cb8bacc7d1ba2c510a86
MD5 fd3288f8b90d07d3a061fc3b79dbb54b
BLAKE2b-256 39d25d9830aa672e8876835d08550fbf1a2bc89d6be276c1b46fb44bf6dfa3f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.5.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c917fc387b604a36e7b9823bef13c2c38ad41887db9688030c56ce365be84a1b
MD5 01d39dee9a70d158e01ea8afdd2561d3
BLAKE2b-256 47a6b2d83ff3cafd6b262b518af6a1dd388c74c7370e5345aa3d0f7afa7c9dea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.5.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2a2ed289f16d240913659913ecf54797e479b9406edcfba15077f20f405dca8d
MD5 69ad8ab1c0f4aa515293490885520e61
BLAKE2b-256 7788b86aae366572c59afc863753d307e98caf9e38ac1d40935cda1f142f19e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.5.2-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 d9751fc451faa18d8f815968d6fc63a1c50f42246d4faa43e87d528aad9115a1
MD5 17829c0a507be1a01e29f25f673d3ec2
BLAKE2b-256 139cc2b78d1ebee035f7d32f9f9f81a12d0ee610f6feb2095f23b834b32ff595

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.5.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 169dc96868dcac3130328a086616f627fcac2a735f073cbde7cb8b09d579dcdf
MD5 4f171dbde17bbbc95871f7bc6bda47f3
BLAKE2b-256 4985a76b9990ce86734c6629f0783f3fd0795fb392d4495fb452f7a70b8f12c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.5.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0eabc4579df1b1cc1d17107c26af8cc1d7299b7b06fee9604e25cd8b097f4407
MD5 55f2481c829e2289d73b5c26754a6dc7
BLAKE2b-256 143ba00dc6a2be0f3802ca9473be7aa95ab27d0d8c038455dc8ddabb0311a2cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.5.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e6de282152269485c6dd54f4179f2ac7b78620c9b4876c13435ba08d211e4976
MD5 bb88d8888be4cb195462c9d4e87fb95b
BLAKE2b-256 5572fb957e1d00ffec9e03ff2256a040eef150e0a0b67bc413787526e2ba6124

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