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

Uploaded CPython 3.10+Windows x86-64

tensorzero-2026.4.1-cp310-abi3-musllinux_1_2_x86_64.whl (42.3 MB view details)

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

tensorzero-2026.4.1-cp310-abi3-musllinux_1_2_aarch64.whl (41.4 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tensorzero-2026.4.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (41.9 MB view details)

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

tensorzero-2026.4.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (41.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tensorzero-2026.4.1-cp310-abi3-macosx_11_0_arm64.whl (38.2 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tensorzero-2026.4.1.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.4.1.tar.gz
Algorithm Hash digest
SHA256 bfe9dfcda763055b71fe79a94cfcb12d5ed6ff38aeff9dbeebda94f353e1e856
MD5 3e640a1092c1b50a62e3ad1d0ef03476
BLAKE2b-256 c91a32b37bd6b3fd6663611dfb4f434fd8bc998f1a7ce588a537800d098f315a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.4.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b1e3d22a9526eddbdbd03400fc6208f2cf9e4e3fa7425ae66b91bee580849cef
MD5 0bc1dbd9b77f29a51a74c2793e0c230c
BLAKE2b-256 99ec2a4681bc9db9cc8ce32695ba377991ef013aea71d979e52031492eb1e888

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.4.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9d5070341c8ce7bde4b34340684abb8a2ec7e8f4033e2441ba36508bc4c93c7e
MD5 8f95a04281b8fe9268a9c2ebad65213a
BLAKE2b-256 f39c234f288b0f63d0f42f6ff22279dcdafab8227dc3f8c3880f82b41ac91941

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.4.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 374cf2b4635b90b7499ed5f598fd46c68a723696257984b3d3367a491d123d20
MD5 8e934f4495ee00e79f302460492cea75
BLAKE2b-256 414154a9a66854266c147b2e3548cec4922e42540e8fd3bc522ce5a2b67841f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.4.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d38bea9e28f48c3860d5ae727cbb8b0f73e8ec6fdcc828a827170bcb71f513c6
MD5 5f638c9b4b1d626715977f0bf23cacda
BLAKE2b-256 65218691674b6339a2b34f404bb40399d8f12f4981741fa14ca9f69d926e6dd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.4.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 22240306f84bcb157b28436d3dcdfeddd5038aeece796771519cd07e756bb8a7
MD5 cb78ca32735e1a78387887e80bede4a8
BLAKE2b-256 fb8a3dfe946c2e7542d9bd14c8f85256ce83c4356e8111458779f312f6eb3304

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.4.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9fd7ad80d84f984e135efd09a16006524cdd1eac306f197650d474f07b110573
MD5 39f538d35e59d72de7088a62c55b0366
BLAKE2b-256 ddd763e94f5df7268ede20faadf0a407644f181f28dbc677d706a9497264c0bb

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