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

Uploaded Python 3

File details

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

File metadata

  • Download URL: unitflow-0.2.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.2.1.tar.gz
Algorithm Hash digest
SHA256 fd1570afd4db1187c0a0bf8f7daa836e9d6e204c7d9ba6bd4d9ccb8d185f7edd
MD5 958031235f16dc2e6c10dc5d3e3f0fc2
BLAKE2b-256 1eee286eac876ecd306096a94ba296fd1e666ee849d034dad8cf95e5c489887c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: unitflow-0.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eb8671f3198c2efa561f66ae3abb34b61aad0c7686118db5c568a87a78d748f9
MD5 4552a82f40d17579f4ed06535e66fc5d
BLAKE2b-256 263c61b5146065ad42ad9815e91f0c255b78a64110c13d889306e9222fca8420

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