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.4.tar.gz (135.6 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.4-cp313-cp313-win_amd64.whl (415.9 kB view details)

Uploaded CPython 3.13Windows x86-64

pintrs-0.2.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (567.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pintrs-0.2.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (551.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

pintrs-0.2.4-cp313-cp313-macosx_11_0_arm64.whl (508.4 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pintrs-0.2.4-cp313-cp313-macosx_10_12_x86_64.whl (531.8 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

pintrs-0.2.4-cp312-cp312-win_amd64.whl (416.6 kB view details)

Uploaded CPython 3.12Windows x86-64

pintrs-0.2.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (567.6 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pintrs-0.2.4-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.4-cp312-cp312-macosx_11_0_arm64.whl (508.6 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pintrs-0.2.4-cp312-cp312-macosx_10_12_x86_64.whl (532.3 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pintrs-0.2.4.tar.gz
Algorithm Hash digest
SHA256 d655eff161b8f7117d1f6be1ea869c30dd5cc2a147052e99bfb1fd84673474c0
MD5 fe45a041e3d011224fbefdc7a17c7e9a
BLAKE2b-256 cff0467286a97caedbd19301f59ed7923dbcd85c0073384309c284b29f2cc937

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pintrs-0.2.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 415.9 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.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 43a024ba74469f15454c7c19a98394ff1d367c1e77fee25a19005809d97cdb71
MD5 d92be328b49859b0725fd1927b2cf98c
BLAKE2b-256 631afc231038afd77bca083fcc3d22a41f8ecc83ca77dcadd55a9a47d6b81f95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 09c1f40f14b69e640b21a3ddc4ec6ea29f5af21731792823b573b3f6d4d0ea5d
MD5 97c2639ed659a0d43222e8c2c78dd353
BLAKE2b-256 27079bdacd80a84df06b0508408e581628d00a5cb30bf32a41948fb0519d1862

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2afed7c5a4c9a22418af03b31d46167aee08ba3f52abefa39a678d66b9fc135c
MD5 21f8ef0f4b0779a0a7e29969e4519640
BLAKE2b-256 20fccaa33d15555735585ca9142c1690ac9d3d7d2e25c13f4fdea3bd47da6abf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 98fcd4e28d3a15135ed91df540c59dbf64909f8229c8006506975d66e7f7f50b
MD5 703c73850a138063a94cc650d734f733
BLAKE2b-256 abb1a07b96fb4396230c9f551997130416daf5616a93fc85278a1a5b7f1122dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.4-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4bd1bab0ff3669685d24614f7beaf846592d6d9cc25b0027ec33c5d29b72e0e8
MD5 c4e6905571c36e2dcc929743ed1c69b0
BLAKE2b-256 fa4b19a995f0515fe3b8a22adbac8442b819fa6855bfd84b1965b32e25dd7465

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pintrs-0.2.4-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 416.6 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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 789535a73efcdd5984132ec31fd75355fe0967d3aa7c0d5707f48e4b03d63b01
MD5 cdbd5c3ad2fd51f56aa27aadc9ebfbde
BLAKE2b-256 1406d40130e604652f04e6e0d275bff7dad4f22b5752ad5682c2250d808a188d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ecf910c57c6ae461bc27dec4320c7d7499a5283bc69eddfbc2fa78a48d21e266
MD5 a63e70c5b296e3e9f72d22324f39c172
BLAKE2b-256 d1bb2aed588e18b895563a6804d85be5b3b53fa35edf7b962fe829f0bd483240

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a543d1f4eb0dc6fc8a922c6f1473ba53a548c6e738f97fafa72aca53bcece3e8
MD5 6e271186edcb90e96aa023eedd1f1801
BLAKE2b-256 ba0cdf4ff3393b09de520f9b86ec08d8d36acdc255d6012d15172368dd6e937d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e40ab81e8799e5867a5bbb689b7c198826f0fca9275d3d8320e538ff12f50106
MD5 8db34c96a419fc20693dbb89f5388c58
BLAKE2b-256 dd812118ffacd80d0b98ca081c6221ceeeb14740cdabde954bc1261c6b7367da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.4-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9519d46d0aa891e2abd60d00902d2bfd79dfcd3baab0ce189b4903f137580f61
MD5 e71cd514190cae783a391fb09fdea1f0
BLAKE2b-256 17d0422ca647b27932dfcfd080dc5f59208570c0bb15675c140c4e4c18299276

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