# OBORPC
[![Downloads](https://static.pepy.tech/personalized-badge/oborpc?period=total&units=international_system&left_color=black&right_color=orange&left_text=Downloads)](https://pepy.tech/project/oborpc)
# Description
An easy to build RPC based on Object Oriented Programming. Build your RPC in seconds. Built-in setup for FastAPI and Flask.
# Installation
```bash
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.OBORBase):
@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
```
2. 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)
```
3. 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)
```
4. Your RPC is ready to go!
Raw data
{
"_id": null,
"home_page": "https://github.com/Danangjoyoo/oborpc",
"name": "oborpc",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "fastapi,flask,rpc,OOP",
"author": "danangjoyoo (Agus Danangjoyo)",
"author_email": "<agus.danangjoyo.blog@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/d6/c5/bb9258fcf77f9f99a76258348e5bf100f91d5d045c4e7a35683e5785e578/oborpc-0.1.2.tar.gz",
"platform": null,
"description": "# OBORPC\n[![Downloads](https://static.pepy.tech/personalized-badge/oborpc?period=total&units=international_system&left_color=black&right_color=orange&left_text=Downloads)](https://pepy.tech/project/oborpc)\n\n# Description\nAn easy to build RPC based on Object Oriented Programming. Build your RPC in seconds. Built-in setup for FastAPI and Flask.\n\n# Installation\n```bash\npip install oborpc\n```\n\n# Basic Examples\n1. Create `calculator.py` as your base\n```\nfrom oborpc.base import meta\nfrom oborpc.decorator import procedure\n\nclass Calculator(meta.OBORBase):\n @procedure\n def add(self, a: int, b: int):\n pass\n\n @procedure\n def subtract(self, a: int, b: int):\n pass\n\nclass CalculatorServer(Calculator):\n def add(self, a: int, b: int):\n print(f\"adding {a} and {b}\")\n return a+b\n\n def subtract(self, a: int, b: int):\n print(f\"subtracting {a} and {b}\")\n return a - b\n```\n\n2. Create your App, below we give 2 examples how to do it with Flask or FastAPI\n\n - using Flask\n ```\n from oborpc.builder import FlaskServerBuilder\n from calculator import CalculatorServer\n from flask import Flask\n\n calculator_server = CalculatorServer()\n\n server_builder = FlaskServerBuilder(\"http://localhost\", 9000)\n calculator_blueprint = server_builder.build_blueprint_from_instance(\n calculator_server, \"calculator\", \"calculator\"\n )\n\n app = Flask(__name__)\n app.register_blueprint(calculator_blueprint)\n\n app.run(port=8000)\n ```\n\n - using FastAPI\n ```\n from oborpc.builder import FastAPIServerBuilder\n from calculator import CalculatorServer\n\n calculator_server = CalculatorServer()\n\n server_builder = FastAPIServerBuilder(\"http://localhost\", 8000)\n calculator_router = server_builder.build_router_from_instance(\n calculator_server, prefix=\"\"\n )\n\n\n from fastapi import FastAPI\n\n app = FastAPI()\n app.include_router(calculator_router)\n ```\n\n3. Create client, you can create a simple `client.py` or a client application\n - simple `client.py`\n ```\n from oborpc.builder import ClientBuilder\n from calculator import Calculator\n\n calculator = Calculator()\n\n client_builder = ClientBuilder(\"http://localhost\", 8000)\n client_builder.build_client_rpc(calculator)\n\n print(calculator.add(1,2))\n ```\n\n - client application\n ```\n from calculator import Calculator\n from fastapi import FastAPI\n from oborpc.builder import ClientBuilder, FastAPIServerBuilder\n\n ## RPC setup\n calculator = Calculator()\n\n clientBuilder = ClientBuilder(\"http://localhost\", 9000)\n clientBuilder.build_client_rpc(calculator)\n\n ## application\n app = FastAPI()\n\n @app.get(\"/calculator/add\")\n def get_add_results(a: float, b: float):\n return calculator.add(a, b)\n ```\n\n4. Your RPC is ready to go!\n",
"bugtrack_url": null,
"license": "",
"summary": "An easy setup object oriented RPC. Built-in setup for FastAPI and Flask",
"version": "0.1.2",
"project_urls": {
"Homepage": "https://github.com/Danangjoyoo/oborpc"
},
"split_keywords": [
"fastapi",
"flask",
"rpc",
"oop"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "53e9fe68f6f6f4bf3c57848640a243667e345316d2238b5f018446417cc2b2d6",
"md5": "ecca7699f089d9ebd352e41899f7470a",
"sha256": "d4d911f0d124800f9362d86806dae439efb2f6d4a3b4e362e91c9e56b26c1320"
},
"downloads": -1,
"filename": "oborpc-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ecca7699f089d9ebd352e41899f7470a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 10372,
"upload_time": "2024-02-04T09:02:49",
"upload_time_iso_8601": "2024-02-04T09:02:49.357372Z",
"url": "https://files.pythonhosted.org/packages/53/e9/fe68f6f6f4bf3c57848640a243667e345316d2238b5f018446417cc2b2d6/oborpc-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d6c5bb9258fcf77f9f99a76258348e5bf100f91d5d045c4e7a35683e5785e578",
"md5": "387124fe23fc0a6ac6b00403cbf44515",
"sha256": "8bfbcd2e15cc6618783d4b23c53d70152c243bebd40b1b123e38d97418731021"
},
"downloads": -1,
"filename": "oborpc-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "387124fe23fc0a6ac6b00403cbf44515",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8352,
"upload_time": "2024-02-04T09:02:50",
"upload_time_iso_8601": "2024-02-04T09:02:50.610251Z",
"url": "https://files.pythonhosted.org/packages/d6/c5/bb9258fcf77f9f99a76258348e5bf100f91d5d045c4e7a35683e5785e578/oborpc-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-04 09:02:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Danangjoyoo",
"github_project": "oborpc",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "oborpc"
}