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.requests import Request
from asgikit.responses import Response


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

    request = Request(scope, receive, send)
    response = Response(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 response.send_json(data)

Example websocket

from asgikit.websockets 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.15.0.tar.gz (21.8 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.15.0-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: asgikit-0.15.0.tar.gz
  • Upload date:
  • Size: 21.8 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.15.0.tar.gz
Algorithm Hash digest
SHA256 9dccbd82129a2ff5d43699721df8b5d7d4c42e606f016bd0c472506928f9f958
MD5 8fea31201c4096e5579c0139614d2dd5
BLAKE2b-256 47eb484b3f843b96d14a568b1012b92a010fed363ee8e7b535d40346639ebc53

See more details on using hashes here.

File details

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

File metadata

  • Download URL: asgikit-0.15.0-py3-none-any.whl
  • Upload date:
  • Size: 17.1 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.15.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8b4cdd7b1b99adaae147fe33496de136d86adb1ec6e405c1cb4114052a42cfc
MD5 014be8c06f801ca5968f7719866dd2f1
BLAKE2b-256 a584d7dd554e1eb2f0837353734f775be1163bc6bbc89d7ff51c464b37d2a3e2

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