Skip to main content

A physical quantities and units package in Python.

Project description

Metronos

Metronos (from the Ancient Greek μέτρον /metron/, meaning "measure" or "that by which anything is measured.")

A lightweight Python library for physical quantities with units. No heavy dependencies, no mandatory annotations, no user-facing registries — just quantities that know what they are and refuse to let you mix them up.


Installation

pip install git+https://github.com/cgburnsi/Metronos.git

Or clone and install locally:

git clone https://github.com/cgburnsi/Metronos.git
cd Metronos
pip install -e .

Quick start

import metronos as mt

d = mt.Quantity(6.2, 'ft')
v = mt.Quantity(60, 'mile/s')
a = mt.Quantity(9.81, 'm/s^2')

Features

Unit conversion

mt.Quantity(6.2, 'ft').to('m')          # Quantity(1.88976 [m])
mt.Quantity(60, 'mile/s').to('km/s')    # Quantity(96.56064 [km/s])
mt.Quantity(9.81, 'm/s^2').to('ft/s^2') # Quantity(32.185 [ft/s^2])

Arithmetic

Units combine automatically. Mixed-unit arithmetic works as long as the dimensions are compatible.

mt.Quantity(100, 'm') + mt.Quantity(0.5, 'km')   # Quantity(600.0 [m])

mass = mt.Quantity(70, 'kg')
accel = mt.Quantity(9.81, 'm/s^2')
force = mass * accel                              # Quantity(686.7 [m*kg/s^2])

KE = 0.5 * mass * mt.Quantity(10, 'm/s') ** 2   # Quantity(3500.0 [m^2*kg/s^2])

Temperature

Offset units (°C, °F, °R) are fully supported.

mt.Quantity(100, 'degC').to('degF')   # Quantity(212.0 [degF])
mt.Quantity(32, 'degF').to('K')       # Quantity(273.15 [K])

Extracting values

speed = mt.Quantity(25, 'm/s')
speed.to('km/s').value    # 0.025  (float, in the requested unit)

ratio = mt.Quantity(3.0) / mt.Quantity(1.5)
float(ratio)              # 2.0  (dimensionless quantities only)

Dimension safety

Metronos raises a DimensionError if you try to add or compare incompatible quantities.

mt.Quantity(1, 'm') + mt.Quantity(1, 'kg')   # DimensionError
mt.Quantity(1, 'm').to('s')                  # DimensionError
mt.Quantity(1, 'm') < mt.Quantity(1, 'kg')   # DimensionError

Comparisons

mt.Quantity(100, 'm') == mt.Quantity(0.1, 'km')   # True
mt.Quantity(100, 'm') < mt.Quantity(1, 'mile')    # True

Supported units

SI base units

Symbol Quantity
m length
g mass (base unit is kg internally)
s time
A electric current
K temperature
mol amount of substance
cd luminous intensity

All SI base and derived units support the full prefix set (n, µ, m, k, M, G, etc.).

Derived SI units

Hz, N, Pa, J, W, C, V, Ω, S, F, T, Wb, H, lm, lx, Bq, Gy, Sv, kat, L

Customary US units

ft, in, inch, mile, yard, lb, lbf, psi, psia, gal, BTU, degF, degR

Other

bar, Torr, min, h, degC


Philosophy

  • Lean: No dependencies beyond the Python standard library.
  • Pythonic: Clean, simple API with no mandatory annotations or boilerplate.
  • Intuitive: It handles the dimensional math so you can focus on the physics.

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

metronos-0.1.1.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.

metronos-0.1.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file metronos-0.1.1.tar.gz.

File metadata

  • Download URL: metronos-0.1.1.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for metronos-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8d25b73fc2e80655f1ad49b193c27ae570f4b43a04a5c2f98ff12b68503f7319
MD5 7be960c5303737ba9db9262ad061c39c
BLAKE2b-256 166fe7fc210caac3ee265399f81db33d501457b57fc7db0092674a620d71d417

See more details on using hashes here.

File details

Details for the file metronos-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: metronos-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for metronos-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e176f93c025e1083a1af0293b58e15a37daa342daf6bc9f3d673d2faeacabfd1
MD5 c0a88e192650fba1d4f637e76dfe32f8
BLAKE2b-256 52bd2a156ee391d5f3f20d4e5300d475509cad606f9c99355a90a93e0093f26c

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