Giter VIP home page Giter VIP logo

birpc's Introduction

๐Ÿ”„ BIRPC

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.

๐ŸŒŸ Features

  • ๐Ÿ”„ 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

โš™๏ธ Installation

pip install birpc

๐Ÿ› ๏ธ Usage

Server

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())

Client

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())

๐Ÿ”ง Error Handling

BIRPC has built-in error handling, which allows you to capture and process exceptions raised by remote methods.

Example

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())

โฒ๏ธ Timeout

Timeouts can be specified during client initialization, ensuring that RPC requests don't hang indefinitely.

๐Ÿ“„ License

This project is licensed under the MIT License.

๐Ÿ™Œ Acknowledgements

This module was fully written by ChatGPT-4, by OpenAI. ๐Ÿค–๐Ÿ’ฌ

birpc's People

Contributors

igvr avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.