Introspection¶
Discover an RPC service's methods, schemas, and parameter types at runtime or statically.
Usage¶
Static introspection (no server needed)¶
Use rpc_methods() to inspect a Protocol class, or describe_rpc() for a human-readable summary:
from vgi_rpc import describe_rpc, rpc_methods
methods = rpc_methods(Calculator)
for name, info in methods.items():
print(f"{name}: {info.method_type.value}, params={info.params_schema}")
print(describe_rpc(Calculator))
Runtime introspection (over a connection)¶
Enable the built-in __describe__ method on the server, then query it from any client:
from vgi_rpc import RpcServer, introspect, connect
# Server: enable describe
server = RpcServer(Calculator, CalculatorImpl(), enable_describe=True)
# Client: query over pipe/subprocess
with connect(Calculator, ["python", "worker.py"]) as proxy:
desc = introspect(proxy._transport)
for name, method in desc.methods.items():
print(f"{name}: {method.method_type.value}")
# Client: query over HTTP
from vgi_rpc import http_introspect
desc = http_introspect("http://localhost:8080")
The ServiceDescription contains method metadata, parameter schemas, default values, and docstrings — everything a dynamic client needs without the Python Protocol class.
For stream methods that declare a header type (Stream[S, H]), MethodDescription includes has_header (bool) and header_schema (pa.Schema | None) fields describing the header's Arrow schema. These are False / None for methods without headers.
API Reference¶
Functions¶
introspect
¶
introspect(
transport: RpcTransport,
ipc_validation: IpcValidation = FULL,
) -> ServiceDescription
Send a __describe__ request over any RpcTransport.
| PARAMETER | DESCRIPTION |
|---|---|
transport
|
An open
TYPE:
|
ipc_validation
|
Validation level for incoming IPC batches.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ServiceDescription
|
A |
| RAISES | DESCRIPTION |
|---|---|
RpcError
|
If the server does not support introspection or returns an error. |
Source code in vgi_rpc/introspect.py
rpc_methods
cached
¶
rpc_methods(protocol: type) -> Mapping[str, RpcMethodInfo]
Introspect a Protocol class and return RpcMethodInfo for each method.
Skips underscore-prefixed names and non-callable attributes.
Source code in vgi_rpc/rpc/_types.py
describe_rpc
¶
describe_rpc(
protocol: type,
*,
methods: Mapping[str, RpcMethodInfo] | None = None
) -> str
Return a human-readable description of an RPC protocol's methods.
Source code in vgi_rpc/rpc/__init__.py
Data Classes¶
ServiceDescription
dataclass
¶
ServiceDescription(
protocol_name: str,
request_version: str,
describe_version: str,
server_id: str,
methods: Mapping[str, MethodDescription],
)
Complete description of an RPC service from introspection.
| ATTRIBUTE | DESCRIPTION |
|---|---|
protocol_name |
Name of the Protocol class.
TYPE:
|
request_version |
Wire protocol version.
TYPE:
|
describe_version |
Introspection format version.
TYPE:
|
server_id |
Server instance identifier.
TYPE:
|
methods |
Mapping of method name to
TYPE:
|
__str__
¶
Return a human-readable summary of the service.
Source code in vgi_rpc/introspect.py
MethodDescription
dataclass
¶
MethodDescription(
name: str,
method_type: MethodType,
doc: str | None,
has_return: bool,
params_schema: Schema,
result_schema: Schema,
param_types: dict[str, str] = dict(),
param_defaults: dict[str, object] = dict(),
has_header: bool = False,
header_schema: Schema | None = None,
)
Description of a single RPC method from introspection.
For STREAM methods, result_schema reflects the Protocol-level
return type (always empty). The actual stream output schema is
determined at runtime by the implementation and cannot be reported
statically.
| ATTRIBUTE | DESCRIPTION |
|---|---|
name |
Method name as it appears on the Protocol.
TYPE:
|
method_type |
Whether this is UNARY or STREAM.
TYPE:
|
doc |
The method's docstring, or
TYPE:
|
has_return |
TYPE:
|
params_schema |
Arrow schema for request parameters.
TYPE:
|
result_schema |
Arrow schema for the response (unary) or empty (streams).
TYPE:
|
param_types |
Human-readable type names keyed by parameter name.
TYPE:
|
param_defaults |
Parsed default values keyed by parameter name.
TYPE:
|
has_header |
TYPE:
|
header_schema |
Arrow schema for the header, or
TYPE:
|
Constants¶
DESCRIBE_METHOD_NAME
module-attribute
¶
Well-known method name for introspection requests.