Skip to main content

Pintext

Extend Pint with unit contexts

PyPI version Documentation Status uv Ruff

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.0

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.0
File Size Uploaded
pintext-0.1.0.tar.gz 178.9 kB Details

Built distribution (wheel)

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

Total release size: 198.4 kB

Release files / pintext-0.1.0.tar.gz

Download URL pintext-0.1.0.tar.gz
Size 178.9 kB
Tags Source
SHA-256 checksum
How to use checksums
514c1e83295be209e77b640f7910691aed6401f2e56c956f75ed3acab5bf967e
BLAKE2b-256 checksum
How to use checksums
7e4d3a20e3e511efe6b6db38f35f2ecb3c76a6fa4e85c15268e165e69b7ca2a7
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.0-py3-none-any.whl

Download URL pintext-0.1.0-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
10366056b946f4d4b2f8c36ef5e2fa3d6ce822d18f7951a6ef9f5ce83ab2df96
BLAKE2b-256 checksum
How to use checksums
0d54501ac5d56f574d082d10b33fc1293a91df6783edbd380c9d38dca4757f5d
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

0.1.1

2 release files

This release

0.1.0 This release

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