/phial

A simple async web framework for Python 3

Primary LanguagePythonMIT LicenseMIT

Phial - A Simple ASGI Framework

Phial is an async micro-framework for the web written in Python. Created as an educational project, I wanted a better understanding of how async programming works in Python. Additionally, I wanted a chance to work closer to the actual HTTP protocol and understand more about the web.

I took heavy inspiration from the Bottle framework, in both philosophy and code. Disregarding tests, the source code for Phial fits in one file and can easily be read in an afternoon.

Using Phial

Note: Phial isn't for use in production! I created Phial to understand more about the HTTP protocol. If you need an async microframework, try Starlette

Creating a "Hello, world!" in Phial is simple, it should look familiar if you have ever used Flask, Bottle, or another micro-framework:

# hello.py
from phial import Router, Phial, Response

ROUTER = Router()

@ROUTER.route(r'^/$')
async def hello(request):
    return Response("Hello World", content_type="text/plain")

app = Phial(router=ROUTER)

Run this file hello.py using an ASGI server like Uvicorn:

uvicorn hello:app

Running Tests

After cloning the repo, install the development packages from requirements.dev.txt:

pip install -r requirements.dev.txt

Tests are run with the pytest command and framework.

License

  • MIT License