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.3.tar.gz (21.9 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.3-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: asgikit-0.16.3.tar.gz
  • Upload date:
  • Size: 21.9 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.3.tar.gz
Algorithm Hash digest
SHA256 4ee52ee5847432227d65c03f8474dedde1a8b165e3659e60801e330dfa2ec17a
MD5 f23b7fef979d00b79561e3606ebff8ca
BLAKE2b-256 9ad0a77c740817c598ae2df8a2b642498018ca8706c409bcfc69edec077ecfaf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asgikit-0.16.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b2677e447089ef50e8d4d1fd1df89eb6c7317ce820254872e16e3c9c082c5cef
MD5 0a66dfb542de85fb66ca44e6d6335ca7
BLAKE2b-256 e600d1c57a3255909c76d1144b0459ed476d64de6a0f3058e3ff8f06805ecbd2

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