fastwapi


Namefastwapi JSON
Version 0.1.3 PyPI version JSON
download
home_page
SummaryA simple API Websocket server to easily parse JSON
upload_time2023-06-15 11:30:09
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT License Copyright (c) 2023 lonode Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords websocket api json
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Description

FastWAPI is a simple lightweight Websocket framework based on Starlette, which provide easy-to-use Python decorator to parse JSON incoming message.  

It's in the same spirit as _FastAPI_, where each decorator map to an HTTP path. But here, each decorator map to a Pydantic object, and each object map to a function. 

# Installation

`pip install fastwapi`
# Disclaimer

 - The module is available, but far from finished & polished, please do not use it in production.

# Roadmap 

- Add authent middleware
- Add background job to asynchrounosly send JSON to the client

# Usage 

See example/main.py for complete code.

Getting started in three steps :

#### Instanciates the framework and declare the Websocket HTTP endpoint.  

```python
import uvicorn
from fastwapi import FastWAPI, WebSocket
from pydantic import BaseModel

app = FastWAPI(endpoint="/ws")

```

#### Define Pyndantic model, for incoming and outgoing messages.

```python
class CM(BaseModel):
    counter: int

class SD(BaseModel):
    name: str
```

#### Map each Pydantic model to your function.

```python
@app.parse(CM)
async def parse_CM(websocket: WebSocket, data: CM):
    print("RECEIVED CM : ", data)
    await websocket.send_json(data.dict())

@app.parse(SD)
async def parse_SD(websocket: WebSocket, data: CM):
    print("RECEIVED SD : ", data)
    await websocket.send_json(data.dict())
```

## Launch your app

Either through command line "uvicorn main:app" or directly inside the python file :

```python
if __name__ == "__main__":
    uvicorn.run("main:app", port=5000, log_level="info")
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "fastwapi",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "websocket,api,json",
    "author": "",
    "author_email": "lonode <lonode-git@proton.me>",
    "download_url": "https://files.pythonhosted.org/packages/5d/ac/ea1bb40ad2fc348039e7c0d384436b57d54b54c9c53db2d361767e1682b3/fastwapi-0.1.3.tar.gz",
    "platform": null,
    "description": "# Description\r\n\r\nFastWAPI is a simple lightweight Websocket framework based on Starlette, which provide easy-to-use Python decorator to parse JSON incoming message.  \r\n\r\nIt's in the same spirit as _FastAPI_, where each decorator map to an HTTP path. But here, each decorator map to a Pydantic object, and each object map to a function. \r\n\r\n# Installation\r\n\r\n`pip install fastwapi`\r\n# Disclaimer\r\n\r\n - The module is available, but far from finished & polished, please do not use it in production.\r\n\r\n# Roadmap \r\n\r\n- Add authent middleware\r\n- Add background job to asynchrounosly send JSON to the client\r\n\r\n# Usage \r\n\r\nSee example/main.py for complete code.\r\n\r\nGetting started in three steps :\r\n\r\n#### Instanciates the framework and declare the Websocket HTTP endpoint.  \r\n\r\n```python\r\nimport uvicorn\r\nfrom fastwapi import FastWAPI, WebSocket\r\nfrom pydantic import BaseModel\r\n\r\napp = FastWAPI(endpoint=\"/ws\")\r\n\r\n```\r\n\r\n#### Define Pyndantic model, for incoming and outgoing messages.\r\n\r\n```python\r\nclass CM(BaseModel):\r\n    counter: int\r\n\r\nclass SD(BaseModel):\r\n    name: str\r\n```\r\n\r\n#### Map each Pydantic model to your function.\r\n\r\n```python\r\n@app.parse(CM)\r\nasync def parse_CM(websocket: WebSocket, data: CM):\r\n    print(\"RECEIVED CM : \", data)\r\n    await websocket.send_json(data.dict())\r\n\r\n@app.parse(SD)\r\nasync def parse_SD(websocket: WebSocket, data: CM):\r\n    print(\"RECEIVED SD : \", data)\r\n    await websocket.send_json(data.dict())\r\n```\r\n\r\n## Launch your app\r\n\r\nEither through command line \"uvicorn main:app\" or directly inside the python file :\r\n\r\n```python\r\nif __name__ == \"__main__\":\r\n    uvicorn.run(\"main:app\", port=5000, log_level=\"info\")\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 lonode  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "A simple API Websocket server to easily parse JSON",
    "version": "0.1.3",
    "project_urls": {
        "Homepage": "https://github.com/lonode/FastWAPI"
    },
    "split_keywords": [
        "websocket",
        "api",
        "json"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0cad8726495ebe671599e95ee5ed1aac31bc402570e2176ed4f22cdf246b491a",
                "md5": "c00d0899ce25495d90978cf05dbf4036",
                "sha256": "762fee5b90cda9b01688bb2e3f9043d13c20a93508a327a5dc9d06a5e94875f3"
            },
            "downloads": -1,
            "filename": "fastwapi-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c00d0899ce25495d90978cf05dbf4036",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4939,
            "upload_time": "2023-06-15T11:30:07",
            "upload_time_iso_8601": "2023-06-15T11:30:07.700976Z",
            "url": "https://files.pythonhosted.org/packages/0c/ad/8726495ebe671599e95ee5ed1aac31bc402570e2176ed4f22cdf246b491a/fastwapi-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5dacea1bb40ad2fc348039e7c0d384436b57d54b54c9c53db2d361767e1682b3",
                "md5": "a2a44e5a5529316a2059b3cc423caa70",
                "sha256": "69d206f98dc65be729ab96d11cfc92565a815b38f8edc2a1c362804dd83590e7"
            },
            "downloads": -1,
            "filename": "fastwapi-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "a2a44e5a5529316a2059b3cc423caa70",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 3830,
            "upload_time": "2023-06-15T11:30:09",
            "upload_time_iso_8601": "2023-06-15T11:30:09.535060Z",
            "url": "https://files.pythonhosted.org/packages/5d/ac/ea1bb40ad2fc348039e7c0d384436b57d54b54c9c53db2d361767e1682b3/fastwapi-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-15 11:30:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lonode",
    "github_project": "FastWAPI",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "fastwapi"
}
        
Elapsed time: 0.07982s