Skip to main content

Thin Python client for metagraphed — the operational + integration registry for Bittensor subnets (api.metagraph.sh).

Project description

metagraphed (Python)

Thin, dependency-free Python client for metagraphed — the operational + integration registry for Bittensor subnets at https://api.metagraph.sh.

It mirrors the npm client: one generic GET helper over the uniform, read-only API surface, returning the parsed { ok, schema_version, data, meta } envelope. Stdlib only — no transitive dependencies.

Install

pip install metagraphed              # dependency-free sync client
pip install 'metagraphed[async]'     # adds the async client (pulls httpx)

Usage

from metagraphed import MetagraphedClient, metagraphed_fetch

client = MetagraphedClient()  # base_url defaults to https://api.metagraph.sh

# List subnets (query params; None values are dropped). The /subnets collection
# nests its rows under data.subnets:
subnets = client.fetch(
    "/api/v1/subnets",
    query={"limit": 10, "sort": "completeness_score", "order": "desc"},
)
print(subnets["data"]["subnets"][0]["name"])

# One subnet by netuid (path params)
detail = client.fetch("/api/v1/subnets/{netuid}", path_params={"netuid": 7})

# Which subnets are buildable? (integration readiness lives in the agent catalog)
catalog = client.fetch("/api/v1/agent-catalog")

# Health of the registry itself:
health = metagraphed_fetch("/api/v1/health")

Every response is the standard envelope:

{"ok": True, "schema_version": 1, "data": ..., "meta": {...}}

On a network failure or non-2xx response, a MetagraphedError is raised (with .status for HTTP errors, and the API error code/message in the message).

Retries, pagination, and the RPC proxy

from metagraphed import (
    MetagraphedClient,
    metagraphed_paginate,
    metagraphed_rpc,
)

# Opt-in retry/backoff for idempotent GETs (retries 429/5xx + network errors,
# honoring a numeric Retry-After). Disabled by default.
client = MetagraphedClient(retries=3)

# Iterate every page of a list endpoint (follows meta.pagination.next_cursor):
for page in client.paginate("/api/v1/subnets", query={"limit": 100}):
    for subnet in page["data"]["subnets"]:
        print(subnet["netuid"])

# Call the read-only Subtensor RPC proxy and get back the JSON-RPC result:
info = metagraphed_rpc("finney", "system_health")

fetch_all + typed models

from metagraphed import MetagraphedClient

client = MetagraphedClient(retries=3)

# Auto-paginate a list endpoint and collect every item (flattened data arrays):
all_surfaces = client.fetch_all("/api/v1/surfaces")

# Typed convenience methods — IDE autocomplete, while .raw keeps the full dict:
for subnet in client.subnets():
    print(subnet.netuid, subnet.name, subnet.integration_readiness)

catalog = client.agent_catalog(7)  # -> AgentCatalogSubnet
print(catalog.service_count, catalog.services)

fetch / fetch_all still return raw dicts; the models (Subnet, Surface, Endpoint, Provider, AgentCatalogSubnet) are opt-in and never lose data.

Async client (httpx)

Install the extra (pip install 'metagraphed[async]'), then fetch many subnets concurrently — no hand-rolled threads:

import asyncio
from metagraphed import AsyncMetagraphedClient

async def main():
    async with AsyncMetagraphedClient(retries=3) as client:
        subnets = await client.subnets()  # typed, auto-paginated
        catalogs = await asyncio.gather(
            *(client.agent_catalog(s.netuid) for s in subnets[:10])
        )
        for c in catalogs:
            print(c.netuid, c.service_count)

asyncio.run(main())

The async client mirrors the sync one (fetch / paginate / fetch_all / rpc + retries/backoff) and reuses a single connection pool.

Versioning & stability

Tracks the public /api/v1 contract; changes are additive within v1. See the backend's API stability policy.

License

Apache-2.0 — see LICENSE. (The metagraphed backend itself is AGPL-3.0; this client SDK is permissively licensed so you can embed it freely.)

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

metagraphed-0.3.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

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

metagraphed-0.3.0-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file metagraphed-0.3.0.tar.gz.

File metadata

  • Download URL: metagraphed-0.3.0.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for metagraphed-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6076c09fe48c3f969cabad30f7c2e1045f149ab11f56fb7327d7da1f64ff2927
MD5 373c6f43d5391009564124cd0ee7ecec
BLAKE2b-256 b80bed413a5c2bcefebdb35d96f710638f20568bcbcb75a9923bf913ecbf3fa7

See more details on using hashes here.

Provenance

The following attestation bundles were made for metagraphed-0.3.0.tar.gz:

Publisher: publish-python.yml on JSONbored/metagraphed

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

File details

Details for the file metagraphed-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: metagraphed-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for metagraphed-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f95176cd01f46aff06bf1dd506549294028acb04f80655510b5dd57d90fa08d
MD5 4be7049513596e78b16fb872d6e2d2c8
BLAKE2b-256 98b4d410b3df80f16acaf4595b934e99814bf662d69c9db3da156be46d6cd872

See more details on using hashes here.

Provenance

The following attestation bundles were made for metagraphed-0.3.0-py3-none-any.whl:

Publisher: publish-python.yml on JSONbored/metagraphed

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