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

Uploaded CPython 3.10+Windows x86-64

tensorzero-2026.5.1-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.1-cp310-abi3-musllinux_1_2_aarch64.whl (41.6 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

tensorzero-2026.5.1-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.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: tensorzero-2026.5.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.5.1.tar.gz
Algorithm Hash digest
SHA256 97d74bbe42a6646442a6c88285a3b8adaf601dc55de8e362c05c0a8ebf36e178
MD5 0ec80072a1553e74ca18922a153a3d61
BLAKE2b-256 2e3a7cde535a5c4a74d4bf6ee45967a7a37cb89d9a3e16bdeb493ff8e6341d47

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.5.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 bb0c9cf6e58e4d106bcec49b0b22e48dce0ee75e52d60a7075d62af165969ec3
MD5 69030ee98ae7fa7684a1193559781179
BLAKE2b-256 d2dce489ca97e56fd37ac4dc19ed050186101688d0d2e18b1ca78315f94d0aa1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.5.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 791523904a7f346b4898d034bfcf1dc70d0ccd4655ac92bc7089d022a36f2340
MD5 384abf3a38b00c1c822c385f3b8017aa
BLAKE2b-256 ad09c69cea9e8acd94e03b9cea0631d382412f9b53cb9f46e369e76c09aeca02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.5.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f212473b99508e5ead13c768cc2ea0d72057abc261d20266990c9c3ccd7996e4
MD5 3c88ff55eea67d7417b34da1a2bf066b
BLAKE2b-256 63ee455da95525396b3270380c4c694530f7be102ec3cb18c216f30991a94b24

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.5.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 55d9352cd3b9b38c135eea23e5e6a14f3fc131ecdcb31e1c9b306292391f787c
MD5 36d262287db35576ade43fdf8aa74609
BLAKE2b-256 2af4320299130722fc87625a910913880fdcc2e95fa34750b9ea570d9176e62f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.5.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2a5accbf322f2d9f68c1b6c2b07837146f94e3d890a13a8c0ff9074d58732b15
MD5 2a3faab73eff3be252df73ab1b6a3f8e
BLAKE2b-256 5c272764a54806157013ca1f7bf1f425aeffa2af848781b8eefde728dd875a2b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tensorzero-2026.5.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0a071a6efab6eb7ee2a62b86e192eb08ab1c7108623182fafdf7f35d60b483a0
MD5 6ed80000060b8c5f7ea42c9df462c3e4
BLAKE2b-256 061b23ed9b29e13da5950053da87685764fc2a39923599e42e35e2479257f346

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