oborpc


Nameoborpc JSON
Version 0.1.5 PyPI version JSON
download
home_pagehttps://github.com/Danangjoyoo/oborpc
SummaryAn easy setup object oriented RPC. Built-in setup for FastAPI and Flask
upload_time2024-07-21 06:49:06
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.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": 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/ad/b5/56cd9fd2107e95054436ff01dca5859a71824f831cde03ddae1a796c8116/oborpc-0.1.5.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": null,
    "summary": "An easy setup object oriented RPC. Built-in setup for FastAPI and Flask",
    "version": "0.1.5",
    "project_urls": {
        "Homepage": "https://github.com/Danangjoyoo/oborpc"
    },
    "split_keywords": [
        "fastapi",
        " flask",
        " rpc",
        " oop"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a5d801e1a106dfe3b31e214cf4ad67f7dd95d101dc746b1cfd58b07c8202f0a1",
                "md5": "679ff2d6b17ee6bcb53d03ed175da936",
                "sha256": "90a2caffdb62b1225d5e5255e2e537ca4daed71cb8e6ef88592ff7f64454764d"
            },
            "downloads": -1,
            "filename": "oborpc-0.1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "679ff2d6b17ee6bcb53d03ed175da936",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10866,
            "upload_time": "2024-07-21T06:49:05",
            "upload_time_iso_8601": "2024-07-21T06:49:05.663732Z",
            "url": "https://files.pythonhosted.org/packages/a5/d8/01e1a106dfe3b31e214cf4ad67f7dd95d101dc746b1cfd58b07c8202f0a1/oborpc-0.1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "adb556cd9fd2107e95054436ff01dca5859a71824f831cde03ddae1a796c8116",
                "md5": "b7e54fa4a1c4f80d83967d953111ebda",
                "sha256": "7889936f53aab6f3d22e0eb36acc526ad5f5d28f845e2500875879adeda11b3f"
            },
            "downloads": -1,
            "filename": "oborpc-0.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "b7e54fa4a1c4f80d83967d953111ebda",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8878,
            "upload_time": "2024-07-21T06:49:06",
            "upload_time_iso_8601": "2024-07-21T06:49:06.929341Z",
            "url": "https://files.pythonhosted.org/packages/ad/b5/56cd9fd2107e95054436ff01dca5859a71824f831cde03ddae1a796c8116/oborpc-0.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-21 06:49:06",
    "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: 1.89989s