API reference
Model and elements
A set of elements with identity, ownership, and lookup.
Source code in src/sysml2kit/model/container.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
add(element, owner=None)
Register an element, optionally under an owner already in the model.
Source code in src/sysml2kit/model/container.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
assign_stable_ids()
Rewrite every element id as a UUIDv5 hash of its qualified name.
Returns the old-to-new id mapping. Refs, ownership maps, and roots are remapped in place. Run this before committing generated interchange files so regeneration produces stable diffs.
Source code in src/sysml2kit/model/container.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
check_refs()
Return (element_id, field_name, missing_target) for dangling refs.
Source code in src/sysml2kit/model/container.py
167 168 169 170 171 172 173 174 | |
find(*, name=None, kind=None)
Return elements matching a declared name and/or a class.
Source code in src/sysml2kit/model/container.py
108 109 110 111 112 113 114 115 116 117 118 119 120 | |
find_by_qualified_name(qualified)
Return the element with this exact qualified name, if any.
Source code in src/sysml2kit/model/container.py
122 123 124 125 126 127 | |
iter_elements(*, kind=None)
Iterate elements in ownership (depth-first) order.
Source code in src/sysml2kit/model/container.py
129 130 131 132 133 134 | |
owned_by(element)
Return the owned elements, in insertion order.
Source code in src/sysml2kit/model/container.py
73 74 75 76 | |
owner_of(element)
Return the owning element, or None for a root.
Source code in src/sysml2kit/model/container.py
67 68 69 70 71 | |
qualified_name(element)
Return the ::-joined name path from the root to this element.
Unnamed elements contribute their kind and a positional index, so the path is always defined (and usable for stable-id hashing).
Source code in src/sysml2kit/model/container.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
relationships(*, kind=None, source=None, target=None)
Return relationships filtered by class and/or endpoint.
Source code in src/sysml2kit/model/container.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
remove(element)
Remove an element and reparent nothing: its owned elements become roots.
Source code in src/sysml2kit/model/container.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
resolve(ref)
Return the element a ref (or id) points at.
Source code in src/sysml2kit/model/container.py
62 63 64 65 | |
Base element classes and the cross-reference type.
Every cross-reference between elements is a :class:Ref (a UUID wrapper),
never a direct Python object reference, so any element serializes on its own
and maps 1:1 onto the Systems Modeling API JSON {"@id": ...} form.
Ownership is not stored on elements either; the Model container keeps it.
Element
Bases: BaseModel
Common base for every model element in the pragmatic profile.
Source code in src/sysml2kit/model/base.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
label
property
A human-readable identifier: name, short name, or the id.
OpaqueElement
Bases: Element
An element outside the pragmatic profile, preserved verbatim.
raw holds the original JSON interchange record; it re-exports
unchanged, so reading and writing a model does not drop content the
profile has no class for.
Source code in src/sysml2kit/model/base.py
64 65 66 67 68 69 70 71 72 73 | |
Ref
Bases: BaseModel
Reference to another element by id.
Source code in src/sysml2kit/model/base.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
resolve(model)
Return the referenced element, raising KeyError if absent.
Source code in src/sysml2kit/model/base.py
36 37 38 | |
to(element)
classmethod
Build a Ref from an element, a UUID, or another Ref.
Source code in src/sysml2kit/model/base.py
27 28 29 30 31 32 33 34 | |
Relationship
Bases: Element
Common base for reified relationships with a source and a target.
Source code in src/sysml2kit/model/base.py
57 58 59 60 61 | |
Builder
Fluent authoring helpers: the API humans and agents actually type.
Each helper constructs an element, registers it in the model under the given owner, and returns it. The raw element classes stay the interchange-faithful layer; nothing here adds state the classes lack.
allocate(model, *, source, target, owner=None)
Record that source is allocated to target (a part).
Source code in src/sysml2kit/model/builder.py
263 264 265 266 267 | |
analysis(model, name, *, owner=None, subject=None, objective=None, definition=None)
Create an analysis case usage.
Source code in src/sysml2kit/model/builder.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
analysis_def(model, name, *, owner=None, doc=None)
Create an analysis case definition.
Source code in src/sysml2kit/model/builder.py
163 164 165 166 167 | |
attr(model, name, value=None, *, owner=None, unit=None, definition=None, source=None)
Create an attribute usage holding a value with optional unit and provenance.
Source code in src/sysml2kit/model/builder.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
attr_def(model, name, *, owner=None, unit=None, doc=None)
Create an attribute definition, optionally with a default unit.
Source code in src/sysml2kit/model/builder.py
102 103 104 105 106 107 108 109 110 111 112 113 | |
connect(model, source, target, *, owner=None, name=None)
Create a connection between two ports (or parts).
Source code in src/sysml2kit/model/builder.py
89 90 91 92 93 94 95 96 97 98 99 | |
derive(model, *, source, target, owner=None)
Record that requirement source derives from requirement target.
Source code in src/sysml2kit/model/builder.py
256 257 258 259 260 | |
metadata(model, annotated, values, *, owner=None, name=None, definition=None)
Attach a key-value metadata annotation to an element.
Default ownership is the annotated element's owner (package level): the
about reference carries the attachment, and package-level placement
is what survives the textual notation (metadata inside definition bodies
is dropped by the parser). Passing definition types the usage by a
metadata def, which lets sibling annotations carry distinct names
(a fidelity ladder) while sharing one annotation kind.
Source code in src/sysml2kit/model/builder.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
metadata_def(model, name, *, owner=None, doc=None)
Add a reusable metadata annotation kind (metadata def).
Source code in src/sysml2kit/model/builder.py
217 218 219 220 221 222 223 224 225 226 227 | |
part(model, name, *, owner=None, definition=None, multiplicity=None, doc=None)
Create a part usage, optionally typed by a part definition.
Source code in src/sysml2kit/model/builder.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
part_def(model, name, *, owner=None, doc=None)
Create a part definition.
Source code in src/sysml2kit/model/builder.py
41 42 43 44 45 | |
pkg(model, name, *, owner=None, doc=None)
Create a package.
Source code in src/sysml2kit/model/builder.py
34 35 36 37 38 | |
port(model, name, *, owner=None, definition=None)
Create a port usage on a part.
Source code in src/sysml2kit/model/builder.py
74 75 76 77 78 79 80 81 82 83 84 85 86 | |
port_def(model, name, *, owner=None, doc=None)
Create a port definition.
Source code in src/sysml2kit/model/builder.py
67 68 69 70 71 | |
req(model, short_name, name, *, owner=None, text=None, subject=None, definition=None)
Create a requirement usage; short_name is the requirement id (e.g. REQ-001).
Source code in src/sysml2kit/model/builder.py
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
req_def(model, name, *, owner=None, doc=None)
Create a requirement definition.
Source code in src/sysml2kit/model/builder.py
135 136 137 138 139 | |
satisfy(model, *, source, target, owner=None)
Record that source (a design element) satisfies target (a requirement).
Source code in src/sysml2kit/model/builder.py
242 243 244 245 246 | |
verify(model, *, source, target, owner=None)
Record that source (an analysis/test) verifies target (a requirement).
Source code in src/sysml2kit/model/builder.py
249 250 251 252 253 | |
Queries
Traceability queries over a Model.
These answer the questions a requirements-driven workflow actually asks: which requirements are unsatisfied or unverified, what is allocated where, and how do requirements trace to parts.
TraceMatrix
dataclass
Requirement-by-part grid of satisfy/verify/allocate marks.
Source code in src/sysml2kit/query.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
render()
Render as a fixed-width text table.
Source code in src/sysml2kit/query.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
allocation_table(model)
Return (allocated element, part) pairs for every allocate relationship.
Source code in src/sysml2kit/query.py
80 81 82 83 84 85 | |
derived_from(model, requirement)
Return the requirements this one derives from.
Source code in src/sysml2kit/query.py
64 65 66 67 | |
parts_of(model, scope=None)
Return part usages, optionally only those under a scope element.
Source code in src/sysml2kit/query.py
38 39 40 41 42 43 44 45 46 47 48 49 | |
requirements_in(model, scope=None)
Return requirement usages, optionally only those under a scope element.
Source code in src/sysml2kit/query.py
24 25 26 27 28 29 30 31 32 33 34 35 | |
satisfied_by(model, requirement)
Return the elements recorded as satisfying this requirement.
Source code in src/sysml2kit/query.py
52 53 54 55 | |
trace_matrix(model)
Build the requirement-to-part traceability matrix.
Source code in src/sysml2kit/query.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
unsatisfied_requirements(model)
Return requirements with no incoming satisfy relationship.
Source code in src/sysml2kit/query.py
70 71 72 | |
unverified_requirements(model)
Return requirements with no incoming verify relationship.
Source code in src/sysml2kit/query.py
75 76 77 | |
verified_by(model, requirement)
Return the analyses/tests recorded as verifying this requirement.
Source code in src/sysml2kit/query.py
58 59 60 61 | |
Validation
Rule-based model validation.
Rules are registered in a module-level table and identified as S2K0NN.
validate(model) runs them all and returns issues sorted by severity.
ValidationIssue
dataclass
One finding from one rule against one element.
Source code in src/sysml2kit/validation.py
32 33 34 35 36 37 38 39 | |
dangling_refs(model)
error: a reference points at an element that is not in the model.
Source code in src/sysml2kit/validation.py
62 63 64 65 66 67 68 | |
duplicate_short_names(model)
error: two requirements share a declared short name (requirement id).
Source code in src/sysml2kit/validation.py
71 72 73 74 75 76 77 78 79 80 81 82 83 | |
empty_package(model)
info: a package owns nothing.
Source code in src/sysml2kit/validation.py
172 173 174 175 176 177 | |
fidelity_ladder_shape(model)
error: two bindings on one analysis share a fidelity label; warning: mixed labeling.
Source code in src/sysml2kit/validation.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
opaque_share(model)
info: opaque elements are present (fine, but worth knowing).
Source code in src/sysml2kit/validation.py
180 181 182 183 184 185 186 187 | |
relationship_endpoint_kinds(model)
error: a traceability relationship points at the wrong element kind.
Source code in src/sysml2kit/validation.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
requirement_without_subject(model)
warning: a requirement names no subject and nothing satisfies it.
Source code in src/sysml2kit/validation.py
157 158 159 160 161 162 163 164 165 166 167 168 169 | |
rule(rule_id)
Register a validation rule under an S2K id.
Source code in src/sysml2kit/validation.py
46 47 48 49 50 51 52 53 | |
sibling_name_clash(model)
error: two named siblings clash, which also breaks stable-id hashing.
Source code in src/sysml2kit/validation.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
unparseable_units(model)
warning: an attribute value carries a unit string pint cannot parse.
Source code in src/sysml2kit/validation.py
143 144 145 146 147 148 149 150 151 152 153 154 | |
unresolvable_definition(model)
error: a usage's definition ref resolves to nothing.
A subset of S2K001 kept separate because typing errors deserve their own id.
Source code in src/sysml2kit/validation.py
129 130 131 132 133 134 135 136 137 138 139 140 | |
validate(model)
Run every rule; issues come back sorted errors-first.
Source code in src/sysml2kit/validation.py
56 57 58 59 | |
Diff
Element-level model diff.
Matching is by element_id by default; by_name=True falls back to
qualified names, for models whose parser regenerated the UUIDs. Semantic
(graph-aware) diffing is out of scope for v0.1.
DiffEntry
dataclass
One difference between two models.
Source code in src/sysml2kit/diff.py
20 21 22 23 24 25 26 | |
diff_models(a, b, *, by_name=False)
Compare two models; entries are sorted by qualified name within each kind.
Source code in src/sysml2kit/diff.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
render_diff(entries)
Render diff entries one per line, with +/-/~/> markers.
Source code in src/sysml2kit/diff.py
97 98 99 100 101 102 103 104 105 106 | |
Interop
Tool-agnostic requirement extraction: the metricKey convention.
A requirement usage that owns attributes named metricKey, threshold,
op (one of >= <= == > <), and optionally severity is machine-
checkable. extract_requirements turns each into a :class:RequirementSpec
with the threshold in both operator form (op + value) and bound form
(minimum/maximum), so downstream tools of either dialect consume it with a
small adapter: an op-form requirements engine maps op/value straight
through, a bound-form one takes minimum/maximum. Adapter code lives
in the consuming packages, not here.
RequirementSpec
Bases: BaseModel
One machine-checkable requirement, extracted from a model.
Source code in src/sysml2kit/interop/requirements.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | |
extract_requirements(model)
Extract every requirement that follows the metricKey convention.
Source code in src/sysml2kit/interop/requirements.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
Units
Unit-string helpers backed by pint.
Models store units as text (round-trip fidelity with the textual notation); these helpers check and convert them. A few decibel spellings common in engineering practice are registered on top of pint's defaults.
check_dimensionality(unit_a, unit_b)
Return whether two unit texts share a dimensionality.
Source code in src/sysml2kit/units.py
58 59 60 | |
convert(value, from_unit, to_unit)
Convert a value between two unit texts.
Source code in src/sysml2kit/units.py
52 53 54 55 | |
is_valid_unit(text)
Return whether pint can parse this unit text.
Source code in src/sysml2kit/units.py
43 44 45 46 47 48 49 | |
parse_unit(text)
Parse unit text into a pint unit; raises ValueError on unknown units.
Source code in src/sysml2kit/units.py
35 36 37 38 39 40 | |
registry()
cached
Return the shared pint unit registry (created on first use).
Source code in src/sysml2kit/units.py
26 27 28 29 30 31 32 | |