Skip to main content

tenspec

Declare what an array must be, beside the value it describes, and check it at one boundary.

Tenspec moves the shape and dtype checks from the top of a function into its signature, where a reader and a type checker both see them. It accepts or refuses the array the caller passed. It converts nothing, moves nothing, and copies nothing, unless the declaration names a transform that copies.

This is an early release, at version 0.1.0. The interface can change before version 1.0.

Install

Install it with pip, or with uv. Either one is enough, so run the line for the tool you use:

pip install "tenspec[numpy]"   # or: uv add "tenspec[numpy]"

Name the array library you need as an extra: numpy or torch. import tenspec loads neither one. It needs Python 3.13 or newer.

What it gives you

  • Ordinary types. A declaration is an ordinary annotation carrying your backend's array type, so a type checker reads it and untouched code still runs. The checkers, the settings they need and their measured limits are on Type checkers and Ruff.
  • Pydantic boundaries, natively. TensorContracts relates the fields of your own model inside one model validation.
  • Runtime checks are opt in. An annotation alone performs no runtime work.
  • Transforms are explicit. A value changes only when a declaration names a transform, and the runtime verifies the result kept its class, shape, native dtype and device.

The three entry points

Entry point Use it for
@checked a function or a method, with its arguments and its return
TensorContracts a Pydantic model, whose related fields share one boundary
validate(value, annotation) one value, or one tuple of related values
from typing import Literal as Shape

import numpy as np

from tenspec import checked
from tenspec.numpy import Float


@checked
def weigh_columns(
    values: Float[Shape["rows features"]], weights: Float[Shape["features"]]
) -> Float[Shape["rows features"]]:
    return values * weights


print(weigh_columns(np.ones((3, 4)), np.array([1.0, 2.0, 3.0, 4.0])).shape)

weights must cover as many features as values has columns. A disagreement is a run-time refusal naming the axis, both extents, and the bindings the boundary held.

No type checker compares two shapes. A shape that disagrees is a run-time refusal, never a static error.

Documentation

The documentation site holds the guide, the API reference and two executed tutorials. The repository holds the source.

Attribution

The shape notation follows jaxtyping, which is MIT licensed. jaxtyping is not a dependency of this package.

License

MIT. See LICENSE.

Metadata

Release files for tenspec 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tenspec 0.1.0
File Size Uploaded Provenance
tenspec-0.1.0.tar.gz 55.0 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for tenspec 0.1.0
File Interpreter ABI Platform
tenspec-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 95.4 kB

Release files / tenspec-0.1.0.tar.gz

Download URL tenspec-0.1.0.tar.gz
Size 55.0 kB
Tags Source
SHA-256 checksum
How to use checksums
57ef5fd241b790e6558593ec9d2b7a63229f9ced2c4a46e2365073afcaf3d057
BLAKE2b-256 checksum
How to use checksums
f6a44f7dc8edb4127c10a0331bc50f546f6faef8e0581713add1a6a5dfb5c316
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Release files / tenspec-0.1.0-py3-none-any.whl

Download URL tenspec-0.1.0-py3-none-any.whl
Size 40.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a26936cd1ab5c4750f51472ed6cf39400493f5f6abecce3f7cd66c014c76df5
BLAKE2b-256 checksum
How to use checksums
b7a8c06351232e686a8964f73e2412a14e9b7bd0696b0b8c83f66ed942ecb1f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

Security for tenspec 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tenspec-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page