Skip to main content

Easly integrate socket.io with your FastAPI app.

Project description

fastapi-socketio

PyPI Changelog 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.

# 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.

# 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.

# 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:

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi-socketio-0.0.9.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

fastapi_socketio-0.0.9-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file fastapi-socketio-0.0.9.tar.gz.

File metadata

  • Download URL: fastapi-socketio-0.0.9.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9

File hashes

Hashes for fastapi-socketio-0.0.9.tar.gz
Algorithm Hash digest
SHA256 8c73aa94fe1bf1c9964ff89233a6ba52eeeec3ac8b9de0024d9d82b11e46bde5
MD5 5011ef34e8c6001af966968f77f8f02f
BLAKE2b-256 67a479a79ec12f315d18ace30d4fcb77e63b492be62a8e4bbc5f2dc0ddbf81b6

See more details on using hashes here.

File details

Details for the file fastapi_socketio-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: fastapi_socketio-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9

File hashes

Hashes for fastapi_socketio-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 30b86938f2216630a49f7706060870254126b027668b2434b42cfaf53c05223b
MD5 ecdc140ebb19f8406a0b4bcc4edee5d8
BLAKE2b-256 1b80b49c40af3154f91ecd459366019017a22ab9e6b5edc1a26850bb9626dab5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page