Skip to main content
physure

Unit-aware, dimension-correct computing for Python — powered by a Rust core

Units, dimensions, and correlated uncertainty tracked through every calculation, with zero overhead under torch.compile / jax.jit.

PyPI crates.io CI Python 3.11–3.14 License: MIT


Why physure?

Most unit libraries make you choose between correctness and speed. physure (physics + measure) refuses the trade-off:

  • Correlated uncertainty propagation. Full sparse-covariance tracking between quantities (GUM-style), not just independent error bars. If x and y share history, x - y knows it.
  • Native-speed dimensional analysis. Unit arithmetic runs in Rust (~50 ns per operation) with rational exponents — no floating-point drift in dimensions, zero-copy buffer FFI to NumPy.
  • ML-ready. Quantity wraps NumPy, PyTorch, and JAX arrays. Under @physure.jit, units are validated at trace time and evaporate at runtime: ~1.17× vs. raw compiled PyTorch.
  • Static unit checking. A mypy plugin narrows Q_(3, "m/s") to Quantity[..., Literal["m/s"]], so unit mismatches can fail before your code even runs.
  • Zero runtime dependencies. pip install physure pulls in nothing else. NumPy/PyTorch/JAX/pandas support activates automatically when those packages are present.

Quick start

from physure import Q_

d = Q_(10, "km")
t = Q_(2, "hr")
print((d / t).to("m/s"))    # 1.3888888888888888 m/s

# Uncertainty propagates automatically — correlations included
g = Q_(9.8, "m/s^2", uncertainty=0.02)
m = Q_(2.5, "kg", uncertainty=0.001)
E = m * g * Q_(12, "m")
print(E.to("J"))            # (294.0 ± 0.61) J

Or straight from the command line — physure ships a unit-aware calculator and REPL:

$ python -m physure "500 N / 2 m^2 => kPa"
0.25 kPa

Highlights

Units that vanish at compile time

@physure.jit traces your function once, validates every dimension in Rust, then runs on raw tensors — dimensional safety with no per-call cost:

from physure import Q_, jit

@jit
def kinetic_energy(mass, velocity):
    return 0.5 * mass * velocity**2

kinetic_energy(Q_(10.0, "kg"), Q_(5.0, "m/s"))   # 125.0 kg·m²/s²
kinetic_energy(Q_(1.0, "m"), Q_(1.0, "s"))       # raises at trace time: incompatible units

Works with plain floats, NumPy arrays, PyTorch tensors (via __torch_dispatch__ + torch.compile), and JAX (jax.jit).

Uncertainty done properly

Choose the propagation mode globally or per-block:

import physure

physure.propagation_mode("correlated")     # full covariance (default: uncorrelated)

with physure.uncertainty_mode("uncorrelated"):
    ...                                    # scoped override

Backends include Gaussian (first-order), Monte Carlo, and Unscented Transform. Covariance lives in a sparse Rust store, so large lineages stay fast and memory stays flat.

Batteries included, loaded lazily

Pandas ExtensionArray, pydantic validation, SymPy symbolic quantities, unit-aware torch.nn layers, Arrow IPC serialization, plotting helpers, and a physics-as-text DSL (stress = 500 N / 2 m^2) — each activates only when you use it. Cold import stays around 20 ms.

How it compares

physure pint astropy.units unyt
Correlated uncertainty (covariance) ✅ — — —
Built-in uncertainty propagation ✅ via uncertainties limited —
Rust-accelerated core ✅ — — —
torch.compile / jax.jit compatible ✅ — — —
Static unit checking (mypy) ✅ — — —
Runtime dependencies none none astropy stack numpy
Ecosystem maturity new ✅ mature ✅ mature mature

If you need a battle-tested converter with a decade of integrations, pint and astropy are excellent. physure is for when you also need uncertainty you can defend and units inside compiled ML code.

Performance

Benchmark Result
Cold import ~21 ms
Unit multiply/divide (Rust core) ~54 ns
Scalar add with dimension check ~40 ns
10⁶-element tensor op, @torch.compile 1.17× vs. pure PyTorch
Covariance propagation (sparse blocks) ~7 µs

Full methodology and reproduction steps: BENCHMARKS.md.

Installation

pip install physure            # Rust-compiled wheel, no other dependencies
pip install "physure[numpy]"   # + NumPy/SciPy/Numba acceleration
pip install "physure[torch]"   # + PyTorch backend
pip install "physure[jax]"     # + JAX backend
pip install "physure[all]"     # everything

From source

git clone https://github.com/Alexisrx96/physure
cd physure
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh   # Rust, if needed
maturin develop --release
uv sync --group dev

Architecture

physure/                     # Cargo workspace root
├── physure-core/            # 🦀 Pure Rust physics engine — no FFI deps
│   └── src/                 #    units, quantity, covariance, uncertainty,
│                            #    symbolic, Arrow serialization
└── physure-python/          # 🐍 PyO3 bindings + Python application layer
    └── physure/
        ├── domain/          # Quantity, units, dimensions, uncertainty
        ├── application/     # Q_ factory, unit-system context, startup
        ├── backends/        # NumPy / PyTorch / JAX adapters
        ├── _jit/            # tracing + compile-time dimension checks
        ├── ext/             # grammar DSL, IO, pandas, numba
        └── nn/              # unit-aware neural network layers

The rule: physure-core is the single source of truth. All math lives in Rust; Python is a thin, zero-copy translation layer.

Documentation

Contributing

Issues and PRs are welcome. The quality bar is enforced in CI: ruff clean, tests green on Python 3.11–3.14 with ≥ 80 % coverage, and zero new SonarQube violations. See CLAUDE.md for the full development guide.

License

MIT — Irvin Torres

Metadata

Release files for physure 0.2.2

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

Source distribution (sdist)

Source distribution for physure 0.2.2
File Size Uploaded
physure-0.2.2.tar.gz 808.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for physure 0.2.2
File
physure-0.2.2-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
physure-0.2.2-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details
physure-0.2.2-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details
physure-0.2.2-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details
physure-0.2.2-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details

Total release size: 7.0 MB

Release files / physure-0.2.2.tar.gz

Download URL physure-0.2.2.tar.gz
Size 808.2 kB
Tags Source
SHA-256 checksum
How to use checksums
bf2c3633167f069412f64fa6a3c442049a1b52204843204a00fd9f79d0a649b0
BLAKE2b-256 checksum
How to use checksums
e166f3cd60a3ee46fef608e80a07aba1c4242eaceff879f7610403555b140458
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 Jul 21, 2026.

Transparency log

Release files / physure-0.2.2-cp311-abi3-win_amd64.whl

Download URL physure-0.2.2-cp311-abi3-win_amd64.whl
Size 1.2 MB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
454c8359e276e3fffa9a8bf2da731545f3e790d4a21fcba679a5b91e1dffffdd
BLAKE2b-256 checksum
How to use checksums
c22a88ad57cd772e42483ef4a5de09d8ae4cd5184e7b630aa08965df118857c9
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 Jul 21, 2026.

Transparency log

Release files / physure-0.2.2-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL physure-0.2.2-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.3 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
e4c4bab3193785691b56804ce9a52d1274fb7094996bd65f679e7b5e935e763f
BLAKE2b-256 checksum
How to use checksums
35b81b4c2a5bb70fe0c158e73246e33a49fd7545e1137c4c8037c67c06ea4bb8
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 Jul 21, 2026.

Transparency log

Release files / physure-0.2.2-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL physure-0.2.2-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.3 MB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
738bd75e0aadcf352847ae2beec4a300b98164ec4ca997298bcdc64f0c0aa24a
BLAKE2b-256 checksum
How to use checksums
b1996c154fd31d51457b065d6b5ff53c8cb8056e7430bc08f327f8ae0ec0548d
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 Jul 21, 2026.

Transparency log

Release files / physure-0.2.2-cp311-abi3-macosx_11_0_arm64.whl

Download URL physure-0.2.2-cp311-abi3-macosx_11_0_arm64.whl
Size 1.2 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
54e337c916e561f44fdda7983da3d558dab22d6947b04ad2ec64da53d6a296f9
BLAKE2b-256 checksum
How to use checksums
9109ad263f555e0f54984f777d05ff4edf8b45e0985d37319fefbca6aa802e61
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 Jul 21, 2026.

Transparency log

Release files / physure-0.2.2-cp311-abi3-macosx_10_12_x86_64.whl

Download URL physure-0.2.2-cp311-abi3-macosx_10_12_x86_64.whl
Size 1.3 MB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
56027bb5f9948ec8404fd75612314828a51d66fb3d72d0b7baaed961ab801012
BLAKE2b-256 checksum
How to use checksums
c0637e44c8dd08d9a977d44953a2b7b7ebe2cd9c2480f33e35a57c3df1980491
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 Jul 21, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.4

6 release files

0.2.3

6 release files

This release

0.2.2 This release

6 release files

0.2.1

6 release files

0.2.0

6 release files

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