Skip to main content

Latest Release

maat_client

Python library for communicating with the Maat API (Management of Assets and Services) for managing physical resources, services, and their characteristics.

Installation

pip install maat_client

Or install from source:

pip install .

For development:

pip install -e ".[dev]"

Requirements

  • Python >= 3.8
  • requests

Quick Start

Initializing client with basic authentication

from maat_client import MaatClient

client = MaatClient(
    host="https://maat.example.com",
    resource_path="/resourceInventoryManagement/v4.0.0/resource",
    username="user",
    password="password"
)

Initializing client with Keycloak

from maat_client import MaatClient

client = MaatClient(
    host="https://maat.example.com",
    resource_path="/resourceInventoryManagement/v4.0.0/resource",
    kc_base_url="https://keycloak.example.com",
    kc_client_id="client_id",
    kc_client_secret="client_secret",
    kc_realm="realm",
    kc_username="user",
    kc_password="password"
)

Core Classes

MaatClient

Main client for communicating with the Maat API.

Constructor

MaatClient(
    host="https://localhost",
    resource_path="/resourceInventoryManagement/v4.0.0/resource",
    username=os.getenv("USER"),
    password=None,
    verify=True,
    request_timeout=None,
    kc_base_url=None,
    kc_client_id=None,
    kc_client_secret=None,
    kc_realm=None,
    kc_grant_type="password",
    kc_username=None,
    kc_password=None,
    kc_token_refresh_margin=30
)

Parameters:

  • host - Maat server address (default: https://localhost)
  • resource_path - Resource path (default: /resourceInventoryManagement/v4.0.0/resource)
  • username - Username for basic authentication (default: os.getenv("USER"))
  • password - Password for basic authentication
  • verify - SSL certificate verification (default: True)
  • request_timeout - Request timeout
  • kc_base_url - Keycloak address
  • kc_client_id - Keycloak client ID
  • kc_client_secret - Keycloak client secret
  • kc_realm - Keycloak realm
  • kc_grant_type - Keycloak grant type (password or client_credentials)
  • kc_username - Keycloak username
  • kc_password - Keycloak password
  • kc_token_refresh_margin - Token refresh margin in seconds (default: 30)

Methods

authenticate() -> bool

Explicitly verify Keycloak connectivity by fetching a fresh token, regardless of the cached token's validity. Intended for health checks and startup probes.

Returns: True when a fresh token was obtained, False when Keycloak is not configured (keycloak_enable=False)

Raises: MaatAuthError when Keycloak is unreachable or rejects the credentials

Example (health check):

try:
    client.authenticate()
except MaatAuthError as e:
    return {"status": "unhealthy", "reason": str(e)}, 503
return {"status": "ok"}, 200

Note: The constructor does not contact Keycloak. The access token is fetched lazily on the first API call, so instantiating MaatClient never fails due to Keycloak being unreachable. Use authenticate() if you want to verify connectivity explicitly (e.g. at startup or in a health check).

find(_query_params: dict)

Search for resources in the Maat database.

Parameters:

  • _query_params - Dictionary with filter rules

Returns: List of matching resources

Example:

resources = client.find({"name": "example-resource"})
get_resource(_resource_id: str, _query_params: dict = None)

Retrieve a single resource from the Maat database.

Parameters:

  • _resource_id - Maat resource ID
  • _query_params - Optional filter rules

Returns: Resource as a dictionary

Example:

resource = client.get_resource("resource-id-123")
add_resource(_resource) -> str

Add a resource to the Maat database.

Parameters:

  • _resource - Resource object with get_active_params() method

Returns: ID of the newly created resource

Example:

from maat_client import PhysicalResource

resource = PhysicalResource(name="example", type="example-type")
resource_id = client.add_resource(resource)
update_resource(_resource_id: str, _resource)

Update an existing resource, merging resourceCharacteristic lists.

Parameters:

  • _resource_id - Maat resource ID
  • _resource - Resource object with get_active_params() method

Example:

resource = PhysicalResource(name="updated-name")
client.update_resource("resource-id-123", resource)
delete_resource(_resource_id: str) -> bool

Delete a resource from the Maat database.

Parameters:

  • _resource_id - Maat resource ID

Returns: True on success

Example:

client.delete_resource("resource-id-123")

Characteristic

Resource characteristic (name-value pair).

Constructor

Characteristic(name=None, value=None)

Parameters:

  • name - Characteristic name
  • value - Characteristic value

Methods

  • to_dict() - Convert object to dictionary
  • to_str() - String representation
  • __repr__() - String representation for print and pprint

BaseResource

Base class for resources.

Constructor

BaseResource(
    category=None,
    description=None,
    href=None,
    id=None,
    name=None,
    resource_characteristic=None,
    resource_relationship=None,
    schema_location=None,
    type=None
)

Parameters:

  • category - Resource category
  • description - Resource description
  • href - Resource href
  • id - Resource ID
  • name - Resource name
  • resource_characteristic - List of characteristics (list[Characteristic])
  • resource_relationship - List of relationships (list[ResourceRelationship])
  • schema_location - Schema location
  • type - Resource type

Methods

  • to_dict() - Convert object to dictionary
  • to_str() - String representation
  • __repr__() - String representation for print and pprint

PhysicalResource

Physical resource.

Constructor

PhysicalResource(
    category=None,
    description=None,
    href=None,
    id=None,
    name=None,
    place=None,
    resource_characteristic=None,
    resource_relationship=None,
    schema_location=None,
    type=None,
    serial_number=None,
    operational_state=None,
    resource_status=None,
    usage_state=None
)

Parameters:

  • category - Resource category
  • description - Resource description
  • href - Resource href
  • id - Resource ID
  • name - Resource name
  • place - Resource location
  • resource_characteristic - List of characteristics (list[Characteristic])
  • resource_relationship - List of relationships (list[ResourceRelationship])
  • schema_location - Schema location
  • type - Resource type
  • serial_number - Serial number
  • operational_state - Operational state
  • resource_status - Resource status
  • usage_state - Usage state

Methods

  • to_dict() - Convert object to dictionary
  • get_active_params() - Get active (non-None) parameters
  • to_str() - String representation
  • __repr__() - String representation for print and pprint

Service

Service.

Constructor

Service(
    category=None,
    description=None,
    href=None,
    id=None,
    name=None,
    service_characteristic=None,
    service_relationship=None,
    resource_relationship=None,
    schema_location=None,
    type=None
)

Parameters:

  • category - Service category
  • description - Service description
  • href - Service href
  • id - Service ID
  • name - Service name
  • service_characteristic - List of service characteristics (list[Characteristic])
  • service_relationship - List of service relationships
  • resource_relationship - List of resource relationships (list[ResourceRelationship])
  • schema_location - Schema location
  • type - Service type

Methods

  • to_dict() - Convert object to dictionary
  • get_active_params() - Get active (non-None) parameters
  • to_str() - String representation
  • __repr__() - String representation for print and pprint

ResourceRelationship

Relationship between resources.

Constructor

ResourceRelationship(relationshipType=None, resource=None)

Parameters:

  • relationshipType - Relationship type
  • resource - Dictionary with resource information

Methods

  • to_dict() - Convert object to dictionary
  • to_str() - String representation
  • __repr__() - String representation for print and pprint

Usage Examples

Creating and adding a physical resource

from maat_client import MaatClient, PhysicalResource

# Initialize client
client = MaatClient(
    host="https://maat.example.com",
    username="user",
    password="password"
)

# Create physical resource
resource = PhysicalResource(
    name="example-router",
    type="router",
    serial_number="SN123456",
    operational_state="active",
    resource_characteristic=[
        Characteristic(name="interface-count", value="24"),
        Characteristic(name="vendor", value="Cisco")
    ]
)

# Add resource
resource_id = client.add_resource(resource)
print(f"Created resource with ID: {resource_id}")

Creating and adding a service

from maat_client import MaatClient, Service, Characteristic

# Initialize client
client = MaatClient(
    host="https://maat.example.com",
    username="user",
    password="password"
)

# Create service
service = Service(
    name="example-service",
    type="connectivity",
    service_characteristic=[
        Characteristic(name="bandwidth", value="1Gbps"),
        Characteristic(name="latency", value="10ms")
    ]
)

# Add service
service_id = client.add_resource(service)
print(f"Created service with ID: {service_id}")

Searching for resources

# Search for resources by name
resources = client.find({"name": "example-resource"})

# Search for resources by type
resources = client.find({"type": "router"})

# Search for resources with multiple criteria
resources = client.find({"name": "example", "type": "router"})

Updating a resource

from maat_client import PhysicalResource

# Retrieve existing resource
resource = client.get_resource("resource-id-123")

# Create update object
updated_resource = PhysicalResource(
    name="updated-name",
    resource_characteristic=[
        Characteristic(name="new-characteristic", value="value")
    ]
)

# Update resource
client.update_resource("resource-id-123", updated_resource)

Deleting a resource

# Delete resource
client.delete_resource("resource-id-123")

Errors

The library defines two main exception types:

  • MaatAuthError - Authentication errors (e.g., invalid Keycloak credentials)
  • MaatAPIError - API errors (e.g., invalid HTTP status code)

License

This project is distributed under the MIT License. See the LICENSE file for details.

Metadata

Release files for maat-client 0.2.0

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

Source distribution (sdist)

Source distribution for maat-client 0.2.0
File Size Uploaded Provenance Actions
maat_client-0.2.0.tar.gz 24.8 kB Without provenance Details for maat_client-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for maat-client 0.2.0
File Interpreter ABI Platform Actions
maat_client-0.2.0-py3-none-any.whl Python 3 none any Details for maat_client-0.2.0-py3-none-any.whl

Total release size: 43.6 kB

Release files / maat_client-0.2.0.tar.gz

Download URL maat_client-0.2.0.tar.gz
Size 24.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c263f9ebeced51eabd4495a16c65350dde45b343ece07f2a147e9d73cb592318
BLAKE2b-256 checksum
How to use checksums
6e3bf44b7eacd085fc2644d9b4975abb3420f1cea1d56865a8b4e17c8d7fb7c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / maat_client-0.2.0-py3-none-any.whl

Download URL maat_client-0.2.0-py3-none-any.whl
Size 18.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1afa7fe47813dfdda30690cd42148bf80504914130bfb4582d88868da69934d6
BLAKE2b-256 checksum
How to use checksums
900571591f2cc1987872d963ba26ad3db326ad6c8d6efa31fe10ff92f93881ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Security for maat-client 0.2.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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