PyTensor is a Python library that allows one to define, optimize, and efficiently evaluate mathematical expressions involving multi-dimensional arrays. It provides the computational backend for PyMC.
Features
A hackable, pure-Python codebase
Extensible graph framework suitable for rapid development of custom operators and symbolic optimizations
Implements an extensible graph transpilation framework that currently provides compilation via C, JAX, and Numba
Contrary to PyTorch and TensorFlow, PyTensor maintains a static graph which can be modified in-place to allow for advanced optimizations
Getting started
import pytensor
from pytensor import tensor as pt
# Declare two symbolic floating-point scalars
a = pt.dscalar("a")
b = pt.dscalar("b")
# Create a simple example expression
c = a + b
# Convert the expression into a callable object that takes `(a, b)`
# values as input and computes the value of `c`.
f_c = pytensor.function([a, b], c)
assert f_c(1.5, 2.5) == 4.0
# Compute the gradient of the example expression with respect to `a`
dc = pytensor.grad(c, a)
f_dc = pytensor.function([a, b], dc)
assert f_dc(1.5, 2.5) == 1.0
# Compiling functions with `pytensor.function` also optimizes
# expression graphs by removing unnecessary operations and
# replacing computations with more efficient ones.
v = pt.vector("v")
M = pt.matrix("M")
d = a/a + (M + a).dot(v)
pytensor.dprint(d)
# Add [id A]
# ├─ ExpandDims{axis=0} [id B]
# │ └─ True_div [id C]
# │ ├─ a [id D]
# │ └─ a [id D]
# └─ dot [id E]
# ├─ Add [id F]
# │ ├─ M [id G]
# │ └─ ExpandDims{axes=[0, 1]} [id H]
# │ └─ a [id D]
# └─ v [id I]
f_d = pytensor.function([a, v, M], d)
# `a/a` -> `1` and the dot product is replaced with a BLAS function
# (i.e. CGemv)
pytensor.dprint(f_d)
# Add [id A] 5
# ├─ [1.] [id B]
# └─ CGemv{inplace} [id C] 4
# ├─ AllocEmpty{dtype='float64'} [id D] 3
# │ └─ Shape_i{0} [id E] 2
# │ └─ M [id F]
# ├─ 1.0 [id G]
# ├─ Add [id H] 1
# │ ├─ M [id F]
# │ └─ ExpandDims{axes=[0, 1]} [id I] 0
# │ └─ a [id J]
# ├─ v [id K]
# └─ 0.0 [id L]
See the PyTensor documentation for in-depth tutorials.
Installation
The latest release of PyTensor can be installed from PyPI using pip:
pip install pytensor
Or via conda-forge:
conda install -c conda-forge pytensor
The current development branch of PyTensor can be installed from GitHub, also using pip:
pip install git+https://github.com/pymc-devs/pytensor
Background
Contributing
We welcome bug reports and fixes and improvements to the documentation.
For more information on contributing, please see the contributing guide.
A good place to start contributing is by looking through the issues here.
Release files for pytensor 3.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytensor-3.3.1.tar.gz | 5.2 MB | Details |
Built distributions (wheels)
Total release size: 41.5 MB
Release files / pytensor-3.3.1.tar.gz
| Download URL | pytensor-3.3.1.tar.gz |
|---|---|
| Size | 5.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db9b8d3e5b61b405fc25c974e1f4a088ca56c80985ee1d1591bdbaabade211e6
|
|
BLAKE2b-256 checksum How to use checksums |
151cbda38ebb5324989212064bb10415a13995d26f760b7c80868603b8ea2822
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-py2.py3-none-any.whl
| Download URL | pytensor-3.3.1-py2.py3-none-any.whl |
|---|---|
| Size | 1.6 MB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b397dc43f32ad5c6351474579869334e2d49d52e75b33ee590fe86561822349e
|
|
BLAKE2b-256 checksum How to use checksums |
79afbae467a73acd152bd84009c770cadada6cb979fabe80ae666dbec6d0eb53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp314-cp314t-win_amd64.whl
| Download URL | pytensor-3.3.1-cp314-cp314t-win_amd64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Windows x86-64 |
|
SHA-256 checksum How to use checksums |
f5fcffda072294cfee86fc18abcddbd887d93ccaf612bb8de4888f4110520891
|
|
BLAKE2b-256 checksum How to use checksums |
ef655b7cdf6d41e9100f7355733f78641f88b07f8db21a84ad8c4a5d7b5faf98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp314-cp314t-musllinux_1_2_x86_64.whl
| Download URL | pytensor-3.3.1-cp314-cp314t-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 2.5 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
0ad5c2a5d5a7ced17a35c79aa80b3f87cbdb69fdfb41bd6b5a1ac59ad532e62d
|
|
BLAKE2b-256 checksum How to use checksums |
c498466317ec9013ce0851b9c095be386bbd787fc7423fc86f8acee0fefbf575
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pytensor-3.3.1-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 2.5 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
da5335a843066077fdcaf38a896438a915dbacea6f36260592dd415ef4f89fb3
|
|
BLAKE2b-256 checksum How to use checksums |
11234f1b5aed0fbbab467d0259b08ac2ccab557a7f141a675d89f3f6b0ef03b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp314-cp314t-macosx_11_0_arm64.whl
| Download URL | pytensor-3.3.1-cp314-cp314t-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.0 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a2f23acc9b9351de4ff57ad47b88a300e2dd32a93fac9325a18fe438921c66f4
|
|
BLAKE2b-256 checksum How to use checksums |
86fffc934f96b3d4b9dad9e01fab76c7a04819f5444c547f70d9a2e6bb1c0369
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp314-cp314-win_amd64.whl
| Download URL | pytensor-3.3.1-cp314-cp314-win_amd64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.14 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
2bcc073525f3f05973212e88ac6bde84ae1cabe94b4304c48fe666a4b7763ae8
|
|
BLAKE2b-256 checksum How to use checksums |
cb623a0e1f78c64cdd6f637e95f4247c9656377991ba8ef45244b43c7de54d60
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp314-cp314-musllinux_1_2_x86_64.whl
| Download URL | pytensor-3.3.1-cp314-cp314-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 2.5 MB |
| Tags | CPython 3.14 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
b7c3d5faa4ff505e8b0015eba06f4d79e8df7312047f5a2c7f8f23491d3756f5
|
|
BLAKE2b-256 checksum How to use checksums |
b5aadca5d300e72d3e2481f31dbce6b47684cacd356ea046764328112eeec4fc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pytensor-3.3.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 2.5 MB |
| Tags | CPython 3.14 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
6d2ca6d829734d77267ab02fb00cf35c597e2f433a57f13b522e883b97028f3b
|
|
BLAKE2b-256 checksum How to use checksums |
4886fba5bbf9c36f3a826d6cd57f88c352047f50f940ca273a570cd51ad185db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | pytensor-3.3.1-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
322827c8d80459c305f07e5de6d81f30b237eb89e23e002e81cfa2ecbb502851
|
|
BLAKE2b-256 checksum How to use checksums |
343370855233f7b7e1fb55ee2d1a0e2de618149745f8a6de7cfaa9d67b365c10
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp313-cp313-win_amd64.whl
| Download URL | pytensor-3.3.1-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
5cf8b8058c2345c3f836a38888a6ca013a1870a0f6070bccd6384f4c17801c49
|
|
BLAKE2b-256 checksum How to use checksums |
efc95d45cbdcf92fe639e6c77fd7492b2f89aa9f7c5cf01c91ee920cda32779f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp313-cp313-musllinux_1_2_x86_64.whl
| Download URL | pytensor-3.3.1-cp313-cp313-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 2.5 MB |
| Tags | CPython 3.13 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
a8e8b78e36d30e324c8e2175893145a416751a6c516a9d92f4943ce7fc5a8790
|
|
BLAKE2b-256 checksum How to use checksums |
e66530a57196f253ad7271f7827240b3be9a6751f2452c09d66b2f9aaf939597
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pytensor-3.3.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 2.5 MB |
| Tags | CPython 3.13 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
1b16174d9f81929bd3592384e44ab7ffe8014eab48b828f79f4da3a30079e1ee
|
|
BLAKE2b-256 checksum How to use checksums |
e19abed8fc69ae406f4059360b5c8638a9648c50289b6a96aa64552591b715d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | pytensor-3.3.1-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f0beb44cfeea5fd3b9dc79b6469c4eb1b68ab328186c4678acfbab76f3910383
|
|
BLAKE2b-256 checksum How to use checksums |
6a8e2ae616629720d1d2ec26a418a62262261fffe9e1c9b2aab96e99c97b766f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp312-cp312-win_amd64.whl
| Download URL | pytensor-3.3.1-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
9b89aaacf6d2a87b9f3539c93615810e824ff885a5364f44afd2d7927ed147a4
|
|
BLAKE2b-256 checksum How to use checksums |
f5efba3691219e16ff465c34dd80c3c0248b5ba1e09964642a796c52fe4e4dc1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp312-cp312-musllinux_1_2_x86_64.whl
| Download URL | pytensor-3.3.1-cp312-cp312-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 2.3 MB |
| Tags | CPython 3.12 Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
97a4769d9c51a7a991e4bf84e6483ee14227f5d641564eb4ed3b9ad7e3dab5b8
|
|
BLAKE2b-256 checksum How to use checksums |
7eebf73f2996df6cec981f0be6b7c277782a81bd069cfed822854b576983249e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
| Download URL | pytensor-3.3.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 2.3 MB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
d717b0613405af995656d7bb6b3d15cbf9d80d87a36bfea4255fb44eb67ff5b6
|
|
BLAKE2b-256 checksum How to use checksums |
7b2366420dfaef672773c69a8446b1e77c549650bc56b3b37675d0f5cade0bf3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency logRelease files / pytensor-3.3.1-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | pytensor-3.3.1-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
75337168ba97e8413a11d83a639369a08cb49cd5d77f663d8897b6f10c1562e5
|
|
BLAKE2b-256 checksum How to use checksums |
d374f4bfef41c43594ab6e40bb2f7923f9d3a91a7fdf57641bfddb39a5d3cab4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
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 7, 2026.
Transparency log