Skip to main content

Fast Rust-based Python extension for physical unit manipulation

Project description

pintrs

Fast physical units for Python, with a pint-compatible API and Rust performance.

pintrs is for people who like pint's ergonomics but not its runtime cost. It keeps the familiar UnitRegistry and Quantity workflow, with the hot path implemented in Rust.

  • Drop into common pint workflows with minimal code changes
  • Usually 8-150x faster on core operations
  • Works with NumPy, pandas, Babel, measurements, contexts, groups, and systems

Why pintrs

If your code spends real time creating quantities, parsing unit strings, or converting units, pintrs removes a lot of overhead without asking you to relearn the API.

  • Quantity creation: 9x faster
  • Parsing unit strings: 152x faster
  • Same-unit addition: 14x faster

Benchmarks below were measured with Python 3.12. Lower is better.

Operation pintrs pint Speedup
Quantity creation 0.37 us 3.33 us 9x
Parse string ("9.81 m/s**2") 0.55 us 50.21 us 91x
Conversion (km -> m) 0.94 us 7.43 us 8x
Conversion (km/h -> m/s) 1.71 us 13.30 us 8x
Addition (same units) 0.34 us 4.64 us 14x
Addition (compatible units) 1.03 us 11.56 us 11x
Multiply by scalar 0.25 us 5.31 us 21x
Multiply quantities 0.38 us 5.01 us 13x
Comparison (>) 0.12 us 1.16 us 10x
To base units 0.37 us 6.43 us 17x
Parse units ("kg * m / s ** 2") 0.26 us 38.85 us 152x
String formatting 0.44 us 7.20 us 16x

Run python examples/benchmark.py to reproduce the numbers. Install pint alongside pintrs for the comparison run.

Migrating from pint

If you already use pint, the change is intentionally small: replace pint with pintrs in your dependencies and swap your imports.

- pint
+ pintrs
- from pint import UnitRegistry
+ from pintrs import UnitRegistry

ureg = UnitRegistry()

Your existing quantity code should continue to look like pint code:

distance = 5 * ureg.kilometer
time = 2 * ureg.hour
speed = distance / time

print(speed)           # 2.5 kilometer / hour
print(speed.to("m/s")) # 0.6944... meter / second

Compatibility with pint

pintrs targets full API compatibility with pint.

That includes the core registry and quantity model, conversions and formatting, decorators, measurements, contexts, groups, systems, and integrations with NumPy, pandas, and Babel.

If you already have working pint code and performance is the problem, pintrs is designed to be the least disruptive upgrade path.

Installation

pip install pintrs

NumPy, pandas, and Babel integrations are available when those packages are installed.

What you get

  • The familiar pint API, with Rust underneath
  • Substantial speedups on quantity creation, parsing, conversion, arithmetic, and formatting
  • Support for NumPy, pandas, Babel, measurements, contexts, groups, systems, logarithmic units, and decorators
  • Type information for mypy and pyright

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pintrs-0.2.1.tar.gz (134.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pintrs-0.2.1-cp313-cp313-win_amd64.whl (416.2 kB view details)

Uploaded CPython 3.13Windows x86-64

pintrs-0.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (567.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pintrs-0.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (552.0 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

pintrs-0.2.1-cp313-cp313-macosx_11_0_arm64.whl (508.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pintrs-0.2.1-cp313-cp313-macosx_10_12_x86_64.whl (532.1 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

pintrs-0.2.1-cp312-cp312-win_amd64.whl (417.0 kB view details)

Uploaded CPython 3.12Windows x86-64

pintrs-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (567.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pintrs-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (552.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

pintrs-0.2.1-cp312-cp312-macosx_11_0_arm64.whl (508.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pintrs-0.2.1-cp312-cp312-macosx_10_12_x86_64.whl (532.6 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file pintrs-0.2.1.tar.gz.

File metadata

  • Download URL: pintrs-0.2.1.tar.gz
  • Upload date:
  • Size: 134.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for pintrs-0.2.1.tar.gz
Algorithm Hash digest
SHA256 746cf1f41bdd80888f6f486e2ce96532f59c1e15a5e4db3ceaa57d395ffc11fb
MD5 2cff4ea35da038ce7beb40e79a18b8d1
BLAKE2b-256 d1aabe15838d90d3b17e1e82260dc5b60298cecf744a3bc2af5f8f3bdfab5a81

See more details on using hashes here.

File details

Details for the file pintrs-0.2.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: pintrs-0.2.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 416.2 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for pintrs-0.2.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 bc7ca50347f4ada1630daabb48d85cadcec2e5dacecf99c337807554cc6fca85
MD5 5438d6c040eeb25df49145b6ba370ea3
BLAKE2b-256 f531fe44c0e51f5a46bc560e0855eddb3d1aa4b8bfda10e965e3e20c8054835f

See more details on using hashes here.

File details

Details for the file pintrs-0.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pintrs-0.2.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0ab4d6bcfd9eb427f8dd2b579cfd4eddcdaf624d85429d33604d6d7cf5574963
MD5 5ee26dc8877256186241d8dba1e24642
BLAKE2b-256 0b04aea13892d272864f3629f3b88629367ba85f1062b44af3b5944769e83937

See more details on using hashes here.

File details

Details for the file pintrs-0.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pintrs-0.2.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ef4a50876beb0b03bc93dcbbd4e2a42be6df10fd8aaa5579038077a701bfde54
MD5 2355abd8f395a2ac1828a6583e2b764e
BLAKE2b-256 784a7d0837c26f5108f4d456b02bfbe22c828cea7959a4993e236d7876239bbc

See more details on using hashes here.

File details

Details for the file pintrs-0.2.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pintrs-0.2.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1a4f6368165f6add22226594fc21efa9e6f85315807982c7969e9dad207b8429
MD5 f6fca3daa0e94b52db86f5cec94343dc
BLAKE2b-256 fd2d7f0e8b8215a3517df848562f30beba5788e34e79cc3d6f7bb08db712a5fb

See more details on using hashes here.

File details

Details for the file pintrs-0.2.1-cp313-cp313-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pintrs-0.2.1-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 aa658f48326aba43bb6e868a528863b4737f291f1eec69cde29c5c025b449101
MD5 2c9edbfa0960412490d2978c200a6278
BLAKE2b-256 997ada25d91abb53446cea995b2826c24553296d4eda50e8d21349a33aa09946

See more details on using hashes here.

File details

Details for the file pintrs-0.2.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: pintrs-0.2.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 417.0 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.12.6

File hashes

Hashes for pintrs-0.2.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6ada0f15e07f53d92e362a0d1e050d03f71fd3b431dbe8fd300ed6f5328c16be
MD5 d2baea09b195353166bb98a8f051bfd7
BLAKE2b-256 21fce50707a7f80e959eed907beecb5523a33bb2ce801f49b5062cd83b9ec593

See more details on using hashes here.

File details

Details for the file pintrs-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pintrs-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3b625c220bbcc4f7c2c1dd216c999a53ddb29fdc373768125b560ba48728ef09
MD5 cdc244cddcabb3c3aaec53644bf68ab8
BLAKE2b-256 be8f65b9cde09346f33c15f0c73e91c4059b05515e9c3163d3fa08f1784abc09

See more details on using hashes here.

File details

Details for the file pintrs-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pintrs-0.2.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ab25c912fa6357c431eda50378012b28b4b276ea9f843e5fef6f647dee2ccedd
MD5 90f0f18d7bad4f9ae15a3407291914b9
BLAKE2b-256 4f1aebaa56e4be125408e45098c1074ff40da5268d687c238b83cd04a8f95eb5

See more details on using hashes here.

File details

Details for the file pintrs-0.2.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pintrs-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ce97ef0bad19e8085637f55cd285fd4e57619c547fd8fede9a593bddcc53277c
MD5 4a6420d73a6b7906cc6207d8d244b760
BLAKE2b-256 54c977cc0ff7cf6ae8d55ce710054622bcc8b6a139e7ba50e96497a67514a6c8

See more details on using hashes here.

File details

Details for the file pintrs-0.2.1-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pintrs-0.2.1-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 46383ec12d63b33c8ebaeb81407a04cd386ee592c511637d0da5b48aa946bc8e
MD5 0e8e53eb692fa54856562033811d44fd
BLAKE2b-256 e553abf8b93109ebda02bb26211469768af622e5861ec39d9abfec5f43d3a794

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page