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.2.tar.gz (135.5 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.2-cp313-cp313-win_amd64.whl (416.0 kB view details)

Uploaded CPython 3.13Windows x86-64

pintrs-0.2.2-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.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (551.9 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

pintrs-0.2.2-cp313-cp313-macosx_11_0_arm64.whl (508.7 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.13macOS 10.12+ x86-64

pintrs-0.2.2-cp312-cp312-win_amd64.whl (416.5 kB view details)

Uploaded CPython 3.12Windows x86-64

pintrs-0.2.2-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.2-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.2-cp312-cp312-macosx_11_0_arm64.whl (508.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pintrs-0.2.2-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.2.tar.gz.

File metadata

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

File hashes

Hashes for pintrs-0.2.2.tar.gz
Algorithm Hash digest
SHA256 095d6adc9898d6ad0582774079114c9677290866e60d19770bff26d4f125217a
MD5 c4b9b6047e77927783505b8e776042a8
BLAKE2b-256 4fb27c22fc00f45de71966026f4c8849dd2e0b6463c50910336de71a2ab150f5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pintrs-0.2.2-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 416.0 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.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 85ef996921d756d561b169523d5c2ac6280eaf96bfb0359e81d42cb50cca317d
MD5 ec8c9604e27ec6ce424bba360c7c4f08
BLAKE2b-256 e7bc617d29518b1670acc6d8254099777bec18b17f77aa94dedeac17063ce4fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1b8119ec35229be3ae6f52bac7061bb249b9074e38f11a5b43cb342b50e9dcd3
MD5 456bd78d5deec6d496e7b046e3c94b04
BLAKE2b-256 8329f991ac7d6fee6d8b5bc4c071ac5f9b4581f6e02a824e6a949d17e2fb8cac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3a5765007bb2bebea2ad35d93cac0f03e98e7a7f345ae8724e9b5fe33b51fae8
MD5 58a5d87e21e9467b3081d2cf282a63f7
BLAKE2b-256 53c98ab5a3b790570e3121f6f6b70aeaf441f1e4c92e7e113b66386440552888

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d121a7403c4504849f41d6e987944f4ff615bcf1a34338c66ba38029a0181bd7
MD5 e8db793d129c44fb6ee1b7564a805abd
BLAKE2b-256 5f2b363d811e3a005355cedfc5d3c44ac03be1cc7ad7a92d8c07dbf03ccca3f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.2-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c77e9c25e74356cbf718efff4629726056467f09cd49734ee56bdf8e51d5d48b
MD5 9cd1f1d38b6cc17791505e575806d10a
BLAKE2b-256 bda8f934eed35a80a277ac140c184f5f8e7b298be18d5ab261f75def23cd87f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pintrs-0.2.2-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 416.5 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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 709499f8aaf7df902f9706ab081dc3bb458b056bb05bf09a3f53074a6e087763
MD5 b3ef412af2a60c42c74b691cc75083e7
BLAKE2b-256 43f33254d0595775b82120dde7cdeef9a5ae2ba7e4e24846385a73426fa65103

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8dfabb1efde81f295436e7645a47a33b212be33107d5e4f26661d34c3fd4d49c
MD5 b3b68cc802240c3a82913b3664e6d739
BLAKE2b-256 3f4d6543933cb60c300e5fa77a63c0057a66f9de47ae5c50ed932183ca9196dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 df93ae09c673d16418f8e87f8dfea0b8ab75c92de0a9ae092f6bcfe40dad0906
MD5 67e1b9319d71c4f4fd9eeeff67145326
BLAKE2b-256 01df66598081b0db6b389948d861f153d94f8792b0773ce5b836cecfc7fdfaea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5255debe5e2073762a28f060a3aff1e8025626f871bd4c15c67a66202aa0cc9d
MD5 4c3047544e3e6f2ecc5bdd13d45a99cc
BLAKE2b-256 3ab8bb8521e80fd86ff38fb2f0642dbbe44d067ea7c6423abcbf132723ab58d9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.2-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 1427d7ccea1bd008ecb269be5e8274df789919c7371ed9cd696f17ac85740f58
MD5 7523910deaa63e9832b1509278323a8b
BLAKE2b-256 6af4704cf9975ea024d65279d8d9cf09c43672bf630f8f8d39431c8d5145d1c9

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