Skip to main content

Pintext

Extend Pint with unit contexts

PyPI version Documentation Status

Motivation

Scientific applications routinely accept plain numbers, e.g. from configuration files, user input or serialized data. They then have to decide what units those numbers carry. Hard-coding the answer at each site is brittle; passing units around explicitly is noisy.

Pintext's answer is the unit context: a registry of named, overridable unit generators built on Pint. Units are resolved when a value is interpreted, not when the code declaring it was written, so a single with block can change how an entire object tree reads its inputs.

Features

  • Define unit contexts to vary unitless value interpretation dynamically
  • Attach units to unitless values and check unit compatibility with a check stricter than Pint's dimensionality (e.g. angles, radiance vs irradiance)
  • Interpret quantities stored as dictionaries or xarray DataArrays
  • Attach units to attrs fields
  • Attach units to pydantic fields

The core depends on Pint alone; the class-framework integrations are optional.

Installation

pip install pintext
pip install "pintext[attrs]"  # attrs integration
pip install "pintext[pydantic]"  # pydantic integration

Check the documentation for more detail.

Contributing

Please refer to the contributor's guide for the AI usage policy, development setup instructions and development practices.

License

Pintext is distributed under the terms of the MIT license.

About

Pintext is written and maintained by Vincent Leroy.

Development is supported by Rayference.

Pintext is a component of the Eradiate radiative transfer model.

Pintext was previously released as Pinttrs, which it supersedes. Pintext contains breaking changes, see the porting guide for details.

Metadata

Release files for pintext 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pintext 0.1.1
File Size Uploaded
pintext-0.1.1.tar.gz 178.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pintext 0.1.1
File Interpreter ABI Platform
pintext-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 198.3 kB

Release files / pintext-0.1.1.tar.gz

Download URL pintext-0.1.1.tar.gz
Size 178.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5a5bc1a3bf78b109bce8bdcd63799ff47ccd3a2aabab4be0024f8b17d246a606
BLAKE2b-256 checksum
How to use checksums
887de98ba3a20b61126bef8c1ad4797b923868146b45876513879b1463f85cac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pintext-0.1.1-py3-none-any.whl

Download URL pintext-0.1.1-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43b15e842f909c00bb992d5e359a81c4b0618ce9813fefe5f8dfcf8c9ad37def
BLAKE2b-256 checksum
How to use checksums
5e71c4c01cfacfd9e451a3c4db8aae9ae276a6681dce956acdb8c52cd8233162
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.6 {"installer":{"name":"uv","version":"0.12.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page