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.
Metadata
Release files for tensorzero 2026.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tensorzero-2026.6.0.tar.gz | 2.3 MB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| tensorzero-2026.6.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| tensorzero-2026.6.0-cp310-abi3-musllinux_1_2_x86_64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ x86-64 | Details |
| tensorzero-2026.6.0-cp310-abi3-musllinux_1_2_aarch64.whl | CPython 3.10 | abi3 | Linux musl 1.2+ ARM64 | Details |
| tensorzero-2026.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| tensorzero-2026.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| tensorzero-2026.6.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 245.7 MB
Release files / tensorzero-2026.6.0.tar.gz
| Download URL | tensorzero-2026.6.0.tar.gz |
|---|---|
| Size | 2.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d27d4b79c412c888d1edf0d0a9ec99a664976a63cb4e6568a35e3e2529990784
|
|
BLAKE2b-256 checksum How to use checksums |
3425932f78db3755656a969f0c023b65742f501a3763a6ba9b5f6ac231ba580e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.13.1
|
Release files / tensorzero-2026.6.0-cp310-abi3-win_amd64.whl
| Download URL | tensorzero-2026.6.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 37.4 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
832b46d04de255a9ef0ca5f5db3e33d75c6bc31fa33cd15efccb0e81ada8d2d1
|
|
BLAKE2b-256 checksum How to use checksums |
4a20b4b0194315095193a92f4930469248e2e184c96ec4b06070333aa2fa3bea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.13.1
|
Release files / tensorzero-2026.6.0-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | tensorzero-2026.6.0-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 42.5 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
50f8c6bd6ecf321d2cc94596d47d8e749fbf9e08ae0baa75ee024eb72605f9f4
|
|
BLAKE2b-256 checksum How to use checksums |
b1823e26232f7bcd9b0a16a6090b5227cde743b8aeaebe0750bb68c4eb9e9f26
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.13.1
|
Release files / tensorzero-2026.6.0-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | tensorzero-2026.6.0-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 41.6 MB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
4539c846b68b62957fc76ba64df154b1c00d0a5d206e1b7b2a8ee2dc8a7b8b2a
|
|
BLAKE2b-256 checksum How to use checksums |
dcdfd66c5832c4cd77f2d700691072c5ea84c1539b5e7b7867e972de981b426d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.13.1
|
Release files / tensorzero-2026.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | tensorzero-2026.6.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 42.2 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e23151baa7d3841808354d2517750b786cfa7680336e7762ece67e8fa185ba68
|
|
BLAKE2b-256 checksum How to use checksums |
d13d6b99b1992c7031753825cad1fa9623d09820135bef9a8ab93524b2862b4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.13.1
|
Release files / tensorzero-2026.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | tensorzero-2026.6.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 41.4 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
3db2adf01b0737800966a4e1be592eb5e57ffc7549658263d3d97a7a45ed107f
|
|
BLAKE2b-256 checksum How to use checksums |
231f002bcca5eaebba838a247e269adc21d5f8f644cd5619b976168b2be8d032
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.13.1
|
Release files / tensorzero-2026.6.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | tensorzero-2026.6.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 38.4 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
7a99799e9a3a924984573ace1e16e2ac56c28888c30290be48b7ea7423390b55
|
|
BLAKE2b-256 checksum How to use checksums |
eee8a791e45a9dc5c258613c46b7d8438fe6df25942ccebc2abf609a822acd0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.13.1
|