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.8.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi-socketio-0.0.8.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for fastapi-socketio-0.0.8.tar.gz
Algorithm Hash digest
SHA256 f4d3c7d7f582ba45fbda4067bf88bfe4866cb2fd5762d3ff760a712bde165c86
MD5 fa48f6d95c62844e0e9732378d81c70d
BLAKE2b-256 7cb683ced31df785a1cb5db585e289c0e054f5ffb130ef59052c070f2cc67eff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastapi_socketio-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.10

File hashes

Hashes for fastapi_socketio-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 abf136c4dff5eabeb5dec6a5bda73eaed8f464007e43f9d8a6eda88e2364758f
MD5 c64613240515d9a14e83eb9619823c8b
BLAKE2b-256 6b3086496c3083dc6895b1d815c275e110f2bfdefc63a1483d33e7017ab2daf8

See more details on using hashes here.

Supported by

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