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.

From Source

pip install .

Editable Mode (Development)

pip install -e .

Getting Started

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

import mbse4u_sysmlv2_api_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 from the given server.
  • get_commits(server_url: str, project_id: str) -> List[Dict]

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

    • Helper to constructing 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.
  • get_elements_byKind_fromAPI(server_url: str, project_id: str, commit_id: str, kind: str) -> List[Dict]

    • Cached query for all elements of a specific type (e.g., 'PartUsage').
  • get_elements_byName_fromAPI(server_url: str, project_id: str, commit_id: str, name: str) -> List[Dict]

    • Finds elements by declaredName. Includes logic to find elements that redefine a named element.

Traversal & Structure

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

    • Returns children of a specific type.
  • get_recursive_owned_elements(...) -> List[Dict]

    • Recursively fetches descendants.
  • check_specialization_hierarchy(query_url, element, super_element_name) -> bool

    • Checks if an element inherits from a specific named element (useful for checking compliance with patterns like systemOfInterest).
  • find_elements_specializing(query_url, elements, super_element_name) -> List[Dict]

    • Filters a list to only include elements that specialize a given supertype.
  • get_feature_value(server_url, project_id, commit_id, element, feature_name) -> Any

    • Extracts the value of a feature (attribute) from an element.

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.1.tar.gz (14.8 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.1-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for mbse4u_sysmlv2_helpers-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4df445745d20fabe9c12c86ba6e9e95ffe62a04060b4cef42fc4431b1aa29298
MD5 96cc6c52148fd48d0bd8a8baa764e564
BLAKE2b-256 a4190a0cf89368ce08d6a19c34242a94da77f47527b2f4e6adeff4bd816cdf97

See more details on using hashes here.

Provenance

The following attestation bundles were made for mbse4u_sysmlv2_helpers-0.1.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mbse4u_sysmlv2_helpers-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 732c83da1f1876c6c9cda983908ab12082e0ab3e495bb47b792f800ebb57a329
MD5 ffebfa55494e88ca495449599cc420c5
BLAKE2b-256 0ec3706d7b43e97aa61f8d931ca0dd7bc92f610a3c383e44d26b5da4316214ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for mbse4u_sysmlv2_helpers-0.1.1-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