Skip to content

Instantly share code, notes, and snippets.

@Ananto30
Last active December 17, 2021 17:00
Show Gist options
  • Save Ananto30/638b959d22bc96e0efbb18f6c4842c67 to your computer and use it in GitHub Desktop.
Save Ananto30/638b959d22bc96e0efbb18f6c4842c67 to your computer and use it in GitHub Desktop.
Example usage of Zero framework
import asyncio
from zero import AsyncZeroClient
zero_client = AsyncZeroClient("localhost", 5559)
async def echo():
resp = await zero_client.call("echo", "Hi there!")
print(resp)
async def hello():
resp = await zero_client.call("hello_world", None)
print(resp)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(echo())
loop.run_until_complete(hello())
from zero import ZeroServer
def echo(msg: str) -> str:
return msg
async def hello_world() -> str:
return "hello world"
if __name__ == "__main__":
app = ZeroServer(port=5559)
app.register_rpc(echo)
app.register_rpc(hello_world)
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment