fastapi-socketio


Namefastapi-socketio JSON
Version 0.0.7 PyPI version JSON
download
home_pagehttps://github.com/pyropy/fastapi-socketio
SummaryEasly integrate socket.io with your FastAPI app.
upload_time2021-06-17 11:37:11
maintainer
docs_urlNone
authorSrdjan Stankovic
requires_python
licenseApache License, Version 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # fastapi-socketio

[![PyPI](https://img.shields.io/pypi/v/fastapi-socketio.svg)](https://pypi.org/project/fastapi-socketio/)
[![Changelog](https://img.shields.io/github/v/release/pyropy/fastapi-socketio?label=changelog)](https://github.com/pyropy/fastapi-socketio/releases)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/pyropy/fastapi-socketio/blob/main/LICENSE)

Easly integrate socket.io with your FastAPI app.

## Installation

Install this plugin using `pip`:

    $ pip install fastapi-socketio

## Usage

To add SocketIO support to FastAPI all you need to do is import `SocketManager` and pass it `FastAPI` object.

```python
# app.py
from fastapi import FastAPI
from fastapi_socketio import SocketManager

app = FastAPI()
socket_manager = SocketManager(app=app)
```


Now you can use SocketIO directly from your `FastAPI` app object.
```python
# socket_handlers.py
from .app import app

@app.sio.on('join')
async def handle_join(sid, *args, **kwargs):
    await app.sio.emit('lobby', 'User joined')

```

Or you can import `SocketManager` object that exposes most of the SocketIO functionality.

```python
# socket_handlers2.py
from .app import socket_manager as sm

@sm.on('leave')
async def handle_leave(sid, *args, **kwargs):
    await sm.emit('lobby', 'User left')

```

## Development

To contribute to this library, first checkout the code. Then create a new virtual environment:

    cd fastapi-socketio
    python -mvenv venv
    source venv/bin/activate

Or if you are using `pipenv`:

    pipenv shell

Now install the dependencies and tests:

    pip install -e '.[test]'

To run the tests:

    pytest


## Run example

To run the examples simply run:

```bash
PYTHONPATH=. python examples/app.py
```

Before running example make sure you have all dependencies installed.

## Contributors

For list of contributors please reefer to CONTRIBUTORS.md file in this repository.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pyropy/fastapi-socketio",
    "name": "fastapi-socketio",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Srdjan Stankovic",
    "author_email": "stankovic.srdjo@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/b8/70/f06f4131122cf7a4df454362c8248a1f950c5008310d3de0232f1255fa47/fastapi-socketio-0.0.7.tar.gz",
    "platform": "",
    "description": "# fastapi-socketio\n\n[![PyPI](https://img.shields.io/pypi/v/fastapi-socketio.svg)](https://pypi.org/project/fastapi-socketio/)\n[![Changelog](https://img.shields.io/github/v/release/pyropy/fastapi-socketio?label=changelog)](https://github.com/pyropy/fastapi-socketio/releases)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/pyropy/fastapi-socketio/blob/main/LICENSE)\n\nEasly integrate socket.io with your FastAPI app.\n\n## Installation\n\nInstall this plugin using `pip`:\n\n    $ pip install fastapi-socketio\n\n## Usage\n\nTo add SocketIO support to FastAPI all you need to do is import `SocketManager` and pass it `FastAPI` object.\n\n```python\n# app.py\nfrom fastapi import FastAPI\nfrom fastapi_socketio import SocketManager\n\napp = FastAPI()\nsocket_manager = SocketManager(app=app)\n```\n\n\nNow you can use SocketIO directly from your `FastAPI` app object.\n```python\n# socket_handlers.py\nfrom .app import app\n\n@app.sio.on('join')\nasync def handle_join(sid, *args, **kwargs):\n    await app.sio.emit('lobby', 'User joined')\n\n```\n\nOr you can import `SocketManager` object that exposes most of the SocketIO functionality.\n\n```python\n# socket_handlers2.py\nfrom .app import socket_manager as sm\n\n@sm.on('leave')\nasync def handle_leave(sid, *args, **kwargs):\n    await sm.emit('lobby', 'User left')\n\n```\n\n## Development\n\nTo contribute to this library, first checkout the code. Then create a new virtual environment:\n\n    cd fastapi-socketio\n    python -mvenv venv\n    source venv/bin/activate\n\nOr if you are using `pipenv`:\n\n    pipenv shell\n\nNow install the dependencies and tests:\n\n    pip install -e '.[test]'\n\nTo run the tests:\n\n    pytest\n\n\n## Run example\n\nTo run the examples simply run:\n\n```bash\nPYTHONPATH=. python examples/app.py\n```\n\nBefore running example make sure you have all dependencies installed.\n\n## Contributors\n\nFor list of contributors please reefer to CONTRIBUTORS.md file in this repository.\n\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "Easly integrate socket.io with your FastAPI app.",
    "version": "0.0.7",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "952d08cc291263455cd4c78137a60f99",
                "sha256": "be14762c78eadea1fb2c3e05487b00b964d2d15e06fffa922f4eda71058cef8a"
            },
            "downloads": -1,
            "filename": "fastapi_socketio-0.0.7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "952d08cc291263455cd4c78137a60f99",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7428,
            "upload_time": "2021-06-17T11:37:10",
            "upload_time_iso_8601": "2021-06-17T11:37:10.683904Z",
            "url": "https://files.pythonhosted.org/packages/83/31/4882aec7913857567d31423c9e1a15d6f0ae1c56f5364e9198f5686ad868/fastapi_socketio-0.0.7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "a0bf581cd7015a89a7b2e69254a0b151",
                "sha256": "4001cc7b681e0360bc5348bcee911d5b45edac226e6b5664f15ea4584384f463"
            },
            "downloads": -1,
            "filename": "fastapi-socketio-0.0.7.tar.gz",
            "has_sig": false,
            "md5_digest": "a0bf581cd7015a89a7b2e69254a0b151",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7192,
            "upload_time": "2021-06-17T11:37:11",
            "upload_time_iso_8601": "2021-06-17T11:37:11.573464Z",
            "url": "https://files.pythonhosted.org/packages/b8/70/f06f4131122cf7a4df454362c8248a1f950c5008310d3de0232f1255fa47/fastapi-socketio-0.0.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-06-17 11:37:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "pyropy",
    "error": "Could not fetch GitHub repository",
    "lcname": "fastapi-socketio"
}
        
Elapsed time: 0.26219s