skillfed

pytensor

Optimizing compiler for evaluating mathematical expressions on CPUs and GPUs.

pytensor v3.3.0 2.2M downloads/30d#3,217 on PyPI636
Permissive license BSD-3-Clause Active released

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 on this page — 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

pytensor on PyPI

pip

pip install pytensor

uv

uv add pytensor

poetry

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 the current Python release (<3.15,>=3.12)
Install friction low — pure-Python wheel
Runtime dependencies 5 — setuptools, scipy, numpy, numba, filelock
Maintenance actively maintained — 2 days since the last release
Last repo commit
First released
Downloads 2,197,832/month — #3,217 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pytensor-3.3.0-py2.py3-none-any.whl

Keywords: pytensor, math, numerical, symbolic, blas, numpy, autodiff, differentiation

Development Status :: 6 - MatureIntended Audience :: DevelopersIntended Audience :: EducationIntended Audience :: Science/ResearchOperating System :: MacOSOperating System :: Microsoft :: WindowsOperating System :: POSIXOperating System :: UnixProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Free Threading :: 1 - UnstableTopic :: Scientific/Engineering :: MathematicsTopic :: Software Development :: Code GeneratorsTopic :: Software Development :: Compilers

Tags

symbolic math expressions pythonautomatic differentiation librarytensor computation frameworkmathematical expression compilernumpy array optimizationgradient computationstatic computation graph
symbolic-computationautodiffprobabilistic-programming

More Mathematics packages