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

Uploaded CPython 3.10+Windows x86-64

tensorzero-2026.3.0-cp310-abi3-musllinux_1_2_x86_64.whl (41.8 MB view details)

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

tensorzero-2026.3.0-cp310-abi3-musllinux_1_2_aarch64.whl (40.8 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tensorzero-2026.3.0-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.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (40.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

tensorzero-2026.3.0-cp310-abi3-macosx_11_0_arm64.whl (37.7 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: tensorzero-2026.3.0.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.0.tar.gz
Algorithm Hash digest
SHA256 fc0422871b80d7c2c920976f6bb4590bee1120b45d6bcf99df3a96a1391056a3
MD5 8e787e34f6e2fbfe74ea429938e59d89
BLAKE2b-256 89bb8d80472df42c20c370082e42f21d0fa3910d1a1ee377c08cc7d667d9337d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4ad76c943f9acfbd1704b8942bedd37d0f91fb7e04a2f971e9aa3072a13a181f
MD5 7040cb7b7c1b3768943eb99a1fa3afdc
BLAKE2b-256 63a4053bc3b68946dd531c25cc7bd56ba975e7b566327f6baa48f256e62b15a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f77000455eb8ebd09f7058bbc5b5d9ecac6e79d740a1efc191698acba5a915e2
MD5 107fe8d4e9d99a84edb45b32a101b384
BLAKE2b-256 7ea3b9afdfdc28a1dc5cfefd84ff958fde424bdaf25b585cf3400236a7511a2f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 611839505cbd68e7cdf507464e7e2a521d398a2cdf70c349a64694d9846a5456
MD5 f5981164d1ed5654033e4c8cb35b07b6
BLAKE2b-256 729692d7636f849ef50100cdd401598ba26e4ee51a36c74b48ac49b64ad9f313

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5499577f44585e2bb55f3aec607ce055979b0b68ab64befbb42e2340ed847251
MD5 612e57b17fdda809363713a0db433838
BLAKE2b-256 f8ad4dec1fa5a73a8de3acde9e969971f07d766f31b30d5f32293d5415c646cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ff9e26bcb2e45fae5e7482df486de4a65f6b41345b690777a646d8efb2ef93cb
MD5 0445ffdf839647e46751398c6ed229fd
BLAKE2b-256 5db100099d451a414ea0bca2dcc7c1a06eed00d6e191b1f027977a729f3683be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.3.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5d788711b1cfd973435b0a14a755c7bcb7ad79922f8cf75258e107b1cac54fdf
MD5 47de86d2360ab33e213d7e7378e592f4
BLAKE2b-256 9042f9369527ae16583bb424dfdc396b7eff8176add3901e2f67b70f667a0147

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