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

Uploaded CPython 3.10+Windows x86-64

tensorzero-2026.3.2-cp310-abi3-musllinux_1_2_x86_64.whl (41.6 MB view details)

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

tensorzero-2026.3.2-cp310-abi3-musllinux_1_2_aarch64.whl (40.6 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tensorzero-2026.3.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (41.2 MB view details)

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

tensorzero-2026.3.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (40.4 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tensorzero-2026.3.2-cp310-abi3-macosx_11_0_arm64.whl (37.5 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tensorzero-2026.3.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.3.2.tar.gz
Algorithm Hash digest
SHA256 9987c8b310f01e9b19f2d582de4cfd7650a6e379ec6de6e409af4c51ac9a6b88
MD5 1811a7c605bf16638f9115afb662bc80
BLAKE2b-256 53df6d80aa9562e86d8aaaa4f04caa20fc7a72d80ecd20044609a2c1dc71a4f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 407942ec3916de4b427b55002b4bc00ff06a233b94125cb4c88e54e7f6192ef3
MD5 0f630b3bafe3b42fcdec63419e86eb83
BLAKE2b-256 31f71b7d54f438f858e12d57c2e334766b5928449cac54a3a8ea200f269751e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f6806ec3efe78c3369e1a31982c1df332e6105d61e5dcaf89775e06aa01b410f
MD5 374191b7f2549d64d702187d4f408e26
BLAKE2b-256 83ac32ad5b41bc11f83cf9800c16ed25abd2b32c9f305ad99505e63c27f87e89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.2-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 9a3d1e0f1d677009f31b8b5a0829abd4426fefd76d6b8e2f7ce30f62903682c2
MD5 c8b13f12475f892aeb6996640f4e4d3f
BLAKE2b-256 5720446f371b314e6ecc3c2857beaeab68e2994a76cc4ea0f2f7f0e34640a852

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ec266235b0e490060bf8e191206a6f60e06a8affde100ddbc51def11746b2610
MD5 04a5289e402f19e6a96981cea82d53cb
BLAKE2b-256 4ec0a074fb213f8fdd15f9d6891f958b671d7b3a82aed2457301a56efc44b40e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bab70187f995cc9a5adb9ee54c1a6d79e5a5093de29c767111086c6123b2702b
MD5 548354f9a433290b52bb56f89cfee5c8
BLAKE2b-256 a8c194c25920d9c1809951e11fd40e041c926a849448ece09c9cc39543312baf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3d6c196635fedcdaca0971ace7ec51062afa281af36f65934488c742c023941c
MD5 d069d71cff69d53c534844f04be7af83
BLAKE2b-256 cc1ebe9bc6710851e1e3ac0c8d5f647cf5555f1d4cfea9d282485247ce941647

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