Socket.io for FastAPI with AsyncAPI documentation
Project description
fastapi-sio
Socket.io FastAPI integration library with first-class documentation using AsyncAPI
The usage of the library is very familiar to the experience you‘re used to in FastAPI. Automatic documentation, type hints everywhere and heavy use of Pydantic.
Features
- First-class generated specification & documentation
- Uses python_socketio underneath
- Fully typed using pydantic, including the AsyncAPI spec
- Streamlined emit to clients (learn more in docs)
- Forces strictly to emit correct data type (see the example)
What‘s Missing?
- Serve AsyncAPI studio at /sio/docs
- Unfortunately, AsyncAPI studio doesn‘t work the same way as Swagger UI, there is currently no way to use CDN hosted built package and supply only single html file and URL with spec JSON
- Support for more obscure fields of AsyncAPI, such as
traits, ...
Usage Example
from fastapi import FastAPI
from pydantic import BaseModel
from fastapi_sio import FastAPISIO
class PurrModel(BaseModel):
detail: str
loudness: int
class BellyRubModel(BaseModel):
where_exactly: str
scratches_num: int
fastapi = FastAPI()
sio = FastAPISIO(app=fastapi)
# Mount this ASGI app. The FastAPI app is passed as the other_asgi_app
# so you'll have access to the FastAPI routes as well.
app = sio.asgi_app
# Run with `uvicorn examples.from_readme:app`
@fastapi.get("/")
async def example_fastapi_route():
return {"message": "Welcome to the FastAPI-SIO example!"}
purr_channel = sio.create_emitter(
"purrs",
model=PurrModel,
summary="Channel for purrs",
description="Receive any purrs here!",
)
@sio.on(
"rubs",
model=BellyRubModel,
summary="Channel for belly rubs",
description="Send your belly rubs through here!",
)
async def handle_rub(sid, data):
await purr_channel.emit(PurrModel(loudness=2, detail="Purr for all listeners"))
return "Ack to the one who rubbed"
👉 Check out the example AsyncAPI documentation output!
By default (you can change these values):
- the Socket.io endpoint path is
/sio/socket.io(thesocket.iopart is set automatically by some clients) - The AsyncAPI spec file is at
/sio/docs/asyncapi.json
Find more in the example.
Documentation & Reference
Refer to the /docs directory to learn how to use this library in your project.
TODO: This documentation will be hosted on Github Pages in the near future, hopefully.
Contribution
...
Used by
Feel free to open a PR to add your project or company to this list.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_sio-0.7.0.tar.gz.
File metadata
- Download URL: fastapi_sio-0.7.0.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.13.2 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c1371aff031e3e42c49f32c7b9db5562c65ec71527922f54a767dd2f2002440
|
|
| MD5 |
097d1d2050b49ad1f52534356357d438
|
|
| BLAKE2b-256 |
059738605b7cdc6229e1a7d3d2dc7a68932592bcd50bd66e468370bede70a075
|
File details
Details for the file fastapi_sio-0.7.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_sio-0.7.0-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.1 CPython/3.13.2 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a28b1bb1ec75bfdd60700642527de189021282840b65bfec9dd67d5c85bc63c2
|
|
| MD5 |
7461179cf3fc98907904d40581a73dba
|
|
| BLAKE2b-256 |
a59a15c21907b5549750d0bcf5067ffe140fdd424285326360134a241e2a9241
|