Skip to main content

asgify

Opinionless ASGI Framework 🙌

Lightweight API to simplify core ASGI specification

📦 Installation

Using pip

pip install asgify

Using uv (Recommended)

uv add asgify

From Source

git clone https://github.com/aprilahijriyan/asgify.git
cd asgify
pip install -e .

🚀 Showcase

HTTP Application Example

import json
from asgify.app import Asgify
from asgify.context import HTTPContext
from asgify.status import HTTP_200_OK, HTTP_201_CREATED, HTTP_404_NOT_FOUND, HTTP_STATUS_CODES


async def http_handler(ctx: HTTPContext):
    # Get path and method
    path = ctx.path
    method = ctx.method

    if path == "/" and method == "GET":
        await ctx.start(HTTP_200_OK, {"content-type": "application/json"})
        await ctx.end(json.dumps({"message": "Hello from asgify!"}).encode())

    elif path.startswith("/users/") and method == "GET":
        user_id = path.split("/users/")[-1]
        page = ctx.params.get("page", "1")

        await ctx.start(HTTP_200_OK, {"content-type": "application/json"})
        await ctx.end(
            json.dumps({"user_id": user_id, "page": page, "status": "active"}).encode()
        )

    elif path == "/api/data" and method == "POST":
        # Read JSON body
        body = b""
        async for chunk in ctx.read_body():
            body += chunk

        data = json.loads(body.decode())

        await ctx.start(HTTP_201_CREATED, {"content-type": "application/json"})
        await ctx.end(json.dumps({"created": True, "data": data}).encode())

    else:
        await ctx.start(HTTP_404_NOT_FOUND, {"content-type": "text/plain"})
        await ctx.end(HTTP_STATUS_CODES[HTTP_404_NOT_FOUND].encode())


app = Asgify(http=http_handler)

To run the HTTP server example above using uvicorn, save the code to a file (for example, showcase_http.py) and run the following command in your terminal:

uvicorn showcase_http:app

WebSocket Application Example

import json
from datetime import datetime

from asgify.app import Asgify
from asgify.context import WebSocketContext
from asgify.errors import ClientDisconnected


async def websocket_handler(ctx: WebSocketContext):
    await ctx.accept()
    await ctx.send_bytes("Welcome to asgify 🚀".encode())
    while True:
        try:
            data = await ctx.receive_text()
            print("<", data)
            reply = json.dumps({"echo": data, "timestamp": datetime.now().isoformat()})
            await ctx.send_text(reply)
            print(">", reply)
        except ClientDisconnected:
            print("disconnected with client")
            break

app = Asgify(websocket=websocket_handler)

To run the WebSocket server example above using uvicorn, save the code to a file (for example, showcase_websocket.py) and run the following command in your terminal:

uvicorn showcase_websocket:app

Testing with wscat:

❯ wscat -P -c http://localhost:8000
Connected (press CTRL+C to quit)
< Welcome to asgify 🚀
> hehehe
< {"echo": "hehehe", "timestamp": "2025-07-08T13:06:34.899579"}
> %

✨ Cool Features

🚀 Zero Overhead

  • Pure ASGI implementation with minimal dependencies
  • No magic, no hidden costs - what you write is what you get

🎯 Context Classes That Rock

The python web framework out there has the same style, but asgify is different because it uses Context to handle requests and responses!

# HTTP Context - Simple & Powerful
await ctx.start(HTTP_200_OK, {"content-type": "application/json"})
await ctx.end(json.dumps({"message": "Hello World"}).encode())

# WebSocket Context - Real-time Ready
await ctx.accept()
message = await ctx.receive_text()
await ctx.send_text(f"Echo: {message}")

🎨 Customizable Everything

  • Swap context classes for your needs
  • Custom lifespan handlers for app lifecycle
  • Full control over request/response flow

📦 Minimal Dependencies

  • Only asgiref, fast-query-parsers and multidict
  • No bloat, no surprises

🔧 Developer Experience

  • Clean, intuitive API
  • Comprehensive status codes (HTTP + WebSocket)
  • Built-in query parameter parsing
  • Application state management

Metadata

Release files for asgify 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asgify 0.3.0
File Size Uploaded Provenance Actions
asgify-0.3.0.tar.gz 12.9 kB With provenance Details for asgify-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for asgify 0.3.0
File Interpreter ABI Platform Actions
asgify-0.3.0-py3-none-any.whl Python 3 none any Details for asgify-0.3.0-py3-none-any.whl

Total release size: 25.2 kB

Release files / asgify-0.3.0.tar.gz

Download URL asgify-0.3.0.tar.gz
Size 12.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7084edb92b4354c84008af000079232542ab766de2a34980814094b5906ddd23
BLAKE2b-256 checksum
How to use checksums
cdbc954786c5706854e1682cc84fdb82a878e98bc3b12dbfaffb25f3d8cf56f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 15, 2025.

Transparency log

Release files / asgify-0.3.0-py3-none-any.whl

Download URL asgify-0.3.0-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5900a60a79e84957179fe7fb3053cce23294cbc70c7f82665e34282c81facd65
BLAKE2b-256 checksum
How to use checksums
ea0abb046c766411b8c93ddfb7bcd812b83258916d0ac835ea03c1e550a15797
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 15, 2025.

Transparency log

Security for asgify 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for asgify-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 15, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page