Skip to main content

Python SDK for Matrix Hub — catalog search, entity detail, install, and remote management for agents, tools, and MCP servers.

Project description

Matrix Python SDK

PyPI Version Python 3.11+ CI Status License

The matrix-python-sdk is the official Python Software Development Kit (SDK) for the Matrix Hub API. It provides a high-level, programmatic interface for interacting with the Matrix Hub, designed for developers and enterprises building solutions within the Matrix ecosystem.

Key Features

  • Catalog Management: Search and retrieve detailed information about agents, tools, and other catalog entities.
  • Package Installation: Programmatically install agents, tools, and MCP servers with dependency resolution.
  • Remote & Ingestion Control: Manage catalog remotes and trigger data ingestion processes.
  • Bulk Operations: A lightweight micro-framework for registering millions of MCP servers concurrently.

Installation

To install the library, run the following command:

pip install matrix-python-sdk

Requirements

  • Python: Version 3.11 or newer.

Optional Extras

You can install additional dependencies for specific functionalities:

  • CLI: pip install "matrix-python-sdk[cli]" for the matrix servers bulk-registration command-line interface.
  • Development: pip install "matrix-python-sdk[dev]" for installing development dependencies (testing, linting).

Getting Started

The following example demonstrates how to initialize the client and perform a basic catalog search.

from matrix_sdk.client import MatrixClient
from matrix_sdk.cache import Cache
from matrix_sdk.schemas import SearchResponse

# 1. (Optional) Initialize a local cache to improve performance for repeated requests.
#    The TTL (Time To Live) is set in seconds.
cache = Cache(cache_dir="~/.cache/matrix", ttl=(4 * 60 * 60)) # 4 hours

# 2. Initialize the MatrixClient with your Hub URL and authentication token.
client = MatrixClient(
    base_url="http://localhost:7300",
    token="YOUR_MATRIX_TOKEN",
    cache=cache,
)

# 3. Perform a catalog search for agents related to "summarize pdfs".
#    Filters can be applied for capabilities, frameworks, providers, etc.
resp: SearchResponse = client.search(
    q="summarize pdfs",
    type="agent",
    capabilities="pdf,summarize",
    frameworks="langgraph,crewai",
    providers="openai,watsonx",
    mode="hybrid",
    limit=10,
)

# 4. Process and display the search results.
print(f"Found {resp.total} results matching your query:")
for item in resp.items:
    print(f"- ID: {item.id} (Score: {item.score_final:.2f})\n  Summary: {item.summary}\n")

API Reference

MatrixClient

The matrix_sdk.client.MatrixClient is the primary interface for interacting with the Matrix Hub API.

Method Description Returns
.search(...) Performs a full-text and filtered search of the catalog. SearchResponse
.get_entity(id) Retrieves the full manifest and metadata for a given entity UID. EntityDetail
.install(id, target, …) Executes an installation plan (e.g., pip, docker, adapters). InstallOutcome
.list_remotes() Lists all configured catalog remotes. dict
.add_remote(url, …) Adds a new remote index, including its name and trust policy. dict
.trigger_ingest(name) Manually initiates the ingestion process for a specified remote. dict

Cache

The matrix_sdk.cache.Cache is an optional component for caching API responses to reduce latency and API load.

  • Constructor: Cache(cache_dir: Path | str, ttl: int)
  • Methods:
    • .get(key, allow_expired=False)CachedResponse | None
    • .set(key, response, etag=None)None

Data Types (matrix_sdk.schemas)

The SDK uses Pydantic models for structured, type-hinted data in API requests and responses. Key models include:

  • Search & Entities: SearchItem, SearchResponse, EntityDetail
  • Installation: InstallStepResult, InstallOutcome
  • Errors: MatrixAPIError

Bulk Server Registration

For managing large-scale deployments, the BulkRegistrar provides an efficient, asynchronous method to register multiple MCP servers from various sources.

from matrix_sdk.bulk.bulk_registrar import BulkRegistrar
import asyncio

# Define sources for server discovery (e.g., Git repository)
sources = [
    {
        "kind": "git",
        "url": "https://github.com/IBM/docling-mcp",
        "ref": "main",
        "probe": True
    }
]

# Initialize the registrar with the gateway URL and an admin token
registrar = BulkRegistrar(
    gateway_url="http://localhost:4444",
    token="YOUR_ADMIN_TOKEN",
    concurrency=100
)

# Asynchronously register all servers found in the defined sources
results = asyncio.run(registrar.register_servers(sources))
print(results)

Development & Testing

To contribute to development or run tests locally, first set up the environment.

# Install development dependencies
make install

Running Tests

Execute the test suite using the Makefile:

make test

Code Style & Linting

We use ruff and black for linting and formatting, which can be run easily via the Makefile.

# Check for code style issues
make lint

# Automatically format all code
make fmt

Continuous Integration (CI) is configured via GitHub Actions. See the workflow file at .github/workflows/ci.yml.


License

This project is licensed under the Apache 2.0 License.

© Agent Matrix — LICENSE


Contributing

We welcome contributions from the community. Please read our CONTRIBUTING.md for guidelines on how to submit issues, feature requests, and pull requests.


Matrix Hub and the Matrix Python SDK are open-source projects by the Agent Matrix team.

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

matrix_python_sdk-0.1.1.tar.gz (36.6 kB view details)

Uploaded Source

Built Distribution

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

matrix_python_sdk-0.1.1-py3-none-any.whl (41.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for matrix_python_sdk-0.1.1.tar.gz
Algorithm Hash digest
SHA256 004440fe31b4fa57986c9f5c14b40869c086b6ad82998981031751935d3a561a
MD5 f06d2273a896996e7e5699127989e0c6
BLAKE2b-256 c0588bea392bcae95bc6ba3be0932771593a6884a7758ebf088ff3d74c5d6a74

See more details on using hashes here.

Provenance

The following attestation bundles were made for matrix_python_sdk-0.1.1.tar.gz:

Publisher: release.yml on agent-matrix/matrix-python-sdk

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

File details

Details for the file matrix_python_sdk-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for matrix_python_sdk-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 39a764582aa4d1c9a8e2fa82198baefe5db9997a8bdc7ad024e6c945b57ca85c
MD5 ff6c3e320784813b39a5bbfd012f281e
BLAKE2b-256 d12fbbb2b0608a2e1a082b01cf3d9ff872e2938849bf186e0888f499aa61ae68

See more details on using hashes here.

Provenance

The following attestation bundles were made for matrix_python_sdk-0.1.1-py3-none-any.whl:

Publisher: release.yml on agent-matrix/matrix-python-sdk

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