Skip to content

✨ A mini lib to build http/websockets apps based on Starlette.

License

Notifications You must be signed in to change notification settings

ArtyTheDev/tinyasgi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TinyASGI

A little ASGI tool-kit to help you build your framework.

  • Fully typed with no errors.
  • Based on PEP8 and flake8.
  • Starlette standard config.
  • Asgiref typing.
  • Support both HTTP and WebSockets.

Example

import tinyasgi

@tinyasgi.application()
async def main(request: tinyasgi.RequestType) -> tinyasgi.ResponseType:
    # To check if the connection is a websocket
    # we use the `isinstance` method to check
    # if the class is a `tinyasgi.WebSocket`
    if isinstance(request, tinyasgi.WebSocket):
        # Accept the connection.
        await request.accept()

        while True:
            try:
                # Receive the text.
                recv = await request.receive_text()
                print(recv)
            except tinyasgi.WebSocketDisconnect:
                break
        
    if isinstance(request, tinyasgi.Request):
        return tinyasgi.PlainTextResponse("Hello, World")

Install

  • You need git to install it.
pip install git+https://github.com/ArtyTheDev/tinyasgi.git

About

✨ A mini lib to build http/websockets apps based on Starlette.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages