Skip to main content

Generic SysML v2 API helpers from MBSE4U

Project description

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.

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

mbse4u_sysmlv2_helpers-0.1.5.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

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

mbse4u_sysmlv2_helpers-0.1.5-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file mbse4u_sysmlv2_helpers-0.1.5.tar.gz.

File metadata

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

File hashes

Hashes for mbse4u_sysmlv2_helpers-0.1.5.tar.gz
Algorithm Hash digest
SHA256 8e9f2ddbedd751c9fe334936fe5ec339c058f6088689acb03c0af2e70d4c5230
MD5 ad26a9263c47d93174f94380ece500a5
BLAKE2b-256 5123901b8e080d605af7ca301d5cf172ff29d4e1b648b14f537022950659ad10

See more details on using hashes here.

Provenance

The following attestation bundles were made for mbse4u_sysmlv2_helpers-0.1.5.tar.gz:

Publisher: python-publish.yml on MBSE4U/mbse4u_sysmlv2_helpers

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

File details

Details for the file mbse4u_sysmlv2_helpers-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for mbse4u_sysmlv2_helpers-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6468210f4955751aa217fc55dd43c9a7735639a23a981ee06fda59fa4e099735
MD5 2cba6ca9e6b2c40fa5a55476e14e43cf
BLAKE2b-256 59a9a0a72b28b1b9725f637e10bd30aa98716f1b201397150b32941f06045ed4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mbse4u_sysmlv2_helpers-0.1.5-py3-none-any.whl:

Publisher: python-publish.yml on MBSE4U/mbse4u_sysmlv2_helpers

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