Last active
December 17, 2021 17:00
-
-
Save Ananto30/638b959d22bc96e0efbb18f6c4842c67 to your computer and use it in GitHub Desktop.
Example usage of Zero framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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