Skip to main content

High-level HTTP client for the AAS Part 2 API v3.x

Project description

basyx-client

PyPI version Python versions License CI

A high-level, BaSyx-model-native HTTP client for the AAS Part 2 API v3.x.

Why basyx-client?

Working with the AAS Part 2 API directly is painful:

  1. Identifier encoding - Every identifier must be base64url encoded (without padding!)
  2. idShortPath encoding - Brackets in paths like Sensors[0] must be URL-encoded as %5B0%5D
  3. No typed responses - You get raw dictionaries, not BaSyx model objects
  4. Manual error handling - Status codes must be checked and mapped to meaningful errors

basyx-client eliminates all of this friction:

from basyx_client import AASClient

# All encoding happens automatically
with AASClient("http://localhost:8081") as client:
    # Get an AAS - returns basyx.aas.model.AssetAdministrationShell, not dict
    aas = client.shells.get("https://acme.org/ids/aas/55")
    print(aas.id_short)  # Type-safe attribute access

    # Access submodel elements with array indices - brackets encoded automatically
    temp = client.submodels.elements.get_value(
        "https://acme.org/ids/sm/sensors",
        "Measurements[0].Temperature"  # [0] becomes %5B0%5D automatically
    )

Installation

pip install basyx-client

Docker (GHCR)

The GitHub Actions workflow publishes a Docker image on release:

docker pull ghcr.io/hadijannat/basyx-client:<version>

The image contains Python with basyx-client installed and defaults to python.

Features

  • Automatic encoding - Base64url for identifiers, URL-encoding for idShortPath
  • Typed responses - Returns basyx.aas.model.* objects, not dictionaries
  • Sync + async - Both synchronous and asynchronous operation support
  • Full auth suite - Bearer, Basic, OAuth2 client credentials, mTLS certificates
  • Proper exceptions - ResourceNotFoundError, ConflictError, etc. instead of generic errors
  • Pagination helpers - Easy iteration through paginated results
  • Element helpers - $metadata, $reference, $path, async operation status/result

Quick Start

Basic Usage

Note: the BaSyx Docker images in docker-compose.yml expose the API at the root (http://localhost:8081, no /api/v3.0). Some deployments mount the API at /api/v3.0 — set base_url accordingly.

from basyx_client import AASClient

with AASClient("http://localhost:8081") as client:
    # List all AAS
    result = client.shells.list()
    for aas in result.items:
        print(f"{aas.id_short}: {aas.id}")

    # Get a specific AAS
    aas = client.shells.get("urn:example:aas:machine-001")

    # Get a submodel
    sm = client.submodels.get("urn:example:sm:operational-data")

    # Get/set element values
    temp = client.submodels.elements.get_value(
        "urn:example:sm:operational-data",
        "Sensors.Temperature"
    )
    client.submodels.elements.set_value(
        "urn:example:sm:operational-data",
        "Sensors.Temperature",
        25.5
    )

Async Usage

import asyncio
from basyx_client import AASClient

async def main():
    async with AASClient("http://localhost:8081") as client:
        # Concurrent fetches
        aas1, aas2 = await asyncio.gather(
            client.shells.get_async("urn:example:aas:1"),
            client.shells.get_async("urn:example:aas:2"),
        )
        print(aas1.id_short, aas2.id_short)

asyncio.run(main())

Authentication

from basyx_client import AASClient
from basyx_client.auth import BearerAuth, OAuth2ClientCredentials

# Bearer token
client = AASClient("http://localhost:8081", auth=BearerAuth("my-token"))

# Basic auth (shorthand)
client = AASClient("http://localhost:8081", auth=("username", "password"))

# OAuth2 client credentials
client = AASClient("http://localhost:8081", auth=OAuth2ClientCredentials(
    token_url="https://auth.example.com/oauth/token",
    client_id="my-client",
    client_secret="my-secret",
    scope="aas:read aas:write",
))

# mTLS
client = AASClient(
    "https://secure.example.com",
    cert=("/path/to/cert.pem", "/path/to/key.pem"),
)

Error Handling

from basyx_client import AASClient
from basyx_client.exceptions import ResourceNotFoundError, ConflictError

with AASClient("http://localhost:8081") as client:
    try:
        aas = client.shells.get("urn:nonexistent:aas")
    except ResourceNotFoundError as e:
        print(f"AAS not found: {e.message}")
        print(f"URL: {e.url}")

    try:
        client.shells.create(my_aas)
    except ConflictError:
        print("AAS already exists")

Pagination

from basyx_client import AASClient
from basyx_client.pagination import iterate_pages

with AASClient("http://localhost:8081/api/v3.0") as client:
    # Manual pagination
    result = client.shells.list(limit=10)
    while result.has_more:
        for aas in result.items:
            process(aas)
        result = client.shells.list(limit=10, cursor=result.cursor)

    # Automatic pagination
    for aas in iterate_pages(lambda limit, cursor: client.shells.list(limit, cursor)):
        process(aas)

API Coverage

Endpoint Status
AAS Repository (/shells) ✅ Full
Submodel Repository (/submodels) ✅ Full
Submodel Elements (/submodels/{id}/submodel-elements/{path}) ✅ Full
Concept Descriptions (/concept-descriptions) ✅ Full
AAS Registry (/shell-descriptors) ✅ Full
Submodel Registry (/submodel-descriptors) ✅ Full
AASX Server (/packages) ✅ Full
Discovery (/lookup/shells) ✅ Full

Development

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/unit -v

# Run linter
ruff check src tests

# Type checking
mypy src

# Integration tests (requires Docker)
docker compose up -d
pytest tests/integration -v
docker compose down

License

Apache License 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

basyx_client-0.1.3.tar.gz (46.1 kB view details)

Uploaded Source

Built Distribution

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

basyx_client-0.1.3-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

Details for the file basyx_client-0.1.3.tar.gz.

File metadata

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

File hashes

Hashes for basyx_client-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6126119a9478c6d57b19874a919d35dd64970c7abd89f6b99c1057b53df71410
MD5 e60db357677d03f44fef0c66dace725e
BLAKE2b-256 d2b5f78a5ec8704d1d7bbc82a8e0cc3fa243cfd086b772354016aa3a519f955f

See more details on using hashes here.

Provenance

The following attestation bundles were made for basyx_client-0.1.3.tar.gz:

Publisher: publish.yml on hadijannat/basyx-client

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

File details

Details for the file basyx_client-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: basyx_client-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 36.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for basyx_client-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0886e2908df1cfae49f71af87192d63298ccc36961186a8ec80a14ddff0f2200
MD5 d5c7f8bf8429c782604fdba0dfb62722
BLAKE2b-256 32dcb4490f62882c05e6818324dea0f67e4e572a5a09ee8f0f0bb158f0300c1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for basyx_client-0.1.3-py3-none-any.whl:

Publisher: publish.yml on hadijannat/basyx-client

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