Skip to main content

Elegant engineering math substrate for executable MBSE.

Project description

UnitFlow

Elegant engineering math for Python.

Unit algebra. Dimensional reasoning. Symbolic constraints. Array workflows. Built for engineers who refuse to compromise on correctness or beauty.

Python 3.13+ Ruff mypy License: Apache 2.0

Installation

pip install unitflow

For NumPy support:

pip install unitflow[numpy]

The core library has zero dependencies. NumPy is optional.

Quick Start

from unitflow import m, cm, kg, s, N, kW, MW, rpm, rad, si

# Intuitive arithmetic
force = 2 * kg * 9.81 * (m / s**2)
print(force.to(N))              # 19.62 N

# Exact conversions across orders of magnitude
power = 5000 * si.W
print(power.to(kW))             # 5 kW
print(power.to(MW))             # 0.005 MW

# Angular speed with exact pi-bearing scale factors
angular = (3000 * rpm).to(rad / s)
print(angular)                  # 314.159... rad/s

# Semantic equality: same physics, same object
assert 1 * m == 100 * cm
assert hash(1 * m) == hash(100 * cm)

Features

  • Clean Unit Algebra -- Immutable, composable units with automatic dimension tracking.
  • Exact Scale Representation -- Rational arithmetic with explicit pi support. No floating-point drift.
  • SI Prefix System -- Every standard prefix from pico to tera, generated programmatically.
  • Torque vs Energy Disambiguation -- Same dimension, different meaning. UnitFlow knows the difference.
  • Symbolic Constraints -- Define equations and inequalities as first-class Python objects for MBSE.
  • NumPy Integration -- Array-backed quantities via __array_ufunc__ and __array_function__.
  • JSON-Safe Serialization -- Quantities and constraint trees serialize to plain dicts.
  • Explicit Errors -- Dimension mismatches and incompatible conversions fail loudly. No silent corruption.

Symbolic Constraints

from unitflow import symbol, N, kg, m, s, W, rpm, rad

F = symbol("F", unit=N)
mass = symbol("m", unit=kg)
a = symbol("a", unit=m / s**2)

newtons_law = F == mass * a          # Returns an Equation, not a bool

x = symbol("x", unit=m)
bounds = (0 * m <= x) & (x <= 10 * m)  # Conjunction of constraints

User-Defined Units

from unitflow import define_unit, UnitNamespace, Quantity, m, s, generate_prefixes
from fractions import Fraction

ft = define_unit(name="foot", symbol="ft", expr=Quantity(Fraction(3048, 10000), m))
print((6 * ft).to(m))  # 1.8288 m

aero = UnitNamespace("aero")
knot = aero.define_unit(name="knot", symbol="kn", expr=Quantity(Fraction(1852, 3600), m / s))
generate_prefixes(aero, knot, include={"milli", "kilo"})

Part of ThunderGraph

UnitFlow is the foundational math layer for ThunderGraph, an AI-powered model-based systems engineering platform.

Links

License

Apache 2.0

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

unitflow-0.2.0.tar.gz (1.9 MB view details)

Uploaded Source

Built Distribution

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

unitflow-0.2.0-py3-none-any.whl (36.8 kB view details)

Uploaded Python 3

File details

Details for the file unitflow-0.2.0.tar.gz.

File metadata

  • Download URL: unitflow-0.2.0.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.3

File hashes

Hashes for unitflow-0.2.0.tar.gz
Algorithm Hash digest
SHA256 33731a7d9e6727343a1c5a05d4cddf7ba92d2bbddee8c03d172d68cc4c3ac2a3
MD5 24557c0509bb3cfe26d01a9968ebfe26
BLAKE2b-256 d25b628b1f53c9c8633f47673552cd696788eecf2323b49a91147bab4133ccb3

See more details on using hashes here.

File details

Details for the file unitflow-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: unitflow-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 36.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.3

File hashes

Hashes for unitflow-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0600f2abfaefc42b4391c4a3d22525ecc6bbef1f537a24e2088692292e6e45a9
MD5 17d9fbf7a7203efaec90146473b0cb81
BLAKE2b-256 53be5ed87d0895683b7d2084cbd03003dd3fdc8fd4ba3c6075dc4a6e7092d9ac

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