--- id: pytensor version: "3.3.0" license: BSD-3-Clause license_treatment: permissive maintenance: active --- # pytensor — Optimizing compiler for evaluating mathematical expressions on CPUs and GPUs. License: permissive · Maintenance: active · Downloads: 2.2M/mo ## What it is and what it does PyTensor is a symbolic computation library that lets you define mathematical expressions as static graphs, then compile and optimize them before execution. Unlike eager frameworks, you first declare symbolic variables and operations, then convert the graph into a callable function that PyTensor optimizes—removing redundant operations and replacing computations with efficient BLAS routines. It supports automatic differentiation (gradients) and can compile expressions to C, JAX, or Numba for performance. The library is primarily used as the computational backend for PyMC, a probabilistic programming framework, but works standalone for any numerical computing task involving arrays and mathematical operations. It depends on numpy for array operations, scipy for scientific functions, and numba for JIT compilation; setuptools and filelock are build and locking utilities. The static-graph design allows advanced optimizations that dynamic frameworks cannot perform. Use it for: - Build probabilistic models and Bayesian inference pipelines using PyMC, which relies on PyTensor for expression evaluation. - Define and optimize complex mathematical expressions (e.g., neural network layers, physics simulations) before compilation. - Compute gradients automatically for optimization and machine learning without manually writing backpropagation. - Compile symbolic expressions to efficient C or GPU code via JAX or Numba for production inference. - Prototype numerical algorithms with symbolic manipulation and graph visualization before deployment. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. PyTensor is a Python library for defining, optimizing, and evaluating symbolic mathematical expressions on multi-dimensional arrays, with automatic differentiation and compilation to C, JAX, or Numba. Yes, if you need symbolic computation with automatic differentiation and graph optimization. PyTensor is actively maintained, has no known vulnerabilities, installs easily, and is the standard backend for PyMC. Install it if you're doing probabilistic programming, building custom optimized numerical pipelines, or need fine-grained control over computation graphs. Not necessary if you only need eager-mode tensor operations (use NumPy or PyTorch instead). ## Install pip install pytensor uv add pytensor poetry add pytensor ## Installing pytensor Before you install: Low install friction with a pure-Python wheel distribution. Active maintenance with a release within 2 days and recent commits; supports current Python versions (3.12–3.14). Depends on well-established packages: numpy, scipy, numba, setuptools, and filelock. License in practice: BSD-3-Clause is a permissive license; you may use, modify, and distribute PyTensor freely in commercial and private projects provided you include the license notice. Quickstart: pip install pytensor import pytensor from pytensor import tensor as pt a = pt.dscalar("a") b = pt.dscalar("b") c = a + b f_c = pytensor.function([a, b], c) print(f_c(1.5, 2.5)) # Output: 4.0 Verify before relying: - Whether JAX or Numba compilation backends require additional system dependencies or configuration beyond the listed runtime packages. - Performance characteristics and memory overhead compared to eager-execution frameworks for typical workloads. ## Package facts - License: BSD-3-Clause (permissive) - Python support: supports_current - Install friction: low - Maintenance: active - Downloads: 2.2M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags symbolic math expressions python, automatic differentiation library, tensor computation framework, mathematical expression compiler, numpy array optimization, gradient computation, static computation graph, symbolic-computation, autodiff, probabilistic-programming [View on SkillFed](https://skillfed.io/packages/pytensor) · [View on PyPI](https://pypi.org/project/pytensor/)