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.3.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.3-cp313-cp313-win_amd64.whl (416.0 kB view details)

Uploaded CPython 3.13Windows x86-64

pintrs-0.2.3-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.3-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.3-cp313-cp313-macosx_11_0_arm64.whl (508.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pintrs-0.2.3-cp313-cp313-macosx_10_12_x86_64.whl (531.9 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

pintrs-0.2.3-cp312-cp312-win_amd64.whl (416.7 kB view details)

Uploaded CPython 3.12Windows x86-64

pintrs-0.2.3-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.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (552.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

pintrs-0.2.3-cp312-cp312-macosx_11_0_arm64.whl (508.9 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pintrs-0.2.3-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.3.tar.gz.

File metadata

  • Download URL: pintrs-0.2.3.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.3.tar.gz
Algorithm Hash digest
SHA256 a8582f338e9ee8983785047f1e4cb911cdf50615d98f9d7ff19638439cb81df6
MD5 acdfe5575e5632c355fa8c21c6af9450
BLAKE2b-256 4176c97c61435483bc75bf9c7bf157354da77d1bcad48cbf72b72713dce69cc7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pintrs-0.2.3-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.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 0f54c27c6cd1686fbc3bee69cf884a854436803da25a212b0486403dad1d803a
MD5 d953c738697ad3de58edd1145311c376
BLAKE2b-256 31d1bec6f9e6cea2d7a4475483792d062da710a03d283b54502a19be59829c9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9a47fddcf6c73ac7a8b167d73bb9a85803ea92e20ac6896dac86be116a68fa93
MD5 88382c0f9097e5c30bb46950e23d8aca
BLAKE2b-256 1db4ca3b32936a532b455f6a72139e52e998b1bce0f5935569726820c214ad97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ee88b92a95eed5b622d8dab31823bb913cd41221a0e3a13815e1d360cee20306
MD5 aa2b2cf6705033002f3d40dcd3f8ca62
BLAKE2b-256 b7367f4256079a893689bc558203dbd8399223d46903abca49133ff4ac871360

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bad339e000e9ec342f980454e46f4a67d703e64148cffe6758a519f8e1a0b990
MD5 89b603ce986be331c82972e01892db98
BLAKE2b-256 e5d3a898b1d667055b97ee9ab9c948c4f7f743e0884e1fd0737e8c9f6a389bef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.3-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 6786fd1adf0686e03bf0068a7696104fb760d5970c7cefa8b1009f88e7dcbbcf
MD5 e7ce0c559a7cefa9ef4e5e4cf8e2d17d
BLAKE2b-256 fc89d1fa3118bfe6d001b1809886f61f1141b4e6cb66a9cc4ca8bbde41f81cf4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pintrs-0.2.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 416.7 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.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a2aef73059f12352eba91d675409adfcb2a6a60f00f5754f8bc882119eb57b75
MD5 26e6a22022c322ec107e1bdb340b08b6
BLAKE2b-256 620cd2b56feadecdc3ce4e89fc62e56eafb5ba0aaa0e459672c5e6fd279fc949

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1af9dbe8efe39de90dd28be4d8e9c9eb164d1a1d627fa2078aa2cc018cd4cc4c
MD5 469a9cc354486e615dff9ee811d440fc
BLAKE2b-256 e86ee675a23525176ae3a2f63906a1a687529fa2928b4441048ccc357d54ee94

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d783085a97b916e8423c1c2829a0814865d6e0bc816564bcbcd4998d3abc187f
MD5 340c8102aa2da52109c99468cc6c3d7e
BLAKE2b-256 f56d23f44c2c7c22c3ffde29abb94e3e1c47a3cd288e144592d62a01b5ab4480

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 28aee8e61b7f25c7cca38f9d31ea7a968821f9bcf47e675d1cc179693ef3d943
MD5 3765b0046c42dbadeb86a93b14f15caf
BLAKE2b-256 9b08c7140940ff40c8469a8f3ebcaf37f245113046513078f7251e9ef415eed7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.2.3-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 536d065345a2ea8a0cda202aa12c46eb04ff78bcc78ff62efbc3c05a22c54498
MD5 3a9f0910f0314455cc84e118e05a2696
BLAKE2b-256 4cd490719e6126eeac9543f65b0583678fa3cbd233e7027f4e7f03c46efde96a

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