Skip to main content

Servicers

Servicers are server-side (backend) classes where you implement the methods you declared for your durable state data types in your .proto files.

To implement the methods for a state type called, e.g., Account, you'll need to subclass the generated Account.Servicer class and provide an implementation for the abstract methods declared in that class. For example:

from bank.v1.bank_rbt import Account

class AccountServicer(Account.Servicer):
# ...

Each method will get passed:

  • context, a subclass of Context specific to the method kind (e.g., ReaderContext).
  • request of the type declared in the .proto.

reader, writer, and transaction methods are also passed:

  • state, e.g., Account.State for the Account servicer.

See workflow for more details about how they read and write state.

Here's an example of the reader method Balance on Account:

async def Balance(
self,
context: ReaderContext,
state: Account.State,
request: BalanceRequest,
) -> BalanceResponse:
return BalanceResponse(balance=state.balance)

If you've used gRPC this will look very familiar, with the difference being the type of context and the inclusion of the state argument for some of the methods.

For more details on the individual methods see the docs for: