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
fastapi_app = FastAPI()
sio_app = FastAPISIO(app=fastapi_app)
purr_channel = sio_app.create_emitter(
"purrs",
model=PurrModel,
summary="Channel for purrs",
description="Receive any purrs here!",
)
@sio_app.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.io
part is set automatically by some clients) - The AsyncAPI spec file is at
/sio/docs/asyncapi.json
Find more in the examples.
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
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
File details
Details for the file fastapi_sio-0.5.1.tar.gz
.
File metadata
- Download URL: fastapi_sio-0.5.1.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.2 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe8912b70ca10cf8ef7e9b09d5b8575a8d4cddfa64280e6f46e9e4c802ce4e17 |
|
MD5 | de452936ede28b2454e5f760d9339045 |
|
BLAKE2b-256 | 376fd253b813a0b0155e4ebfa71946c7392060d8b622dfa2c73ba6d9d44dfd02 |
File details
Details for the file fastapi_sio-0.5.1-py3-none-any.whl
.
File metadata
- Download URL: fastapi_sio-0.5.1-py3-none-any.whl
- Upload date:
- Size: 11.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.2 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d8e91e44ebb8e5b847f3ff9f5a31acd3d2ce7323fb84851ffe248b20c46ce2c |
|
MD5 | 877bf5f6bc8d462579bd0e993cf74687 |
|
BLAKE2b-256 | 22fef022f79e3da274aa483b5743feaacee6d7aae6770d37ec8311fd6ac951b7 |