# metricq/metricq-python architecture

> Architecture diagram of the GitHub repository metricq/metricq-python, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/metricq/metricq-python
- Repository: https://github.com/metricq/metricq-python

## Overview

MetricQ-Python is a client library for the MetricQ protocol. A producer registers with the management network, declares metrics, then publishes timestamped values; a sink subscribes to metrics and receives values. The library also exposes historical-data access, drain/subscriber utilities, source variants, CLI support, and time-series types. The graph includes the shared agent/client and RPC layers. Some subsystem internals were not excerpted, so uncertain runtime links are omitted or marked unverified.

Main entry points: [`metricq/source.py`](https://github.com/metricq/metricq-python/blob/master/metricq/source.py) (Source), [`metricq/history_client.py`](https://github.com/metricq/metricq-python/blob/master/metricq/history_client.py) (History client), [`metricq/agent.py`](https://github.com/metricq/metricq-python/blob/master/metricq/agent.py) (Agent lifecycle), [`metricq/client.py`](https://github.com/metricq/metricq-python/blob/master/metricq/client.py) (Management client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_protocol["Protocol clients"]
  node_agent["Agent lifecycle<br/>[agent.py]"]
  node_client["Management client<br/>[client.py]"]
  node_data_client["Data client<br/>[data_client.py]"]
  node_rpc["RPC dispatch<br/>[rpc.py]"]
  node_watchdog["Connection watchdog"]
end

subgraph group_stream["Live data"]
  node_producer["Source<br/>[source.py]"]
  node_metric["Source metric<br/>[source_metric.py]"]
  node_interval["Interval source<br/>[interval_source.py]"]
  node_syncsource["Synchronous source"]
  node_sink["Sink<br/>[sink.py]"]
  node_subscriber["Subscriber<br/>[subscription.py]"]
end

subgraph group_history["History and utilities"]
  node_history["History client<br/>[history_client.py]"]
  node_drain["Drain<br/>[drain.py]"]
  node_pandas["Pandas history"]
end

subgraph group_core["Shared foundations"]
  node_cli["CLI decorators<br/>[decorator.py]"]
  node_params["CLI parameters<br/>[params.py]"]
  node_time["Time-series types"]
  node_logging["Logging<br/>[logging.py]"]
  node_exceptions["Exceptions<br/>[exceptions.py]"]
  node_version["Version metadata<br/>[version.py]"]
end

node_actor(("Application"))
node_network{{"MetricQ network"}}
node_history_store[("History service")]

node_actor -->|"configures"| node_producer
node_producer -->|"registers and publishes"| node_network
node_actor -->|"selects metrics"| node_sink
node_network -->|"delivers values"| node_sink
node_producer -->|"delegates points"| node_metric
node_producer -->|"configures data"| node_data_client
node_interval -->|"extends"| node_producer
node_syncsource -->|"extends"| node_producer
node_sink -->|"uses"| node_data_client
node_subscriber -->|"uses"| node_client
node_drain -->|"uses"| node_sink
node_history -->|"extends"| node_client
node_actor -.->|"requests history"| node_history
node_history -.->|"requests data"| node_history_store
node_history -->|"provides data to"| node_pandas
node_client -->|"extends"| node_agent
node_data_client -->|"extends"| node_client
node_agent -->|"dispatches"| node_rpc
node_agent -->|"monitors connections"| node_watchdog
node_history -->|"monitors connection"| node_watchdog
node_producer -->|"calls handlers"| node_rpc
node_history -->|"uses time values"| node_time
node_params -->|"parses time values"| node_time
node_actor -.->|"invokes commands"| node_cli
node_cli -->|"uses parameters"| node_params
node_agent -->|"logs activity"| node_logging
node_agent -->|"raises errors"| node_exceptions

click node_producer "https://github.com/metricq/metricq-python/blob/master/metricq/source.py"
click node_metric "https://github.com/metricq/metricq-python/blob/master/metricq/source_metric.py"
click node_interval "https://github.com/metricq/metricq-python/blob/master/metricq/interval_source.py"
click node_syncsource "https://github.com/metricq/metricq-python/blob/master/metricq/synchronous_source.py"
click node_sink "https://github.com/metricq/metricq-python/blob/master/metricq/sink.py"
click node_subscriber "https://github.com/metricq/metricq-python/blob/master/metricq/subscription.py"
click node_agent "https://github.com/metricq/metricq-python/blob/master/metricq/agent.py"
click node_client "https://github.com/metricq/metricq-python/blob/master/metricq/client.py"
click node_data_client "https://github.com/metricq/metricq-python/blob/master/metricq/data_client.py"
click node_rpc "https://github.com/metricq/metricq-python/blob/master/metricq/rpc.py"
click node_watchdog "https://github.com/metricq/metricq-python/blob/master/metricq/connection_watchdog.py"
click node_history "https://github.com/metricq/metricq-python/blob/master/metricq/history_client.py"
click node_drain "https://github.com/metricq/metricq-python/blob/master/metricq/drain.py"
click node_pandas "https://github.com/metricq/metricq-python/blob/master/metricq/pandas/pandas_history_client.py"
click node_cli "https://github.com/metricq/metricq-python/blob/master/metricq/cli/decorator.py"
click node_params "https://github.com/metricq/metricq-python/blob/master/metricq/cli/params.py"
click node_time "https://github.com/metricq/metricq-python/tree/master/metricq/timeseries"
click node_logging "https://github.com/metricq/metricq-python/blob/master/metricq/logging.py"
click node_exceptions "https://github.com/metricq/metricq-python/blob/master/metricq/exceptions.py"
click node_version "https://github.com/metricq/metricq-python/blob/master/metricq/version.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_agent,node_client,node_data_client,node_rpc,node_watchdog toneBlue
class node_producer,node_metric,node_interval,node_syncsource,node_sink,node_subscriber,node_history_store toneAmber
class node_history,node_drain,node_pandas toneMint
class node_cli,node_params,node_time,node_logging,node_exceptions,node_version toneRose
class node_actor,node_network toneIndigo
```

## Components

### Protocol clients

- [Agent lifecycle](https://github.com/metricq/metricq-python/blob/master/metricq/agent.py): `metricq/agent.py`
- [Management client](https://github.com/metricq/metricq-python/blob/master/metricq/client.py): `metricq/client.py`
- [Data client](https://github.com/metricq/metricq-python/blob/master/metricq/data_client.py): `metricq/data_client.py`
- [RPC dispatch](https://github.com/metricq/metricq-python/blob/master/metricq/rpc.py): `metricq/rpc.py`
- [Connection watchdog](https://github.com/metricq/metricq-python/blob/master/metricq/connection_watchdog.py): `metricq/connection_watchdog.py`

### Live data

- [Source](https://github.com/metricq/metricq-python/blob/master/metricq/source.py): `metricq/source.py`
- [Source metric](https://github.com/metricq/metricq-python/blob/master/metricq/source_metric.py): `metricq/source_metric.py`
- [Interval source](https://github.com/metricq/metricq-python/blob/master/metricq/interval_source.py): `metricq/interval_source.py`
- [Synchronous source](https://github.com/metricq/metricq-python/blob/master/metricq/synchronous_source.py): `metricq/synchronous_source.py`
- [Sink](https://github.com/metricq/metricq-python/blob/master/metricq/sink.py): `metricq/sink.py`
- [Subscriber](https://github.com/metricq/metricq-python/blob/master/metricq/subscription.py): `metricq/subscription.py`

### History and utilities

- [History client](https://github.com/metricq/metricq-python/blob/master/metricq/history_client.py): `metricq/history_client.py`
- [Drain](https://github.com/metricq/metricq-python/blob/master/metricq/drain.py): `metricq/drain.py`
- [Pandas history](https://github.com/metricq/metricq-python/blob/master/metricq/pandas/pandas_history_client.py): `metricq/pandas/pandas_history_client.py`

### Shared foundations

- [CLI decorators](https://github.com/metricq/metricq-python/blob/master/metricq/cli/decorator.py): `metricq/cli/decorator.py`
- [CLI parameters](https://github.com/metricq/metricq-python/blob/master/metricq/cli/params.py): `metricq/cli/params.py`
- [Time-series types](https://github.com/metricq/metricq-python/tree/master/metricq/timeseries): `metricq/timeseries`
- [Logging](https://github.com/metricq/metricq-python/blob/master/metricq/logging.py): `metricq/logging.py`
- [Exceptions](https://github.com/metricq/metricq-python/blob/master/metricq/exceptions.py): `metricq/exceptions.py`
- [Version metadata](https://github.com/metricq/metricq-python/blob/master/metricq/version.py): `metricq/version.py`

### Other components

- **Application**
- **MetricQ network**
- **History service**

## Connections

- Application → Source: configures (evidence: `README.md`)
- Source → MetricQ network: registers and publishes (evidence: `metricq/source.py`)
- Application → Sink: selects metrics (evidence: `README.md`)
- MetricQ network → Sink: delivers values (evidence: `README.md`)
- Source → Source metric: delegates points (evidence: `metricq/source.py`)
- Source → Data client: configures data (evidence: `metricq/source.py`)
- Interval source → Source: extends (evidence: `metricq/interval_source.py`)
- Synchronous source → Source: extends (evidence: `metricq/synchronous_source.py`)
- Sink → Data client: uses (evidence: `metricq/data_client.py`)
- Subscriber → Management client: uses (evidence: `metricq/subscription.py`)
- Drain → Sink: uses (evidence: `metricq/drain.py`)
- History client → Management client: extends (evidence: `metricq/history_client.py`)
- Application → History client: requests history
- History client → History service: requests data
- History client → Pandas history: provides data to (evidence: `metricq/pandas/pandas_history_client.py`)
- Management client → Agent lifecycle: extends (evidence: `metricq/client.py`)
- Data client → Management client: extends (evidence: `metricq/data_client.py`)
- Agent lifecycle → RPC dispatch: dispatches (evidence: `metricq/agent.py`)
- Agent lifecycle → Connection watchdog: monitors connections (evidence: `metricq/agent.py`)
- History client → Connection watchdog: monitors connection (evidence: `metricq/history_client.py`)
- Source → RPC dispatch: calls handlers (evidence: `metricq/source.py`)
- History client → Time-series types: uses time values (evidence: `metricq/history_client.py`)
- CLI parameters → Time-series types: parses time values (evidence: `metricq/cli/params.py`)
- Application → CLI decorators: invokes commands
- CLI decorators → CLI parameters: uses parameters (evidence: `metricq/cli/decorator.py`)
- Agent lifecycle → Logging: logs activity (evidence: `metricq/agent.py`)
- Agent lifecycle → Exceptions: raises errors (evidence: `metricq/agent.py`)
