Pulya
Tiny web framework based on msgspec and dependency-injector with a focus on performance and new python features like free-threading / nogil
Install / Use
/learn @romantolkachyov/PulyaREADME
<p align="center"><b>pulya</b> is a tiny python web framework focused on performance and new python features.</p>
<div style="text-align: center;">
<img src="/logos/horizontal-2.png">
</div>
<p></p>
Features:
- msgspec for validation and serialization
- dependency-injector as the main and the only DI framework
- RSGI and first-class granian support
- free-threading / no-gil python support
- zero-cost routing with python-matchit
Minimal supported python version 3.12.
Quick start
Installation:
pip install pulya
Simple application (main.py:
from typing import Any
from pulya import Pulya, RequestContainer
from dependency_injector import containers, providers
class Container(containers.DeclarativeContainer):
# Wiring configuration.
# RequestContainer will also use this wiring config.
wiring_config = containers.WiringConfiguration(
modules=[__name__],
)
# Specially named dependency providing access to active request.
# Must have exact name `request`, actual container will be injected
# by the application on startup.
request = providers.Container(RequestContainer)
app = Pulya(Container)
@app.get("/")
def home() -> dict[str, Any]:
return {"success": True}
Run using granian:
granian --interface rsgi main:app
Check:
curl http://localhost:8000/
Performance
In the actual state with a lack of some features, pulya outperforms all frameworks available in https://github.com/romantolkachyov/python-framework-benchmarks benchmark.
Benchmark Results using wrk with 12 threads
and 400 connections for 10s
┏━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Framework ┃ Requests/sec ┃ Transfer/sec ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
│ pulya │ 138690.14 │ 21.96MB │
│ starlette │ 129946.20 │ 18.84MB │
│ litestar │ 111868.04 │ 18.35MB │
│ sanic │ 105941.45 │ 17.28MB │
│ fastapi │ 93575.14 │ 13.56MB │
│ quart │ 67418.17 │ 9.84MB │
│ robyn │ 53397.80 │ 6.62MB │
│ flask │ 2232.87 │ 388.25KB │
└───────────┴──────────────┴──────────────┘
wrk -t12 -c400 -d10s -s wrk_script.lua http://localhost:8000/echo
Running 10s test @ http://localhost:8000/echo
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 5.40ms 8.58ms 128.34ms 89.02%
Req/Sec 11.72k 1.55k 55.05k 92.67%
1400773 requests in 10.10s, 221.76MB read
Requests/sec: 138690.14
Transfer/sec: 21.96MB
