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

Uploaded CPython 3.10+Windows x86-64

tensorzero-2026.3.3-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.3-cp310-abi3-musllinux_1_2_aarch64.whl (40.6 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tensorzero-2026.3.3-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.3-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.3.3-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.3.tar.gz.

File metadata

  • Download URL: tensorzero-2026.3.3.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.3.tar.gz
Algorithm Hash digest
SHA256 eea477f27cef89d8cdb02cc2a09066c08a6da52e3aa2cb099c716ac799a9eaa7
MD5 e736800091a8e336e53e2dbc8bb1cbf6
BLAKE2b-256 e9b02b08cd2584c8f4fdabadd26fb9872cc34154e647d6303b37c11d594632e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 94f8f517afbd965a698204a39eb4a5b039f53c2a7ab6d0e233d6ce44eaa44bd8
MD5 c26e8ea23deb008ad1b9de8d88d31026
BLAKE2b-256 a4e541e859b15bbd2e7989fd54d411be07448e39829780d4003ee8a9708b971c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.3-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4419a79a0ff33d13ea6484c7840e0c35f380f1b6ee77a7d4c5d1b1a0dec17619
MD5 d90cb92f8cd17646f921d25080abb587
BLAKE2b-256 93e5dd7727b65c100d09bc32ea376bfdf14bedcf2e23571d0540e5f63e3e1197

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.3-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 6326a9c8cc85455432405dea56473ec1ea75657c9d3c2255bfcdbf98fa007c52
MD5 47676a885ac71301b33fccb381c1237d
BLAKE2b-256 2a99f3c5eb5c4287e025e4b65f5bc296909b2c5298d98cc9088e1536dd42fdff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f9ea77aee18bb245f83b5e18473a76d51ed0d9e0d213c282d01a13bd7e7bb52d
MD5 3885e739e3cd83101ac137ba74d4de46
BLAKE2b-256 e4b90f00a7a74e8cd08932c340fd2d7c3ec2ea0b4d09e2d5d30065c49962536a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a0628a166bcb13b538aa74df33fe7291df81c1b67def46a78ae66127db2b4371
MD5 823fb55c719da3d05d7a1815741645c3
BLAKE2b-256 9a64f87af012666fc07fba7ad8938aa9675df5c1d1912a5b39d1f681080668f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6b4db3ec21e2e07d71fa29429921a4aa684c465eda04aa6790f64c58501c75c1
MD5 578c95173861e6a01b0923e486a49c47
BLAKE2b-256 036628a65ac5f6c7a6ed699e7ee6b814fceecf2a638ac3195d02a1d48c9ba1c8

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