Skip to main content

SysML v2.0 Parser

Project description

sysmlpy

PyPI versionPyPI statusMIT license

Description

sysmlpy is an open source pure Python library for constructing python-based classes consistent with the SysML v2.0 standard.

This project began as a fork of the sysml2py project by Christopher Cox. Since April 2026 Jon Fox decided to complete coverage of all SysMLv2 features over two months of weekends, and dropped the textX parser in favor of an ANTLR4 parser grammar and changed our unit library to pint. The project had diverged so much from sysml2py that a new name, sysmlpy, was selected.

Lines of Code Over Time

v0.12.0: 100% conformance test pass rate (123/123). Storage abstraction layer with in-memory and NetworkX graph backends. Convenience functions: find_all, count, traverse, to_dict, to_graph, path_between.

Requirements

sysmlpy requires the following Python packages:

Optional Dependencies

  • networkx — graph analysis backend (install with pip install sysmlpy[graph])

Installation

Multiple installation methods are supported by sysmlpy, including:

Logo Platform Command
PyPI logo PyPI python -m pip install sysmlpy
PyPI logo PyPI python -m pip install sysmlpy[graph] (with graph analysis)
GitHub logo GitHub python -m pip install https://github.com/mycr0ft/sysmlpy/archive/refs/heads/main.zip

Documentation

Documentation can be found here.

Basic Usage

The code below will create a part called Stage 1, with a shortname of <'3.1'> referencing a specific requirement or document. It has a mass attribute of 100 kg. It has a thrust attribute of 1000 N. These attributes are created and placed as a child of the part. Next, we recall the part value for thrust and add 199 N. Finally, we can dump the output from this class.

  from sysmlpy import Attribute, Part, ureg

  a = Attribute(name='mass')
  a.set_value(100 * ureg.kilogram)
  b = Attribute(name='thrust')
  b.set_value(1000 * ureg.newton)
  c = Part(name="Stage_1", shortname="'3.1'")
  c._set_child(a)
  c._set_child(b)
  v = "Stage_1.thrust"
  c._get_child(v).set_value(c._get_child(v).get_value() + 199 * ureg.newton)
  print(c.dump())

It will output the following:

  part <'3.1'> Stage_1 {
    attribute mass= 100 [kilogram];
    attribute thrust= 1199.0 [newton];
  }

The package is able to handle Items, Parts, and Attributes.

a = Part(name='camera')
b = Item(name='lens')
d = Attribute(name='mass')
c = Part(name='sensor')
c._set_child(a)
c._set_child(b)
a._set_child(d)
print(c.dump())

will return:

part sensor {
   part camera {
      attribute mass;
   }
   item lens;
}

Actions

Actions (activities) can be defined with input and output parameters::

from sysmlpy import Action

# Action definition with typed inputs/outputs
a = Action(definition=True, name='Focus')
a.add_input('scene', 'Scene')
a.add_output('image', 'Image')
print(a.dump())
# → action def Focus { in scene : Scene; out image : Image; }

# Action usage with references
b = Action(name='TakePicture')
b.add_input('scene')
b.add_output('picture')
print(b.dump())
# → action TakePicture { in scene; out picture; }

References

References can reference other elements::

from sysmlpy import Reference, Item

# Simple reference
r = Reference(name='driver')
print(r.dump())
# → ref driver;

# Reference with type
person = Item(name='Person')
r2 = Reference(name='driver')
r2.set_type(person)
print(r2.dump())
# → ref driver : Person;

# Reference redefinition
r3 = Reference(name='payload', redefines=True)
r3.set_type(person)
print(r3.dump())
# → ref :>> payload : Person;

Grammar Round-Trip

loads() parses SysML v2 text and classtree() converts the result back to text. This round-trip is the basis for the grammar test suite.

from sysmlpy import loads
from sysmlpy.formatting import classtree

text = """package 'Action Example' {
    action def Focus { in scene : Scene; out image : Image; }
    action def Shoot { in image: Image; out picture : Picture; }

    action def TakePicture {
        in item scene : Scene;
        out item picture : Picture;

        bind focus.scene = scene;

        action focus : Focus { in scene; out image; }

        flow focus.image to shoot.image;

        first focus then shoot;

        action shoot : Shoot { in image; out picture; }

        bind shoot.picture = picture;
    }
}"""

model = loads(text)
tree = classtree(model)
print(tree.dump())

61% of the 56 grammar round-trip tests currently pass (34/56), covering packages, parts, items, ports, interfaces, binding connectors, flow connections, all action forms (definition, shorthand, succession, decomposition), expressions, calculations, and constraints.

Conformance

100% of 123 OMG XPect conformance tests pass (123/123).

License

sysmlpy is released under the MIT license, hence allowing commercial use of the library.

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

sysmlpy-0.12.2.tar.gz (837.8 kB view details)

Uploaded Source

Built Distribution

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

sysmlpy-0.12.2-py3-none-any.whl (903.9 kB view details)

Uploaded Python 3

File details

Details for the file sysmlpy-0.12.2.tar.gz.

File metadata

  • Download URL: sysmlpy-0.12.2.tar.gz
  • Upload date:
  • Size: 837.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sysmlpy-0.12.2.tar.gz
Algorithm Hash digest
SHA256 fc38bea377f65600840e45c889d19b56fed3bf76d4c76b41c14db39cb5c6d56e
MD5 a3518156ff11c72ef748332cfcb18abf
BLAKE2b-256 7f5e73ae7b0d2cc375e825f00b5a2c2971579525dc1e07c1a38de5ee56d4f1a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for sysmlpy-0.12.2.tar.gz:

Publisher: release.yml on mycr0ft/sysmlpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sysmlpy-0.12.2-py3-none-any.whl.

File metadata

  • Download URL: sysmlpy-0.12.2-py3-none-any.whl
  • Upload date:
  • Size: 903.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sysmlpy-0.12.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ebff2e86c85eee738306602d26579ce47e7f89af1d95c331ec1e64b9a4fdb017
MD5 f23db1b2e0fa3dfbd911abcc28bcc9f4
BLAKE2b-256 b4f99a40d27ff83fb6a512509df3f236a84a51d0122978707bba546a53adb163

See more details on using hashes here.

Provenance

The following attestation bundles were made for sysmlpy-0.12.2-py3-none-any.whl:

Publisher: release.yml on mycr0ft/sysmlpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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