Tensormesh Python SDK with CLI support.
Project description
Tensormesh SDK
Python SDK and CLI for Tensormesh AI inference and control-plane management.
Install
pip install tensormesh
tm version
pip install tensormesh is the primary one-click install path for the Python SDK and the bundled tm CLI. If you only want the CLI on macOS or Linux without managing Python 3.12+, use the public standalone installer described in docs/cli/guides/installation.mdx.
Python SDK Quick Start
from tensormesh import Tensormesh
from tensormesh.types import ChatMessage
# Inference
with Tensormesh(inference_api_key="YOUR_INFERENCE_API_KEY") as client:
completion = client.inference.serverless.chat.completions.create(
model="SERVERLESS_MODEL_NAME",
messages=[ChatMessage(role="user", content="Say hello.")],
)
print(completion.choices[0].message.content)
# Control Plane
with Tensormesh(control_plane_token="YOUR_CONTROL_PLANE_TOKEN") as client:
profile = client.control_plane.users.get_auth_profile()
models = client.control_plane.models.list()
Full SDK docs: docs/sdk/index.mdx
Repository
This repository has three primary surfaces:
- A published-docs path for the Python SDK under
docs/sdk/ - A Mintlify docs site under
docs/for Tensormesh inference APIs and generated Control Plane API reference. - A library-first Python SDK under
src/tensormesh/, with a Python CLI,tm, undersrc/tensormesh_cli/consuming that SDK for Control Plane and inference workflows.
Supporting scripts live under scripts/ for bootstrap, docs/spec sync, validation, and network verification.
No credentials are required for most local validation. npm run sync, npm test, npm run verify, and the default GitHub Actions verify workflow are all designed to run without Control Plane or gateway secrets. Credentials are only needed for the optional live network checks.
For SaaS upgrade checks against the latest published SDK wheel, use npm run verify:released-client-compatibility, which is also wired into the same-repo reusable/manual GitHub Actions workflow .github/workflows/released-client-compatibility.yml.
Release-facing docs:
Main Components
docs/api-reference/src/*.yaml: canonical inference API source inputsdocs/api-reference/on-demand.openapi.yaml: generated On-Demand inference OpenAPI outputdocs/api-reference/serverless.openapi.yaml: generated Serverless inference OpenAPI outputopenapi/tensormesh/**/*.swagger.json: canonical Control Plane Swagger sourcesopenapi/.generated/tensormesh-api/specs/**/*.openapi.json: normalized generated Control Plane OpenAPI outputsdocs/openapi/.generated/tensormesh-api/published-specs/**/*.openapi.json: published generated Control Plane OpenAPI outputs materialized locally for docs validationdocs/docs.base.json: hand-maintained Mintlify config sourcedocs/docs.json: generated Mintlify config and navigationsrc/tensormesh/: Tensormesh Python SDK implementationsrc/tensormesh_cli/: Tensormesh CLI implementationscripts/: bootstrap, sync, verify, and e2e helpers
Prerequisites
- Node.js 22 LTS recommended (see
.nvmrc; CI and Mintlify require a modern Node runtime) - Python 3.12 for repo scripts and the local venv
jqfor Swagger-to-OpenAPI conversion and network verification scripts
macOS example:
brew install node@22 jq
export PATH="/opt/homebrew/opt/node@22/bin:$PATH"
Quickstart
- Bootstrap the repo:
npm run bootstrap
That flow preflights Node TLS against the npm registry with the repo CA bundle, installs Node dependencies, creates .venv, and runs the fast local validation path.
- Start the docs site locally:
npm run dev
- Optional: log in to the Control Plane:
./.venv/bin/tm auth login
./.venv/bin/tm auth whoami
- Optional: sync managed gateway config and run a gateway smoke test:
./.venv/bin/tm auth login
./.venv/bin/tm init --sync
./.venv/bin/tm infer chat \
--json '[{"role":"user","content":"Say hello."}]'
tm init --sync fetches the gateway provider, API key, user id, and served
model name from the Control Plane, then stores them under
[managed] in the active config.toml state root. When TM_CONFIG_HOME is
unset, that file is ~/.config/tensormesh/config.toml.
gateway_api_key is the CLI config name for the same underlying inference API key the SDK accepts as inference_api_key, and gateway_model_id remains a config compatibility key whose value is the served model name sent as model.
@latest resolves from Control Plane model inventory, so it still requires
valid gateway credentials plus Control Plane auth:
./.venv/bin/tm infer chat \
--model @latest \
--json '[{"role":"user","content":"Say hello."}]'
Python SDK
The repository packages a library-first Python SDK from src/tensormesh/ with parallel sync and async clients.
Start with the published SDK docs:
- docs/sdk/index.mdx
- docs/sdk/guides/getting-started.mdx
- docs/sdk/guides/auth-and-config.mdx
- docs/sdk/guides/inference.mdx
- docs/sdk/guides/control-plane.mdx
- docs/cli/guides/control-plane-workflows.mdx
- docs/tensormesh-api/index.mdx
The Python SDK is published to PyPI as tensormesh, and the same distribution also installs the tm CLI. External Python applications should start from the SDK docs. CLI-only users on macOS or Linux can install the public standalone CLI distribution instead.
Basic serverless inference:
from tensormesh import Tensormesh
from tensormesh.types import ChatMessage
with Tensormesh(
inference_api_key="YOUR_INFERENCE_API_KEY",
) as client:
completion = client.inference.serverless.chat.completions.create(
model="SERVERLESS_MODEL_NAME",
messages=[ChatMessage(role="user", content="Say hello.")],
)
print(completion.choices[0].message.content)
Streaming on-demand inference:
from tensormesh import Tensormesh
from tensormesh.types import ChatMessage
with Tensormesh(
inference_api_key="YOUR_INFERENCE_API_KEY",
on_demand_base_url="https://external.nebius.tensormesh.ai",
on_demand_user_id="00000000-0000-0000-0000-000000000000",
) as client:
stream = client.inference.on_demand.chat.completions.create(
model="SERVED_GATEWAY_MODEL_NAME",
messages=[ChatMessage(role="user", content="Stream a short reply.")],
stream=True,
)
for text in stream.text_deltas():
print(text, end="")
Async serverless inference:
import asyncio
from tensormesh import AsyncTensormesh
from tensormesh.types import ChatMessage
async def main() -> None:
async with AsyncTensormesh(
inference_api_key="YOUR_INFERENCE_API_KEY",
) as client:
completion = await client.inference.serverless.chat.completions.create(
model="SERVERLESS_MODEL_NAME",
messages=[ChatMessage(role="user", content="Say hello.")],
)
print(completion.choices[0].message.content)
asyncio.run(main())
Control plane user profile lookup:
from tensormesh import Tensormesh
with Tensormesh(control_plane_token="YOUR_CONTROL_PLANE_TOKEN") as client:
profile = client.control_plane.users.get_auth_profile()
print(profile.display_name)
Control plane billing and support:
from tensormesh import Tensormesh
with Tensormesh(control_plane_token="YOUR_CONTROL_PLANE_TOKEN") as client:
balance = client.control_plane.billing.balance.get()
tickets = client.control_plane.support.tickets.list(size=20)
print(balance.units if balance is not None else "0")
print([ticket.subject for ticket in tickets.tickets])
Auto-pagination for paged control-plane resources:
from tensormesh import Tensormesh
with Tensormesh(control_plane_token="YOUR_CONTROL_PLANE_TOKEN") as client:
for transaction in client.control_plane.billing.transactions.auto_paging_iter(
page_size=100,
):
print(transaction.transaction_id, transaction.amount)
Raw and streaming inference responses:
from tensormesh import AsyncTensormesh
from tensormesh import Tensormesh
from tensormesh.types import ChatMessage
with Tensormesh(inference_api_key="YOUR_INFERENCE_API_KEY") as client:
raw_response = client.inference.serverless.chat.completions.with_raw_response.create(
model="SERVERLESS_MODEL_NAME",
messages=[ChatMessage(role="user", content="Say hello.")],
)
print(raw_response.json())
async def inspect_stream() -> None:
async with AsyncTensormesh(
inference_api_key="YOUR_INFERENCE_API_KEY",
) as async_client:
raw_stream = await async_client.inference.serverless.chat.completions.with_streaming_response.create(
model="SERVERLESS_MODEL_NAME",
messages=[ChatMessage(role="user", content="Stream a short reply.")],
)
async for line in raw_stream.iter_lines():
print(line)
Environment And Auth
For Python applications, prefer explicit SDK configuration through constructor arguments or environment variables. The SDK does not read CLI config or auth files by default.
The bullets below describe CLI and local-operator behavior:
- The standard persistent CLI setup lives under
~/.config/tensormesh/by default. - Set
TM_CONFIG_HOMEwhen you want the CLI to use a different local root for bothconfig.tomlandauth.json. - The SDK default Control Plane base in this repo is
https://api.tensormesh.ai, and it can be overridden withcontrol_plane_base_urlorTENSORMESH_CONTROL_PLANE_BASE_URL. - The CLI targets the same host via
--controlplane-base,TENSORMESH_CONTROL_PLANE_BASE_URL, or top-levelcontrolplane_baseinconfig.toml. - Control Plane auth lives at
~/.config/tensormesh/auth.jsonby default, or at$TM_CONFIG_HOME/auth.jsonwhenTM_CONFIG_HOMEis set. ~/.config/tensormesh/config.tomlis the canonical CLI config file by default, or$TM_CONFIG_HOME/config.tomlwhenTM_CONFIG_HOMEis set.- When
TM_CONFIG_HOMEis unset,./.venv/bin/tm auth loginstores Control Plane tokens in~/.config/tensormesh/auth.json. - When
TM_CONFIG_HOMEis unset,./.venv/bin/tm config initwrites the canonical config file to~/.config/tensormesh/config.toml. - When
TM_CONFIG_HOMEis unset,./.venv/bin/tm init --syncupdates[managed]in~/.config/tensormesh/config.tomlwith synced gateway values. - When
./.venv/bin/tm init --syncruns with--controlplane-base, it also persists thatcontrolplane_baseinto the activeconfig.tomlso later@latestand Control Plane-assisted flows stay on the same environment. - Global CLI options such as
--outputmust come before the subcommand:tm --output json auth status. ./.venv/bin/tm auth whoamiis the live bearer-token check and usesGET /auth/profile../.venv/bin/tm auth print-token --yes-i-knowprints the raw bearer token for controlled scripts.- On-Demand inference commands normally read provider, API key, user id, and served model name from
[managed]in the activeconfig.tomlstate root.
Example:
./.venv/bin/tm auth login
./.venv/bin/tm init --sync
./.venv/bin/tm config show --sources
Common Commands
npm run bootstrap: preflight Node TLS against the npm registry, install Node deps, create.venv, and run local validation./scripts/lint-shell.sh: lint repo shell scripts usingshellcheckfrom your PATH or./.venv/binnpm run build:python-dist: build SDK-first Python wheel artifacts, checksums, and the release manifest underdist/pythonnpm run build:python-sdist: build the source distribution intodist/pythonnpm run dev: start Mintlify locallynpm run doctor: check local prerequisites and repo statenpm run clean: remove local caches and build artifactsnpm run sync: regenerate generated Control Plane OpenAPI outputs, semi-generated control-plane SDK resources, async SDK mirrors, inference OpenAPI outputs, CLI reference pages, and docs navigationnpm test: run the fast network-free local verification path without regennpm run verify:python: run compile, ShellCheck, Ruff, and Python tests with coveragenpm run verify:compatibility: run opt-in compatibility tests for removed surfaces and migration behaviornpm run verify:dist: build fresh wheel and source-distribution artifacts, then smoke-test the packaged SDK+CLI install paths./scripts/smoke-test-python-sdist.sh: smoke-test a source distribution artifact fromdist/pythonby defaultnpm run verify: run sync plus CI-parity local validation without network probesnpm run verify:network: run live inference smoke tests; this requires a syncedgateway_api_key, plus the optional Control Plane proxy smoke when auth is available./.venv/bin/tm --help: inspect the current CLI surface
CI
- The default GitHub Actions CI path is token-free.
verify.ymlruns docs/spec validation, Python linting, unit tests with coverage, and dist packaging smoke tests without requiring Control Plane or gateway credentials. - Live dev/staging verification is separated into manual dispatch via
.github/workflows/live-verify.yml, which materializes CLI state from Control Plane secrets, runstm init --sync, and then runsnpm run verify:networkwithout changing the default network-free CI contract.
Documentation Map
Use these docs by audience and task:
- Getting started with the repo:
README.md - Developer setup and local environment: dev/setup.md
- Validation, CI parity, release flow, and network verification: dev/workflows.md
- CLI guides and command reference: docs/cli/index.mdx
- Docs/OpenAPI generation pipeline: dev/docs-system.md
- Mintlify hosting/proxy operational requirements: dev/runbook-mintlify-hosting.md
- Troubleshooting setup, TLS, and local verification: dev/troubleshooting.md
- Contributing expectations and generated-file rules: CONTRIBUTING.md
- Security reporting: SECURITY.md
- Docs site landing page and published API reference:
docs/index.mdx
Generated Files
- Do not hand-edit
openapi/.generated/tensormesh-api/specs/**/*.openapi.json. - Do not hand-edit
docs/openapi/.generated/tensormesh-api/published-specs/**/*.openapi.json. - Do not hand-edit
docs/cli/reference/**/*.mdx. - Update the source Swagger under
openapi/tensormesh/and regenerate withnpm run sync, which rebuilds the normalized raw specs, republishes the docs-facing specs, and refreshes the semi-generated SDK control-plane resource modules. - Hand-maintain
docs/docs.base.jsonand letnpm run syncregeneratedocs/docs.json. docs/tensormesh-api/publish-manifest.jsondeclares merged published Control Plane nav specs such as the combined Model surface.docs/cli/reference/**/*.mdxis generated from the Click command tree plus structured metadata attached insrc/tensormesh_cli/docs_meta.py.
Governance
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tensormesh-0.1.8.tar.gz.
File metadata
- Download URL: tensormesh-0.1.8.tar.gz
- Upload date:
- Size: 210.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e3f02e980856db9cc11d9e2b4c2a229901d7ad6a76c646fbceab633abbf17ae
|
|
| MD5 |
decd1677d41dfec87a329a77b84ccc27
|
|
| BLAKE2b-256 |
0d79ed1638317611bb5902672a8d490bc20d470ce78d6e64d312777724419f1e
|
Provenance
The following attestation bundles were made for tensormesh-0.1.8.tar.gz:
Publisher:
release.yml on Tensormesh-Production/tensormesh-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tensormesh-0.1.8.tar.gz -
Subject digest:
5e3f02e980856db9cc11d9e2b4c2a229901d7ad6a76c646fbceab633abbf17ae - Sigstore transparency entry: 1280552955
- Sigstore integration time:
-
Permalink:
Tensormesh-Production/tensormesh-sdk@37ecc9d578ada0bf038a85656986dfa90fb91302 -
Branch / Tag:
refs/tags/v0.1.8 - Owner: https://github.com/Tensormesh-Production
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@37ecc9d578ada0bf038a85656986dfa90fb91302 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tensormesh-0.1.8-py3-none-any.whl.
File metadata
- Download URL: tensormesh-0.1.8-py3-none-any.whl
- Upload date:
- Size: 170.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d587e5dc804eb75db34c7e0df48273530cbb5c0e85b58326139ad722152df981
|
|
| MD5 |
0dc3d25ce3b09b25f48b9cc6b34ee8d6
|
|
| BLAKE2b-256 |
390b7d677785e277d9d4bbf9180fb2fbfb21b9e5e8438a668d87cfd4782bb36a
|
Provenance
The following attestation bundles were made for tensormesh-0.1.8-py3-none-any.whl:
Publisher:
release.yml on Tensormesh-Production/tensormesh-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tensormesh-0.1.8-py3-none-any.whl -
Subject digest:
d587e5dc804eb75db34c7e0df48273530cbb5c0e85b58326139ad722152df981 - Sigstore transparency entry: 1280552969
- Sigstore integration time:
-
Permalink:
Tensormesh-Production/tensormesh-sdk@37ecc9d578ada0bf038a85656986dfa90fb91302 -
Branch / Tag:
refs/tags/v0.1.8 - Owner: https://github.com/Tensormesh-Production
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@37ecc9d578ada0bf038a85656986dfa90fb91302 -
Trigger Event:
push
-
Statement type: