Server¶
erpc.server ¶
eRPC server, metrics, and CORS configuration dataclasses.
Maps the eRPC server configuration surface to Python dataclasses,
matching the Go ServerConfig, MetricsConfig, and CORSConfig
structs from erpc/common/config.go.
Examples:
>>> from erpc.server import ServerConfig, MetricsConfig, CORSConfig
>>> server = ServerConfig(http_host="0.0.0.0", http_port=8080)
>>> server.to_dict()
{'httpHostV4': '0.0.0.0', 'httpPort': 8080, 'maxTimeout': '60s'}
CORSConfig
dataclass
¶
Cross-Origin Resource Sharing configuration for the eRPC server.
When all fields are at their defaults (empty lists, False, 0),
CORS is effectively disabled and to_dict() returns an empty dict
so no cors key appears in the generated YAML.
Attributes:
| Name | Type | Description |
|---|---|---|
allowed_origins |
list[str]
|
Origins permitted to make cross-origin requests. |
allowed_methods |
list[str]
|
HTTP methods allowed in cross-origin requests. |
allowed_headers |
list[str]
|
HTTP headers allowed in cross-origin requests. |
allow_credentials |
bool
|
Whether credentials (cookies, auth) are allowed. |
max_age |
int
|
How long (seconds) browsers should cache preflight responses. |
Examples:
Source code in erpc/server.py
to_dict ¶
Serialize to an eRPC-compatible dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with camelCase keys. Returns empty dict when all |
dict[str, Any]
|
values are at their defaults (CORS disabled). |
Source code in erpc/server.py
ServerConfig
dataclass
¶
eRPC HTTP server configuration.
Maps to the server section of the eRPC YAML config.
Attributes:
| Name | Type | Description |
|---|---|---|
http_host |
str
|
Bind address for the HTTP server. |
http_port |
int
|
Listen port for the HTTP server. |
max_timeout |
str
|
Maximum request timeout (e.g. |
enable_gzip |
bool
|
Enable gzip compression for responses. |
listen_v6 |
bool
|
Enable IPv6 listening. |
cors |
CORSConfig
|
Cross-origin resource sharing configuration. |
Examples:
>>> server = ServerConfig(http_host="0.0.0.0", http_port=8080)
>>> server.to_dict()["httpHostV4"]
'0.0.0.0'
Source code in erpc/server.py
to_dict ¶
Serialize to an eRPC-compatible dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with camelCase keys. Boolean fields that are |
dict[str, Any]
|
|
Source code in erpc/server.py
MetricsConfig
dataclass
¶
eRPC metrics / Prometheus endpoint configuration.
Maps to the metrics section of the eRPC YAML config.
Attributes:
| Name | Type | Description |
|---|---|---|
enabled |
bool
|
Whether the metrics endpoint is active. |
host |
str
|
Bind address for the metrics HTTP server. |
port |
int
|
Listen port for the metrics HTTP server. |
Examples:
>>> metrics = MetricsConfig(enabled=True, host="0.0.0.0", port=9090)
>>> metrics.to_dict()
{'enabled': True, 'host': '0.0.0.0', 'port': 9090}
Source code in erpc/server.py
to_dict ¶
Serialize to an eRPC-compatible dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with metrics configuration. When disabled, only |
dict[str, Any]
|
|