Skip to content

Getting Started

Jasper Quillweld edited this page Oct 20, 2026 · 1 revision

Getting Started

Install the library:

pip install sysml2py

Your first model

A PackageBuilder is the top-level container. Add Parts, and give each part children with add():

from sysml2py import PackageBuilder, Part, Attribute

pkg = PackageBuilder('MyModel')
stage = Part('Stage_1')
stage.add(Attribute('mass'))
stage.add(Attribute('thrust'))
pkg.add(stage)
print(pkg.dump())
package MyModel
{
   part Stage_1
   {
      attribute mass;
      attribute thrust;
   }
}

What just happened

  • PackageBuilder('MyModel') started a package container.
  • Part('Stage_1') made a part usage.
  • stage.add(Attribute('mass')) nested two attributes under the part.
  • pkg.add(stage) put the part inside the package.
  • pkg.dump() printed the whole thing as valid SysML v2 text.

Because these are builders, you can print any one of them directly:

>>> Part('Stage_1').dump()
'part Stage_1;'

Usage vs. definition

A bare Part('Stage_1') is a usage in SysML terms. Ask for a definition with kind=:

>>> Part('Stage_1', kind='definition').dump()
'part def Stage_1;'

Some kinds have no definition form — the generator refuses rather than emit something it can't cast back (see The Builder API).

Next

Clone this wiki locally