Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pyropy/fastapi-socketio
Easily integrate socket.io with your FastAPI app 🚀
https://github.com/pyropy/fastapi-socketio
fastapi fastapi-socketio python socketio websocket
Last synced: 3 months ago
JSON representation
Easily integrate socket.io with your FastAPI app 🚀
- Host: GitHub
- URL: https://github.com/pyropy/fastapi-socketio
- Owner: pyropy
- License: apache-2.0
- Archived: true
- Created: 2020-09-11T15:22:31.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-11-26T03:02:26.000Z (about 1 year ago)
- Last Synced: 2024-09-29T12:17:58.284Z (3 months ago)
- Topics: fastapi, fastapi-socketio, python, socketio, websocket
- Language: Python
- Homepage:
- Size: 33.2 KB
- Stars: 329
- Watchers: 3
- Forks: 31
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-fastapi - FastAPI SocketIO - Easy integration for FastAPI and SocketIO. (Third-Party Extensions / Utils)
- awesome-fastapi - FastAPI SocketIO - Easy integration for FastAPI and SocketIO. (Third-Party Extensions / Utils)
README
# 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 SocketManagerapp = 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/activateOr 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.