Skip to main content

Statically typed units

Project description

u

Statically typed units.

Quickstart

# Type safe assignments
duration: u.Duration = u.seconds(5)  # Ok
distance: u.Distance = u.amperes(5)  # Type checking error

# Type safe math
print(u.seconds(120) + u.minutes(3))  # Ok
print(u.seconds(120) + u.amperes(3))  # Type checking error

# Type safe compound units (with some caveats)
speed: u.Div[u.Distance, u.Duration] = u.km(5) / u.hours(1)  # Ok

# Reusable prefixes
print(u.bytes(1000) == u.mega(u.bytes)(1))

# Define your own Quantities and Units
class Tastiness(u.Quantity):
    pass

mmm = u.Unit[Tastiness](symbol='mmm', multiplier=1)
yum = u.Unit[Tastiness]('yum', 10)

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

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

Source Distribution

u-0.1.tar.gz (7.1 kB view hashes)

Uploaded Source

Built Distribution

u-0.1-py3-none-any.whl (11.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page