Client¶
erpc.client ¶
HTTP client for eRPC runtime health and metrics endpoints.
Provides a lightweight client to query eRPC's health endpoint (on the server port) and Prometheus metrics endpoint (on the metrics port).
Examples:
Quick health check::
>>> client = ERPCClient("http://localhost:4000")
>>> client.is_healthy
True
>>> status = client.health()
>>> status.version
'0.0.49'
Fetch Prometheus metrics::
>>> metrics = client.metrics()
>>> metrics["erpc_requests_total{method=\"eth_call\"}"]
42.0
HealthStatus
dataclass
¶
Structured result from an eRPC health check.
Attributes:
| Name | Type | Description |
|---|---|---|
status |
str
|
Health status string (e.g. |
uptime |
float
|
Process uptime in seconds. |
version |
str
|
eRPC version string. |
Source code in erpc/client.py
from_dict
classmethod
¶
Create a HealthStatus from a JSON-decoded dictionary.
Missing fields are filled with sensible defaults so partial responses don't crash the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict[str, Any]
|
Decoded JSON body from the health endpoint. |
required |
Returns:
| Type | Description |
|---|---|
HealthStatus
|
Populated |
Source code in erpc/client.py
ERPCClient ¶
Lightweight HTTP client for eRPC runtime endpoints.
Uses only :mod:urllib from the standard library — no extra dependencies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Base URL of the eRPC server (e.g. |
required |
metrics_port
|
int
|
Port for the Prometheus metrics endpoint. Defaults to |
4001
|
timeout
|
int
|
HTTP request timeout in seconds. Defaults to |
5
|
Examples:
Source code in erpc/client.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
is_healthy
property
¶
Quick boolean health check.
Returns:
| Type | Description |
|---|---|
bool
|
|
__init__ ¶
Initialize the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Base URL of the eRPC server (e.g. |
required |
metrics_port
|
int
|
Port for the Prometheus metrics endpoint. |
4001
|
timeout
|
int
|
HTTP request timeout in seconds. |
5
|
Source code in erpc/client.py
health ¶
Fetch structured health status from eRPC.
Queries the server's root endpoint and parses the JSON response
into a :class:HealthStatus dataclass.
Returns:
| Type | Description |
|---|---|
HealthStatus
|
Parsed health status. |
Raises:
| Type | Description |
|---|---|
ERPCHealthCheckError
|
On connection failure, timeout, or unparseable response. |
Source code in erpc/client.py
metrics ¶
Fetch and parse Prometheus metrics from eRPC.
Queries the metrics endpoint and returns a flat dictionary of metric names (with labels) to their float values.
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Mapping of metric name (with labels) to value. |
Raises:
| Type | Description |
|---|---|
ERPCHealthCheckError
|
On connection failure or timeout. |