Repository navigation
Units
Value-bearing attributes are first-class in sysml2py. Pass a value and a
unit and the library renders the SysML [unit] syntax, importing the unit
automatically.
from sysml2py import Attribute
Attribute('mass', value=1000, unit='kg').dump()
'attribute mass = 1000[kg];'When the attribute lives in a container, the unit is imported as a
public import (SysML v2 / KERML-74 requires an explicit visibility
modifier — bare import is not valid):
pkg = PackageBuilder('Rocket')
stage = Part('Stage_1')
stage.add(Attribute('mass', value=1000, unit='kg'))
pkg.add(stage)
print(pkg.dump())package Rocket
{
public import SI::kg;
part Stage_1
{
attribute mass = 1000[kg];
}
}
If you prefer, pass a pint or astropy Quantity and the unit is
derived from it — either works as a drop-in convenience:
# pint
import pint
ureg = pint.UnitRegistry()
Attribute('mass', value=1000 * ureg.kg) # attribute mass = 1000[kg];
# astropy (the original Quantity integration, still supported)
import astropy.units as u
Attribute('mass', value=1000 * u.kg) # attribute mass = 1000[kg];Both render composite units faithfully, e.g.
9.8 * ureg.m / ureg.s**2 → attribute accel = 9.8[m/s**2];, and both
import the unit as a public import in the right namespace (SI base units
→ SI::, imperial → USCustomaryUnits::).
The sysml2py runtime itself is pure standard library — pint/astropy are
not bundled. If you use a Quantity form, add the import and a
pint/astropy dependency to your own project.
Systems like m/s**2 and / denominators are supported by the generator's
unit handling (see the sysml2py-lab corpus tests and the units spec).