Skip to main content

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()
    balance = client.control_plane.billing.balance.get()

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, under src/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 inputs
  • docs/api-reference/serverless.openapi.yaml: generated Serverless inference OpenAPI output
  • openapi/tensormesh/**/*.swagger.json: canonical Control Plane Swagger sources
  • openapi/.generated/tensormesh-api/specs/**/*.openapi.json: normalized generated Control Plane OpenAPI outputs
  • docs/openapi/.generated/tensormesh-api/published-specs/**/*.openapi.json: published generated Control Plane OpenAPI outputs materialized locally for docs validation
  • docs/docs.base.json: hand-maintained Mintlify config source
  • docs/docs.json: generated Mintlify config and navigation
  • src/tensormesh/: Tensormesh Python SDK implementation
  • src/tensormesh_cli/: Tensormesh CLI implementation
  • scripts/: 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
  • jq for 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

  1. 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.

  1. Start the docs site locally:
npm run dev
  1. Optional: log in to the Control Plane:
./.venv/bin/tm auth login
./.venv/bin/tm auth whoami
  1. Optional: send a serverless inference smoke test:
./.venv/bin/tm infer chat \
  --api-key YOUR_INFERENCE_API_KEY \
  --model YOUR_SERVERLESS_MODEL_NAME \
  --json '[{"role":"user","content":"Say hello."}]'

gateway_api_key is the CLI config name for the same underlying inference API key the SDK accepts as inference_api_key. Set it under [overrides] in config.toml, or pass --api-key per request.

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:

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 serverless inference:

from tensormesh import Tensormesh
from tensormesh.types import ChatMessage

with Tensormesh(
    inference_api_key="YOUR_INFERENCE_API_KEY",
) as client:
    stream = client.inference.serverless.chat.completions.create(
        model="SERVERLESS_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_HOME when you want the CLI to use a different local root for both config.toml and auth.json.
  • The SDK default Control Plane base in this repo is https://api.tensormesh.ai, and it can be overridden with control_plane_base_url or TENSORMESH_CONTROL_PLANE_BASE_URL.
  • The CLI targets the same host via --controlplane-base, TENSORMESH_CONTROL_PLANE_BASE_URL, or top-level controlplane_base in config.toml.
  • Control Plane auth lives at ~/.config/tensormesh/auth.json by default, or at $TM_CONFIG_HOME/auth.json when TM_CONFIG_HOME is set.
  • ~/.config/tensormesh/config.toml is the canonical CLI config file by default, or $TM_CONFIG_HOME/config.toml when TM_CONFIG_HOME is set.
  • When TM_CONFIG_HOME is unset, ./.venv/bin/tm auth login stores Control Plane tokens in ~/.config/tensormesh/auth.json.
  • When TM_CONFIG_HOME is unset, ./.venv/bin/tm config init writes the canonical config file to ~/.config/tensormesh/config.toml.
  • Global CLI options such as --output must come before the subcommand: tm --output json auth status.
  • ./.venv/bin/tm auth whoami is the live bearer-token check and uses GET /auth/profile.
  • ./.venv/bin/tm auth print-token --yes-i-know prints the raw bearer token for controlled scripts.
  • Serverless inference commands accept --api-key and --model per request, or read gateway_api_key from [overrides] in the active config.toml.

Example:

./.venv/bin/tm auth login
./.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 using shellcheck from your PATH or ./.venv/bin
  • npm run build:python-dist: build SDK-first Python wheel artifacts, checksums, and the release manifest under dist/python
  • npm run build:python-sdist: build the source distribution into dist/python
  • npm run dev: start Mintlify locally
  • npm run doctor: check local prerequisites and repo state
  • npm run clean: remove local caches and build artifacts
  • npm 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 navigation
  • npm test: run the fast network-free local verification path without regen
  • npm run verify:python: run compile, ShellCheck, Ruff, and Python tests with coverage
  • npm run verify:compatibility: run opt-in compatibility tests for removed surfaces and migration behavior
  • npm 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 from dist/python by default
  • npm run verify: run sync plus CI-parity local validation without network probes
  • npm run verify:network: run live inference smoke tests; this requires gateway_api_key set under [overrides] in config.toml, 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.yml runs 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 and then runs npm run verify:network without changing the default network-free CI contract.

Documentation Map

Use these docs by audience and task:

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 with npm 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.json and let npm run sync regenerate docs/docs.json.
  • docs/tensormesh-api/publish-manifest.json declares merged published Control Plane nav specs such as the combined Model surface.
  • docs/cli/reference/**/*.mdx is generated from the Click command tree plus structured metadata attached in src/tensormesh_cli/docs_meta.py.

Governance

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

tensormesh-0.2.0.tar.gz (122.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tensormesh-0.2.0-py3-none-any.whl (170.7 kB view details)

Uploaded Python 3

File details

Details for the file tensormesh-0.2.0.tar.gz.

File metadata

  • Download URL: tensormesh-0.2.0.tar.gz
  • Upload date:
  • Size: 122.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tensormesh-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1b5e5d54b8ae15b1c3730b6e5a34f3b837d338ac912f7c3a91f31c212fe55ed4
MD5 2eccbf5741aa2b254a1d37e233268115
BLAKE2b-256 e2118798b9d8b1b1af21fb0aaf04943e0b05085f675dabda0f5841d3611f6dd6

See more details on using hashes here.

Provenance

The following attestation bundles were made for tensormesh-0.2.0.tar.gz:

Publisher: release.yml on Tensormesh-Production/tensormesh-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tensormesh-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tensormesh-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 170.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tensormesh-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af43aaec38f5dfdbefb36d5d19bfc8d379eafa2c5bcabddb897f0bbffc7a7486
MD5 1183399577e8dcbbacc951f323d17d69
BLAKE2b-256 dc871ffa193cc02c671b16c34a070eefe7790c27b1a0756229f7dc76f829fb84

See more details on using hashes here.

Provenance

The following attestation bundles were made for tensormesh-0.2.0-py3-none-any.whl:

Publisher: release.yml on Tensormesh-Production/tensormesh-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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