torchtyping
Runtime type annotations for the shape, dtype etc. of PyTorch Tensors.
Decision gist · record as of 2026-08-14
Yes, if you are actively developing PyTorch models and want runtime shape validation. The low install friction and permissive license make adoption straightforward. However, be aware that the package is aging and the author recommends jaxtyping for new projects due to better static type checker support. If you need static type checking or are starting a new project, consider jaxtyping instead; if you have an existing codebase using torchtyping or prefer runtime-only validation, it remains functional.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires typeguard <3.0.0 if using runtime checking; Python >=3.7 and PyTorch >=1.7.0.
- Low friction installation with only torch and typeguard as runtime dependencies.
- Maintenance status is aging—last release was in 2024—but the repository remains active and unarchived with 1484 stars.
License · maintenance · safety
Apache-2.0 (permissive) — Apache-2.0 permissive license allows commercial and private use with minimal restrictions; suitable for most projects.
last release 2024-08-01 (743 days) · last repo commit 2025-05-02 · 1,484 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 186,194 downloads/mo, #9,992 on PyPI
Alternatives
Verify before relying
pip install torchtyping typeguard
from torch import rand
from torchtyping import TensorType, patch_typeguard
from typeguard import typechecked
patch_typeguard()
@typechecked
def func(x: TensorType["batch"], y: TensorType["batch"]) -> TensorType["batch"]:
return x + y
func(rand(3), rand(3)) # works- Whether static type checkers (mypy, pyright) fully recognize TensorType annotations without additional configuration
- Current adoption rate and community support level relative to the newer jaxtyping recommendation
- Whether the package remains actively maintained beyond the most recent release date
What it is and what it does
torchtyping lets you annotate PyTorch tensors with their expected shape, dtype, layout, and dimension names directly in function signatures. Instead of writing comments like `# x has shape (batch, hidden_state)`, you write `x: TensorType["batch", "hidden_state"]`, making tensor contracts explicit and machine-readable. When typeguard is installed and enabled, these annotations are checked at runtime to catch shape mismatches and dtype errors early.
The package integrates with typeguard for optional runtime validation and pytest for test-time checking, so you can enforce tensor contracts without runtime overhead in production. It supports flexible shape specifications (exact sizes, named dimensions, variable batch dimensions with `...`), multiple dtype checks, and extensible custom validation rules. However, the author now recommends jaxtyping for new projects, citing better static type checker compatibility.
Use it for
- Document tensor shapes in neural network functions to prevent shape mismatch bugs during model development.
- Validate batch dimensions and channel sizes at runtime during training to catch data pipeline errors early.
- Enforce consistent dimension naming across a codebase to improve code clarity and reduce shape-related debugging.
- Test tensor contracts in pytest with automatic typeguard patching to catch shape violations in unit tests.
- Combine with typeguard's import hook to automatically check all tensor operations in a module without manual decorators.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you are actively developing PyTorch models and want runtime shape validation.
The low install friction and permissive license make adoption straightforward. However, be aware that the package is aging and the author recommends jaxtyping for new projects due to better static type checker support. If you need static type checking or are starting a new project, consider jaxtyping instead; if you have an existing codebase using torchtyping or prefer runtime-only validation, it remains functional.
Install
torchtyping on PyPI
Before you install
Low friction installation with only torch and typeguard as runtime dependencies. Maintenance status is aging—last release was in 2024—but the repository remains active and unarchived with 1484 stars.
Requires typeguard <3.0.0 if using runtime checking; Python >=3.7 and PyTorch >=1.7.0.
License in practice
Apache-2.0 permissive license allows commercial and private use with minimal restrictions; suitable for most projects.
Quickstart
pip install torchtyping typeguard
from torch import rand
from torchtyping import TensorType, patch_typeguard
from typeguard import typechecked
patch_typeguard()
@typechecked
def func(x: TensorType["batch"], y: TensorType["batch"]) -> TensorType["batch"]:
return x + y
func(rand(3), rand(3)) # works
Verify before relying
- Whether static type checkers (mypy, pyright) fully recognize TensorType annotations without additional configuration
- Current adoption rate and community support level relative to the newer jaxtyping recommendation
- Whether the package remains actively maintained beyond the most recent release date
Package facts
| License | Apache-2.0 permissive |
| Python support | Supports the current Python release >=3.7.0 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 2 packagestorchtypeguard |
| Maintenance | Aging 743 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 186,194 / month, #9,992 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 3 - AlphaFramework :: PytestIntended Audience :: DevelopersIntended Audience :: Financial and Insurance IndustryIntended Audience :: Information TechnologyIntended Audience :: Science/ResearchLicense :: OSI Approved :: Apache Software LicenseNatural Language :: EnglishProgramming Language :: Python :: 3Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonTopic :: Scientific/Engineering :: Artificial IntelligenceTopic :: Scientific/Engineering :: Information AnalysisTopic :: Scientific/Engineering :: Mathematics |
Evidence: torchtyping-0.1.5-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “pytorch tensor type annotations”
- torchtypingAdds type annotations for PyTorch tensor shape, dtype, layout, and…
- jaxtypingProvides type annotations and runtime type-checking for array shape…
- torch-complexProvides a Python class wrapping real and imaginary PyTorch tensors…
Give your agent the search over MCP, or paste the wish link into any chat.
More Artificial Intelligence packages
LiteLLM provides a unified Python interface to call 100+ LLM providers (OpenAI, Anthropic, Gemini, Bedrock, Azure, and others) using OpenAI-compatible API format, available as both a Python SDK and a self-hosted AI Gateway proxy server.
Install it if you need to work with multiple LLM providers or want to centralize LLM routing in your organization.
Client library and CLI tool for downloading, uploading, and managing models, datasets, and repositories on the Hugging Face Hub platform.
Install it if you work with Hugging Face Hub models or datasets.
LangChain provides a framework for building agents and LLM-powered applications by composing language models, tools, and memory through a unified API that abstracts over multiple model providers.
hf-xet provides chunk-based deduplication and efficient file transfer for the Hugging Face Hub, enabling faster uploads and downloads of large files with local disk caching.
Tokenizers converts raw text into token sequences for NLP models, with support for training custom vocabularies and using pre-built tokenizers (BPE, WordPiece) optimized for speed via Rust.
Transformers provides a unified framework for loading, fine-tuning, and running state-of-the-art pretrained models across text, vision, audio, video, and multimodal tasks using PyTorch, JAX, or TensorFlow.
Install it if you need to run or train any transformer-based model for NLP, vision, audio, or multimodal tasks.
See also jaxtyping · lovely-tensors · typeguard · spmd-types · torch-complex · safetensors · nptyping · torch · rotary-embedding-torch · pytorch