Skip to main content

An easy setup object oriented RPC. Built-in setup for FastAPI and Flask

Project description

OBORPC

Downloads

Description

An easy to build RPC based on Object Oriented Programming. Build your RPC in seconds. Built-in setup for FastAPI and Flask.

Installation

pip install oborpc

Basic Examples

  1. Create calculator.py as your base
from oborpc.base import meta
from oborpc.decorator import procedure

class Calculator(meta.RPCBase):
    @procedure
    def add(self, a: int, b: int):
        pass

    @procedure
    def subtract(self, a: int, b: int):
        pass

class CalculatorServer(Calculator):
    def add(self, a: int, b: int):
        print(f"adding {a} and {b}")
        return a+b

    def subtract(self, a: int, b: int):
        print(f"subtracting {a} and {b}")
        return a - b
  1. Create your App, below we give 2 examples how to do it with Flask or FastAPI

    • using Flask
    from oborpc.builder import FlaskServerBuilder
    from calculator import CalculatorServer
    from flask import Flask
    
    calculator_server = CalculatorServer()
    
    server_builder = FlaskServerBuilder("http://localhost", 9000)
    calculator_blueprint = server_builder.build_blueprint_from_instance(
        calculator_server, "calculator", "calculator"
    )
    
    app = Flask(__name__)
    app.register_blueprint(calculator_blueprint)
    
    app.run(port=8000)
    
    • using FastAPI
    from oborpc.builder import FastAPIServerBuilder
    from calculator import CalculatorServer
    
    calculator_server = CalculatorServer()
    
    server_builder = FastAPIServerBuilder("http://localhost", 8000)
    calculator_router = server_builder.build_router_from_instance(
        calculator_server, prefix=""
    )
    
    
    from fastapi import FastAPI
    
    app = FastAPI()
    app.include_router(calculator_router)
    
  2. Create client, you can create a simple client.py or a client application

    • simple client.py
    from oborpc.builder import ClientBuilder
    from calculator import Calculator
    
    calculator = Calculator()
    
    client_builder = ClientBuilder("http://localhost", 8000)
    client_builder.build_client_rpc(calculator)
    
    print(calculator.add(1,2))
    
    • client application
    from calculator import Calculator
    from fastapi import FastAPI
    from oborpc.builder import ClientBuilder, FastAPIServerBuilder
    
    ## RPC setup
    calculator = Calculator()
    
    clientBuilder = ClientBuilder("http://localhost", 9000)
    clientBuilder.build_client_rpc(calculator)
    
    ## application
    app = FastAPI()
    
    @app.get("/calculator/add")
    def get_add_results(a: float, b: float):
        return calculator.add(a, b)
    
  3. Your RPC is ready to go!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

oborpc-0.2.0.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

oborpc-0.2.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file oborpc-0.2.0.tar.gz.

File metadata

  • Download URL: oborpc-0.2.0.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for oborpc-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e94a43cc6bfe5179b44b97495baa14e94c1e4b0787c5005a813fb3320029b588
MD5 4bf36a4bafbf58073468250c7846c10c
BLAKE2b-256 45d3df5e41473fc6ef4c9da57e21e363320d279b9b7586a1c0adbc2ad69b1703

See more details on using hashes here.

File details

Details for the file oborpc-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: oborpc-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for oborpc-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2e49d62884e67afe6d5962915f2ced0278c2f270c67aa5ebfdcfc4ff015d44c
MD5 c0410ddec74f26ef091542b245cee3fc
BLAKE2b-256 7dc6799df1d1acd8492eb18eb6db60bfb88532ad7c6a1c724f51f1b87d24d25b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page