affine transformations with units support
Project description
kanne
kanne
Kanne is a small utility package to help manage unit-aware quantities and a simple registry/context pattern for parsing and validating units using Pint. It provides convenience helpers, validators, and a minimal context manager (Kanne) to make working with Pint registries explicit and testable.
Key ideas:
- Keep unit parsing and validation ergonomic.
- Provide a lightweight context aware registry (
Kanne) for libraries. - Export commonly-used units and small helpers for convenience.
📦 Installation
uv add kanne
⚡ Quick Start
Kanne provides a context manager to manage Pint registries easily.
# Global Pattern
from kanne import Kanne, Millisecond, Millimeter, define_unit
from pydantic import BaseModel
class Event(BaseModel):
duration: Millisecond
class OtherEvent(BaseModel):
length: Millimeter
Event(duration="1500 ms") # works fine
OtherEvent(length="1500 mm") # raises a validation error
event = Event(duration="1500 ms") # works fine
other = OtherEvent(length="1500 mm") # raises a validation error
event.duration + other.length # raises an error since they are not compatible
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kanne-2.1.0.tar.gz.
File metadata
- Download URL: kanne-2.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f67d3730a65e98414aa0717333dd783182d9949612f98daf8cb64e7e3db75232
|
|
| MD5 |
cf0d5407a1c4c954cf534c9e313047fd
|
|
| BLAKE2b-256 |
ccaef4360839e16c6edd86c6f6fea97ad4ff9eeb11fd198003b6bc4901cd9261
|
File details
Details for the file kanne-2.1.0-py3-none-any.whl.
File metadata
- Download URL: kanne-2.1.0-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17da417f10d7d0bf118ea8d4a89040084e9f6c67c31bf1a611730d8d432c7424
|
|
| MD5 |
4b45b51ad2b03e50cff08639e764844d
|
|
| BLAKE2b-256 |
e1b011d1243bf0242e4386fb7153a1ca802d2396d31a56237dd129bc0d9c2d17
|