Skip to main content

Toolkit for building ASGI applications and libraries

Project description

Asgikit - ASGI Toolkit

Asgikit is a toolkit for building asgi applications and frameworks.

The examples directory contain usage examples of several use cases

Features:

  • Request
    • Headers
    • Cookies
    • Body (bytes, str, json, form, stream)
    • Form
  • Response
    • Plain text
    • Json
    • Streaming
    • File
  • Websockets

Example request and response

from asgikit import Request


async def main(scope, receive, send):
    assert scope["type"] == "http"

    request = Request(scope, receive, send)

    # request method
    method = request.method

    # request path
    path = request.path

    # request headers
    headers = request.headers

    # read body as json
    body = await request.read_json()

    data = {
        "lang": "Python",
        "async": True,
        "platform": "asgi",
        "method": method,
        "path": path,
        "headers": dict(headers.items()),
        "body": body,
    }

    # send json response
    await request.respond_json(data)

Example websocket

from asgikit import WebSocket, WebSocketDisconnect


async def app(scope, receive, send):
    assert scope["type"] == "websocket"

    ws = WebSocket(scope, receive, send)
    await ws.accept()

    while True:
        try:
            message = await ws.read()
            await ws.write(message)
        except WebSocketDisconnect:
            print("Client disconnect")
            break

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

asgikit-0.16.2.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

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

asgikit-0.16.2-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file asgikit-0.16.2.tar.gz.

File metadata

  • Download URL: asgikit-0.16.2.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.1 CPython/3.14.0 Linux/6.14.0-35-generic

File hashes

Hashes for asgikit-0.16.2.tar.gz
Algorithm Hash digest
SHA256 6fa8b515786deb58645b9791002183faa2b908b8d2c9c893e1671b4f3dcc6089
MD5 e0c033d6ff4e5d879655fcaf84138103
BLAKE2b-256 8e2bb4af5d69b392d7b3e3df5d05d2fdacd0625ea0fe8aaf9b0d083e0d773d92

See more details on using hashes here.

File details

Details for the file asgikit-0.16.2-py3-none-any.whl.

File metadata

  • Download URL: asgikit-0.16.2-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.26.1 CPython/3.14.0 Linux/6.14.0-35-generic

File hashes

Hashes for asgikit-0.16.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7a7efbba42220057eac2761b6f6b265eb01458f80c4ed547a0b36d80a2d0d1f1
MD5 5e72f0293fbc715fef71b36c6512be98
BLAKE2b-256 493d5a982b513ba3e574a0a7333d47c5f170f3c7909c12dad6a9755b93ee93fa

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