oborpc


Nameoborpc JSON
Version 0.2.3 PyPI version JSON
download
home_pagehttps://github.com/Danangjoyoo/oborpc
SummaryAn easy setup object oriented RPC. Built-in setup for FastAPI and Flask
upload_time2025-01-09 17:55:49
maintainerNone
docs_urlNone
authordanangjoyoo (Agus Danangjoyo)
requires_pythonNone
licenseNone
keywords fastapi flask rpc oop
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.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
```

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": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "fastapi, flask, rpc, OOP",
    "author": "danangjoyoo (Agus Danangjoyo)",
    "author_email": "<agus.danangjoyo.blog@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/ae/e3/ddfb91dae8a3497c867b7d63ba6ac08613c45747c801c15bdbf90f54f512/oborpc-0.2.3.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.RPCBase):\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": null,
    "summary": "An easy setup object oriented RPC. Built-in setup for FastAPI and Flask",
    "version": "0.2.3",
    "project_urls": {
        "Homepage": "https://github.com/Danangjoyoo/oborpc"
    },
    "split_keywords": [
        "fastapi",
        " flask",
        " rpc",
        " oop"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cba965f03f719569b014e959a7625da51111dc147239b770d6c333d2b62de978",
                "md5": "69bf5c74588d41b2fc092cb2566406a8",
                "sha256": "a5bc7429469d4052231503bf34bdde87ac0b745515c8aad88fab0cd97938a503"
            },
            "downloads": -1,
            "filename": "oborpc-0.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "69bf5c74588d41b2fc092cb2566406a8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 12714,
            "upload_time": "2025-01-09T17:55:47",
            "upload_time_iso_8601": "2025-01-09T17:55:47.156879Z",
            "url": "https://files.pythonhosted.org/packages/cb/a9/65f03f719569b014e959a7625da51111dc147239b770d6c333d2b62de978/oborpc-0.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "aee3ddfb91dae8a3497c867b7d63ba6ac08613c45747c801c15bdbf90f54f512",
                "md5": "1aa18cf025eb0b5344b479c282f527be",
                "sha256": "511afdf67659a5816fefed41d8964db7c58d1947105991a36a941bb9f35bacbf"
            },
            "downloads": -1,
            "filename": "oborpc-0.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "1aa18cf025eb0b5344b479c282f527be",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10398,
            "upload_time": "2025-01-09T17:55:49",
            "upload_time_iso_8601": "2025-01-09T17:55:49.379367Z",
            "url": "https://files.pythonhosted.org/packages/ae/e3/ddfb91dae8a3497c867b7d63ba6ac08613c45747c801c15bdbf90f54f512/oborpc-0.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-09 17:55:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Danangjoyoo",
    "github_project": "oborpc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "oborpc"
}
        
Elapsed time: 0.42536s