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 7-100x 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: 10x faster
  • Parsing expressions like "9.81 m/s**2": 104x faster
  • Common conversions like km/h -> m/s: 8x faster

Benchmarks below were measured on this branch with Python 3.13.5. Lower is better.

Operation pintrs pint Speedup
Quantity creation 0.35 us 3.65 us 10x
Parse string ("9.81 m/s**2") 0.67 us 70.12 us 104x
Conversion (km -> m) 1.18 us 7.84 us 7x
Conversion (km/h -> m/s) 1.75 us 13.80 us 8x
Addition (compatible units) 0.88 us 12.01 us 14x
Multiply by scalar 0.13 us 5.88 us 46x
Multiply quantities 0.16 us 5.44 us 33x
Parse units ("kg * m / s ** 2") 0.88 us 23.66 us 27x
String formatting 0.29 us 8.41 us 29x

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.1.9.tar.gz (105.1 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.1.9-cp313-cp313-win_amd64.whl (393.1 kB view details)

Uploaded CPython 3.13Windows x86-64

pintrs-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (543.7 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

pintrs-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (531.2 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

pintrs-0.1.9-cp313-cp313-macosx_11_0_arm64.whl (488.8 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pintrs-0.1.9-cp313-cp313-macosx_10_12_x86_64.whl (512.4 kB view details)

Uploaded CPython 3.13macOS 10.12+ x86-64

pintrs-0.1.9-cp312-cp312-win_amd64.whl (393.8 kB view details)

Uploaded CPython 3.12Windows x86-64

pintrs-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (544.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

pintrs-0.1.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (532.3 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

pintrs-0.1.9-cp312-cp312-macosx_11_0_arm64.whl (488.3 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pintrs-0.1.9-cp312-cp312-macosx_10_12_x86_64.whl (512.8 kB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pintrs-0.1.9.tar.gz
Algorithm Hash digest
SHA256 4a609cdc4795d28c807ae46de971fd17057e89fe6795296bce01db0ac1aa6785
MD5 fa76e26bc7f450ddcc3701e821e80a22
BLAKE2b-256 936ea2db14be21fe756a03abbb1455c88b6980f5a0b40b75a1bf452bbb7f2a1d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pintrs-0.1.9-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 393.1 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.1.9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ff7f4f92fc02ae482eb3551dbb4ead37473966f9da659cdeb2fbd014e93df669
MD5 f46bae55397c2cdfe92e9058422c9a6d
BLAKE2b-256 0a8d50151e87bbb92693034f8da43680daa1b1c1b2f4a59c039acdd7012f85b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 90944c8d657c2fef49657835ddf637f1358ed82caf8e2ed9e409065d0904a448
MD5 29ff9cce2cca16442f844b72118af2fa
BLAKE2b-256 a49368fecb0f17ba484a3b32b6175d9b028e075d04c535940c2ffe4c01bd916d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4eb70d886d88882c91e637175b34ada7def3737c6c2b99ff6527aee1bfee08eb
MD5 4bc5639fe7821f7f3cd9f27fe5274262
BLAKE2b-256 8b591e2e0fd82b587604b4edac2bb94eb9fbcf7698c8f130545b5e972286ca89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.1.9-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c9a9353668154ab58528795fb662736ed4ac1bd1391bd859cdcac82eba39ffbd
MD5 6d2779ce2a2387457569be0e92c25080
BLAKE2b-256 a5dbc76e709065fc29d4a159eae066b67e5f3befee15966eea1513f9c177de3d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.1.9-cp313-cp313-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 514310b6f1c9c55e7316ea70c924ce30fabb92e34cfe21aaa40255354ea8eaa6
MD5 4f02576568489c6f56a9b9c5c447a74c
BLAKE2b-256 d9c64789f0ee687efec0d4668be57428039f0c3864e8d27179e3cf0b10e2c84c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pintrs-0.1.9-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 393.8 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.1.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b80f3afb44a8cdbf1838b15fd0c94a82e5b54e75ef2aad1eb8e5ae8c52f64050
MD5 bd70d9bda4b1cf6b7f497e71fbc6eec5
BLAKE2b-256 92aefe9b8f7d59ea5c9c26bdb184299e55afd3c21cd3c17641e91823b09f4285

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7efc119d69ae10999fd88cd85b6873ca5f2f5854e7580d5c61d05b8c421a0538
MD5 e9e8e2035bcc9c798774c756c1e65d1d
BLAKE2b-256 edd5f12c44c28ca4a3d3a69c2a6b28ac6b63a02ecbc42dca21b4da1b68ee743d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.1.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 876d7b8f490d0bc77af37a7a2095e66861e89678b3b9ceb72cb8fc51f3bd2d4f
MD5 947a1462dd3b7201429f63366018445d
BLAKE2b-256 692de7d3caa29b5bd006c69421d0c299f4fff95aa13a35758e15c57d78dd5c64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.1.9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0863552bf54d0a2e469cc9daa2410a9725fbbe6aff8b3945c8df7f0e6053876f
MD5 799b437be0a6e7bc27c02fe3c8575af3
BLAKE2b-256 51881e3f706cb2abd7a47c7175bae27d7a014a7883481187038cd16c9bc7d130

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pintrs-0.1.9-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c0c1db7353dcda8163325e5532b4bed1e70d73cbb0c62498bc54c78659e416bd
MD5 1cc960efdd9bb124c412021d156607b9
BLAKE2b-256 de41f3c80348be12fcf5c4928369a996b0b7971e8549de607e1690529c454cb5

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