Skip to main content

MBSE4U SysML v2 API Helpers

Generic helper functions for interacting with SysML v2 REST API. This library simplifies the process of querying projects, commits, and traversing the SysML v2 model structure.

Installation

You can install this package via pip.

pip install mbse4u-sysmlv2-helpers

Getting Started

Here is a simple example of how to connect to a server and list projects.

import mbse4u_sysmlv2_helpers as api

SERVER_URL = "http://localhost:9000"

try:
    # Fetch all projects
    projects = api.get_projects(SERVER_URL)
    print(f"Found {len(projects)} projects.")

    for p in projects:
        print(f"- {p.get('name')} (ID: {p.get('@id')})")
        
        # Get commits for the first project
        commits = api.get_commits(SERVER_URL, p['@id'])
        if commits:
            latest_commit = commits[-1]
            print(f"  Latest commit: {latest_commit.get('id')}")

except Exception as e:
    print(f"Error: {e}")

API Reference

Project & Commit Management

  • get_projects(server_url: str, page_size: int = 256) -> List[Dict]

    • Fetches and sorts projects alphabetically from the given server.
  • get_commits(server_url: str, project_id: str) -> List[Dict]

    • Retrieves commit history for a specific project, sorted by creation date.
  • get_commit_url(server_url: str, project_id: str, commit_id: str) -> str

    • Helper to construct the base URL for commit-specific queries.

Caching

  • load_model_cache(server_url: str, project_id: str, commit_id: str, page_size: int = 256) -> int
    • Loads all elements of a commit into an in-memory ELEMENT_CACHE to speed up subsequent queries. Returns the number of elements cached.

Element Retrieval

  • get_element_fromAPI(query_url: str, element_id: str) -> Optional[Dict]

    • Fetches a single element by ID, checking the local cache first.
  • get_elements_fromAPI(query_url: str, element_ids: List[str]) -> List[Dict]

    • Batch retrieval of elements by a list of IDs.
  • get_elements_byDeclaredName_fromAPI(server_url: str, project_id: str, commit_id: str, name: str) -> List[Dict]

    • Fetches elements by their declaredName. Includes logic to find elements that redefine a named element via Redefinition relationships.
  • get_elements_byKind_fromAPI(server_url: str, project_id: str, commit_id: str, kind: str) -> List[Dict]

    • Query for all elements of a specific type (e.g., 'PartUsage', 'MetadataDefinition').
  • get_elements_byProperty_fromAPI(server_url: str, project_id: str, commit_id: str, property: str, value: str) -> List[Dict]

    • Fetches elements matching a given property/value pair. Also resolves Redefinition relationships.

Traversal & Structure

  • get_contained_elements(server_url, project_id, commit_id, element_id, kind, elementKind='ownedElement') -> List[Dict]

    • Returns children of a specific type within an element's owned collection.
  • get_recursive_owned_elements(server_url, project_id, commit_id, start_element_id, kind, max_depth=5, current_depth=0) -> List[Dict]

    • Recursively fetches descendants of a specific kind down to a maximum depth.
  • get_owned_usages(server_url, project_id, commit_id, owner, feature_name) -> List[Dict]

    • Fetches owned usages for an element from both the Usage itself and its Definition.
  • check_specialization_hierarchy(query_url, element, super_element, visited=None) -> bool

    • Recursively checks if an element specializes the given super_element. Uses a visited set to prevent infinite loops.
  • find_element_by_id(aggregated_results: List[Dict], target_id: str) -> Optional[Dict]

    • Searches a list of elements for one matching a specific ID.
  • find_elements_specializing(server_url, project_id, commit_id, elements, super_element_name, element_kind=None) -> List[Dict]

    • Filters a list to only include elements that specialize a given supertype (by qualified name).

Feature & Attribute Access

  • get_feature(server_url, project_id, commit_id, owner, feature_name, feature_kind='AttributeUsage') -> Optional[Dict]

    • Retrieves a specific feature element (by name and kind) from an owner element, including inherited features.
  • get_feature_value(server_url, project_id, commit_id, owner, feature_name, feature_kind='AttributeUsage') -> Union[str, int, float, None]

    • Extracts the resolved value of a feature (attribute) from an element.
  • get_attribute_value_from_usage(query_url: str, attr_usage: Dict) -> Union[str, int, float, None]

    • Low-level helper to extract and resolve a value from an AttributeUsage element, including literal values, enum references, and FeatureChainExpression.
  • getValueFromOperatorExpressionUnit(query_url: str, opExp: Dict) -> Optional[Dict]

    • Helper to extract the value element from an OperatorExpression (e.g., for unit quantities).

Metadata

  • get_metadata_ids_by_name(server_url, project_id, commit_id, metadata_shortnames: List[str]) -> Dict[str, str]

    • Fetches the IDs of MetadataDefinition elements by their short names. Returns a mapping of short name → ID.
  • get_metadatausage_annotatedElement_ids(server_url, project_id, commit_id, metadefinition_dict: Dict[str, str]) -> Dict[str, List[str]]

    • Retrieves the IDs of elements annotated with specific metadata definitions. Returns a mapping of metadata key → list of annotated element IDs.

Element Relationships & Documentation

  • get_element_definition(server_url, project_id, commit_id, element: Dict) -> Optional[Dict]

    • Retrieves the Definition element for a given usage element.
  • get_element_documentation(server_url, project_id, commit_id, element_id: str) -> Optional[List[str]]

    • Retrieves the documentation body texts for a given element.

Model Update

  • update_model_element(server_url, project_id, commit_id, element_id, feature_name, feature_value) -> str
    • Creates a new commit that updates a single feature value on a model element. Returns the new commit ID.

License

Copyright 2026 MBSE4U - Tim Weilkiens. Licensed under the Apache License, Version 2.0.

Metadata

Release files for mbse4u-sysmlv2-helpers 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mbse4u-sysmlv2-helpers 0.1.5
File Size Uploaded Provenance Actions
mbse4u_sysmlv2_helpers-0.1.5.tar.gz 18.5 kB With provenance Details for mbse4u_sysmlv2_helpers-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mbse4u-sysmlv2-helpers 0.1.5
File Interpreter ABI Platform Actions
mbse4u_sysmlv2_helpers-0.1.5-py3-none-any.whl Python 3 none any Details for mbse4u_sysmlv2_helpers-0.1.5-py3-none-any.whl

Total release size: 37.1 kB

Release files / mbse4u_sysmlv2_helpers-0.1.5.tar.gz

Download URL mbse4u_sysmlv2_helpers-0.1.5.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8e9f2ddbedd751c9fe334936fe5ec339c058f6088689acb03c0af2e70d4c5230
BLAKE2b-256 checksum
How to use checksums
5123901b8e080d605af7ca301d5cf172ff29d4e1b648b14f537022950659ad10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.

Transparency log

Release files / mbse4u_sysmlv2_helpers-0.1.5-py3-none-any.whl

Download URL mbse4u_sysmlv2_helpers-0.1.5-py3-none-any.whl
Size 18.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6468210f4955751aa217fc55dd43c9a7735639a23a981ee06fda59fa4e099735
BLAKE2b-256 checksum
How to use checksums
59a9a0a72b28b1b9725f637e10bd30aa98716f1b201397150b32941f06045ed4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.

Transparency log

Security for mbse4u-sysmlv2-helpers 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mbse4u_sysmlv2_helpers-0.1.5.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page