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 authenticationverify- SSL certificate verification (default:True)request_timeout- Request timeoutkc_base_url- Keycloak addresskc_client_id- Keycloak client IDkc_client_secret- Keycloak client secretkc_realm- Keycloak realmkc_grant_type- Keycloak grant type (passwordorclient_credentials)kc_username- Keycloak usernamekc_password- Keycloak passwordkc_token_refresh_margin- Token refresh margin in seconds (default:30)
Methods
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 withget_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 withget_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 namevalue- Characteristic value
Methods
to_dict()- Convert object to dictionaryto_str()- String representation__repr__()- String representation forprintandpprint
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 categorydescription- Resource descriptionhref- Resource hrefid- Resource IDname- Resource nameresource_characteristic- List of characteristics (list[Characteristic])resource_relationship- List of relationships (list[ResourceRelationship])schema_location- Schema locationtype- Resource type
Methods
to_dict()- Convert object to dictionaryto_str()- String representation__repr__()- String representation forprintandpprint
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 categorydescription- Resource descriptionhref- Resource hrefid- Resource IDname- Resource nameplace- Resource locationresource_characteristic- List of characteristics (list[Characteristic])resource_relationship- List of relationships (list[ResourceRelationship])schema_location- Schema locationtype- Resource typeserial_number- Serial numberoperational_state- Operational stateresource_status- Resource statususage_state- Usage state
Methods
to_dict()- Convert object to dictionaryget_active_params()- Get active (non-None) parametersto_str()- String representation__repr__()- String representation forprintandpprint
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 categorydescription- Service descriptionhref- Service hrefid- Service IDname- Service nameservice_characteristic- List of service characteristics (list[Characteristic])service_relationship- List of service relationshipsresource_relationship- List of resource relationships (list[ResourceRelationship])schema_location- Schema locationtype- Service type
Methods
to_dict()- Convert object to dictionaryget_active_params()- Get active (non-None) parametersto_str()- String representation__repr__()- String representation forprintandpprint
ResourceRelationship
Relationship between resources.
Constructor
ResourceRelationship(relationshipType=None, resource=None)
Parameters:
relationshipType- Relationship typeresource- Dictionary with resource information
Methods
to_dict()- Convert object to dictionaryto_str()- String representation__repr__()- String representation forprintandpprint
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.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| maat_client-0.1.1.tar.gz | 17.0 kB | Without provenance | Details for maat_client-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| maat_client-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for maat_client-0.1.1-py3-none-any.whl |
Total release size: 31.7 kB
Release files / maat_client-0.1.1.tar.gz
| Download URL | maat_client-0.1.1.tar.gz |
|---|---|
| Size | 17.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2e77aea6c82fb3087acdaa2a59335ec17875ff28b75b865daf9281160f0de7f
|
|
BLAKE2b-256 checksum How to use checksums |
26b3a0d11785cecb967ca329b8e003995f9f69f4b03ede8c80153d42005ccf5c
|
| 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.1.1-py3-none-any.whl
| Download URL | maat_client-0.1.1-py3-none-any.whl |
|---|---|
| Size | 14.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
58af5b4b060f76905857f4488d0fb006f304b54aa40cb421273cc50d7347b69c
|
|
BLAKE2b-256 checksum How to use checksums |
113d03d0bf07172937facbfaa6d4d444e61aa4da8cb4e4f4a3a72fa5ab9fb54c
|
| 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.1.1
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.