BIRPC is a simple and efficient bidirectional RPC (Remote Procedure Call) library built on top of WebSockets for Python. It facilitates seamless communication between server and client applications using the power of asynchronous Python. BIRPC is inspired by and a Python version of the original JavaScript package biRPC.
- ๐ Bidirectional communication between server and client
- ๐ Asynchronous support with
asyncio
- ๐ก๏ธ Flexible error handling and timeouts
- ๐ Simple method registration and remote invocation
- โก Built on top of WebSockets for efficient communication
pip install birpc
import asyncio
from birpc import BIRPC
async def main():
server = BIRPC("server", "localhost", 9000)
def local_method(arg1, arg2):
return arg1 * arg2
server.register_local_method(local_method)
await server.start()
asyncio.run(main())
import asyncio
from birpc import BIRPC
async def main():
client = BIRPC("client", "localhost", 9000, reconnect_interval=1, timeout=2)
await client.start()
result = await client.call("local_method", 5, 6)
print("Result:", result)
asyncio.run(main())
BIRPC has built-in error handling, which allows you to capture and process exceptions raised by remote methods.
import asyncio
from birpc import BIRPC
async def main():
client = BIRPC("client", "localhost", 9000, reconnect_interval=1, timeout=2)
await client.start()
try:
result = await client.call("local_method", 5, 6)
print("Result:", result)
except Exception as e:
print(f"Error: {e}")
asyncio.run(main())
Timeouts can be specified during client initialization, ensuring that RPC requests don't hang indefinitely.
This project is licensed under the MIT License.
This module was fully written by ChatGPT-4, by OpenAI. ๐ค๐ฌ