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.1.1.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.1.1-py3-none-any.whl (33.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: unitflow-0.1.1.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.1.1.tar.gz
Algorithm Hash digest
SHA256 53fc183cc1dd20b97cd0f4ef6d8aa8e845b7368d79f8a83816956b42800bdbf1
MD5 6047503b6167532de3833f31bcc4b1db
BLAKE2b-256 d9a597b32cb9b30c15ed298de432958dea80c2a790bba2fcdca01d6e90465f7e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for unitflow-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dcb780d038d038222ced68688a4205b6da30a52475842f831c035701ca1f6988
MD5 86e9e514b6fd61d14b461ef8e3daa54b
BLAKE2b-256 4a4e9ee35b471955691ce769b818b2c6efdff3fd9039e55492a3682c7124fe31

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