Skip to main content

Opinionless ASGI Framework 🙌

Project description

asgify

Opinionless ASGI Framework 🙌

📦 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

Async-First Architecture

  • Built from the ground up for async/await
  • Non-blocking I/O for maximum performance

🎯 Context Classes That Rock

# 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 and fast-query-parsers
  • 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.1.0.tar.gz (12.0 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.1.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for asgify-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fdc618bdde60fcbcaa047468bc83c25f67a96f32ba5abc7fcad894d84fcbbf53
MD5 ee41b57a9f2491cec25d811f1b012dca
BLAKE2b-256 07ca5b57a08e149b0272541bb61af31896422c14aa17195b16a9e7864030cce7

See more details on using hashes here.

Provenance

The following attestation bundles were made for asgify-0.1.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: asgify-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f6ae2427348c0e867c2b855e66d5d6dc6bafca458d231fbe299d553f03dec59
MD5 9495b6d17d572bfaa12f363983111390
BLAKE2b-256 2e4b176ad1043c3152bd51d88098932b8eb6c870880ce2c155403b07acca1e45

See more details on using hashes here.

Provenance

The following attestation bundles were made for asgify-0.1.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