v0.4.0-beta
Msgspec as default serializer! π
Default serializer
Msgspec is the default serializer. So msgspec.Struct
(for high performance) or dataclass
or any supported types can be used easily to pass complex arguments, i.e.
from dataclasses import dataclass
from msgspec import Struct
from zero import ZeroServer
app = ZeroServer()
class Person(Struct):
name: str
age: int
dob: datetime
@dataclass
class Order:
id: int
amount: float
created_at: datetime
@app.register_rpc
def save_person(person: Person) -> None:
# save person to db
...
@app.register_rpc
def save_order(order: Order) -> None:
# save order to db
...
Return type
The return type of the RPC function can be any of the supported types. If return_type
is set in the client call
method, then the return type will be converted to that type.
@dataclass
class Order:
id: int
amount: float
created_at: datetime
def get_order(id: str) -> Order:
return zero_client.call("get_order", id, return_type=Order)
What's Changed
Full Changelog: v0.3.60-beta...v0.4.0-beta