Skip to content

Python

Python binding

The Python binding lets an asyncio application host service methods and call methods on other peers. Python defines payloads and handlers; the PyO3 bridge connects them to Aster’s shared Rust transport and dispatcher.

Use it for an asynchronous worker, control service, or consumer that needs peer calls and optional data exchange. Start with one request and response, then add streaming or private session state as the application needs them. The first-service project supplies matching producer and consumer files.

The Python preview is distributed through Forgejo packages, rather than PyPI. Choose the wheel for your platform from the Python artifact list: Apple Silicon macOS, Linux x86-64 or ARM64 (glibc 2.34+), or Windows x86-64.

For example, on Apple Silicon macOS:

Terminal window
python -m pip install https://forge.emrul.dev/api/packages/Aster/generic/aster-python/0.3.893/aster_rpc-0.3.893-cp39-abi3-macosx_11_0_arm64.whl

Use the corresponding wheel URL on other platforms. Python 3.9–3.13 is required. The optional CLI is independently versioned; see the CLI reference for installation and its validation limits.

This in-process demonstration uses a real peer connection and explicitly allows unenrolled consumers. Use it with test data.

import asyncio
from dataclasses import dataclass
from aster import AsterServer, AsterClient, service, rpc
@dataclass
class HelloRequest:
name: str = ""
@dataclass
class HelloResponse:
message: str = ""
@service
class HelloService:
@rpc
async def say_hello(self, req: HelloRequest) -> HelloResponse:
return HelloResponse(message=f"Hello, {req.name}!")
async def main():
# Producer
async with AsterServer(services=[HelloService()], allow_all_consumers=True) as srv:
addr = srv.address
# Consumer
async with AsterClient(address=addr) as client:
hello = await client.client(HelloService)
resp = await hello.say_hello(HelloRequest(name="World"))
print(resp.message) # "Hello, World!"
asyncio.run(main())

The server context owns the producer node. The client context owns the consumer endpoint and connections. The inner context closes first, so no call outlives its endpoint. The expected result is Hello, World!.

For cross-language services, add explicit wire names and match the remote contract; the local Python example shares one definition.

Task Continue with
Register handlers and control server lifetime Python server
Connect, call, and handle refusals Python client
Define payloads, streams, and service scope Service guide
Configure identity and protected access Trust model

Define services and methods with decorators on plain Python classes:

Decorator Purpose
@service Mark a class as an Aster RPC service.
@rpc Unary RPC method.
@server_stream Server-streaming method (async generator).
@client_stream Client-streaming method.
@bidi_stream Bidirectional streaming method.
@wire_type("ns/Type") Stable wire identity for a dataclass.
API Purpose
AsterServer(services=[...]) High-level declarative producer. Handles admission, hooks, and ALPN routing.
Server(endpoint, services=[...]) Lower-level server. Manual endpoint and connection management.
API Purpose
AsterClient(address="aster1...") High-level declarative consumer. Handles admission and service discovery.
create_client(ServiceClass, connection=conn) Lower-level client. Wraps an existing QUIC connection.
API Purpose
AsterConfig Unified configuration dataclass. Loads from env vars, TOML files, or code.
AsterConfig.from_env() Build config from ASTER_* environment variables.
AsterConfig.from_file("aster.toml") Build config from TOML file with env overrides.
config.print_config() Display resolved config with provenance.
API Purpose
generate_root_keypair() Generate an ed25519 root keypair (offline use).
sign_credential(...) Sign an enrollment credential with the root private key.
ConsumerEnrollmentCredential Dataclass representing a signed enrollment token.

Built-in middleware chain:

Interceptor Purpose
DeadlineInterceptor Enforce and propagate call deadlines.
AuthInterceptor Token-based authentication.
RetryInterceptor Automatic retry for idempotent methods.
CircuitBreakerInterceptor Circuit breaker pattern for failing endpoints.
AuditLogInterceptor Log all RPC calls for audit.
CapabilityInterceptor Application/local-transport capability policy; network dispatch also enforces requirements in Rust.
API Purpose
@service(scoped="session") Producer-side: one service instance per connection-scoped session ID (the class __init__ receives a peer argument).
await client.session("ServiceName") Consumer-side: open a session-scoped service through SessionProxyClient. Calls carry the same connection-scoped session ID on separate streams.

Python defines service schemas and runs application handlers on asyncio. The PyO3 bridge exposes Rust operations as awaitables. The shared Rust dispatcher owns framing, method lookup, deadline enforcement, sessions, and capability checks; Python interceptors add application policy around handlers.

The SDK also exposes node identity, blobs, documents, gossip, leases, topology, and coordination clients. Start with the data guide and coordination guide for their behavior and ownership boundaries. Check the release matrix before using newer parity helpers from a source example.