Skip to main content

Opinionless ASGI Framework 🙌

Project description

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

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

asgify-0.3.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

asgify-0.3.0-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file asgify-0.3.0.tar.gz.

File metadata

  • Download URL: asgify-0.3.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for asgify-0.3.0.tar.gz
Algorithm Hash digest
SHA256 7084edb92b4354c84008af000079232542ab766de2a34980814094b5906ddd23
MD5 3166ebe49a8ca69093eea804c4ce8ea5
BLAKE2b-256 cdbc954786c5706854e1682cc84fdb82a878e98bc3b12dbfaffb25f3d8cf56f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for asgify-0.3.0.tar.gz:

Publisher: python-publish.yml on aprilahijriyan/asgify

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asgify-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: asgify-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for asgify-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5900a60a79e84957179fe7fb3053cce23294cbc70c7f82665e34282c81facd65
MD5 5045d86a6311b2b2b4335464d39ed80c
BLAKE2b-256 ea0abb046c766411b8c93ddfb7bcd812b83258916d0ac835ea03c1e550a15797

See more details on using hashes here.

Provenance

The following attestation bundles were made for asgify-0.3.0-py3-none-any.whl:

Publisher: python-publish.yml on aprilahijriyan/asgify

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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