Skip to content

marianhlavac/fastapi-sio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastapi-sio

FastAPI library Socket.io Uses AsyncAPI Current state

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

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 (the socket.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.

About

FastAPI Socket.io with first-class documentation using AsyncAPI

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages