Skip to main content

a context-aware si-unit registry manager built on pint and pydantic

Project description

kanne

codecov PyPI version Maintainer PyPI pyversions PyPI status PyPI download day

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kanne-1.0.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kanne-1.0.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file kanne-1.0.0.tar.gz.

File metadata

  • Download URL: kanne-1.0.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.20 {"installer":{"name":"uv","version":"0.11.20","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}

File hashes

Hashes for kanne-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4fa4a0154a4db6ec1eba90a5b11a9d181d9f38ef50e3ef7c01b8f7dc8d5f8986
MD5 30df135f67384c0ad176aa12c4207e86
BLAKE2b-256 08d31f68afabc565fc3b09b9bacd3a43d02e411f27c4ac9ce173676f2ea7e354

See more details on using hashes here.

File details

Details for the file kanne-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: kanne-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.20 {"installer":{"name":"uv","version":"0.11.20","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}

File hashes

Hashes for kanne-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48a0662a1018966ef430f08f5a727a2e7bab8e2f53771fdb685967e8a9d2c2cf
MD5 984e6d4be92993c4d754cd166996d1f5
BLAKE2b-256 cf7b5b2de6c3e75ba34c984db13ff9baf6e468e1a5c19f16b5f18e3cc33caafa

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