# Lilya
<p align="center">
<a href="https://lilya.dev"><img src="https://res.cloudinary.com/dymmond/image/upload/v1707501404/lilya/logo_quiotd.png" alt='Lilya'></a>
</p>
<p align="center">
<em>🚀 Yet another ASGI toolkit that delivers. 🚀</em>
</p>
<p align="center">
<a href="https://github.com/dymmond/lilya/actions/workflows/test-suite.yml/badge.svg?event=push&branch=main" target="_blank">
<img src="https://github.com/dymmond/lilya/actions/workflows/test-suite.yml/badge.svg?event=push&branch=main" alt="Test Suite">
</a>
<a href="https://pypi.org/project/lilya" target="_blank">
<img src="https://img.shields.io/pypi/v/lilya?color=%2334D058&label=pypi%20package" alt="Package version">
</a>
<a href="https://pypi.org/project/lilya" target="_blank">
<img src="https://img.shields.io/pypi/pyversions/lilya.svg?color=%2334D058" alt="Supported Python versions">
</a>
</p>
---
**Documentation**: [https://lilya.dev](https://lilya.dev) 📚
**Source Code**: [https://github.com/dymmond/lilya](https://github.com/dymmond/lilya)
**The official supported version is always the latest released**.
---
## Motivation
In the world of ASGI, alternatives are always great to have and no tool serves it all.
Lilya, coming from the great inspirations of the ones who paved the way, its a more simple, accurate
fast and easy to use Python toolkit/framework that aims for simplicity.
A lot of times you won't be needing a fully fledge Python web framework as it can be overwhelming
for some simple tasks, instead you would prefer a simple ASGI toolkit that helps you designing
production ready, fast, elegant, maintainable and modular applications.
This is where Lilya places itself.
Almost no hard dependencies, 100% pythonic, fully typed and ready for production.
## What does it bring?
Lilya comes bearing fruits.
* A lightweight ASGI toolkit/framework.
* Support for HTTP/WebSocket.
* Tasks (in ASGI known as background tasks).
* Lifespan events (on_startup/on_shutdown and lifespan).
* Native permission system.
* Middlewares (Compressor, CSRF, Session, CORS...).
* A native and **optional** [client](https://lilya.dev/lilya-cli).
* **Directive management control system** for any custom scripts to run inside the application.
* Little hard dependencies.
* Compatibility with `trio` and `asyncio`.
* Dynamic routing system with the help of the native **Include** and minimum boilerplate.
* Native settings system. No more bloated instances.
* Native dependency injection that is extremely scalable, clean and fast.
* Dynamic, native and fast custom serializers.
## Installation
If you want just the toolkit/framework.
```shell
$ pip install lilya
```
If you want the Lilya client (for scaffolds, and other useful tools)
```shell
$ pip install lilya[standard]
```
If you wish to use to extra functionalities such as the **shell** or **directives**
(project scaffold generation to speed up).
```shell
$ pip install lilya[cli,ipython] # for ipython shell
$ pip install lilya[cli,ptpython] # for ptpython shell
```
You can learn more about the [client](https://lilya.dev/directives/discovery) in the documentation.
Or if you want to install everything that will allow you to use all the resources of Lilya, such
as some specific middlewares.
```shell
$ pip install lilya[all]
```
### Additional
You would want to install an ASGI server such as [uvicorn](https://www.uvicorn.org/) or
[hypercorn](https://pgjones.gitlab.io/hypercorn/) as well.
## Quickstart
If you are familiar with other Python frameworks and toolkits, Lilya provides you with the same
feeling.
A Lilya also uses a [native settings system](https://lilya.dev/settings) which is something that can be extremely useful
for any application.
### The normal way
```python
from lilya.apps import Lilya
from lilya.requests import Request
from lilya.responses import Ok
from lilya.routing import Path
async def welcome():
return Ok({"message": "Welcome to Lilya"})
async def user(user: str):
return Ok({"message": f"Welcome to Lilya, {user}"})
async def user_in_request(request: Request):
user = request.path_params["user"]
return Ok({"message": f"Welcome to Lilya, {user}"})
app = Lilya(
routes=[
Path("/{user}", user),
Path("/in-request/{user}", user_in_request),
Path("/", welcome),
]
)
```
### Using Lilya to decorate
```python
from lilya.apps import Lilya
from lilya.requests import Request
from lilya.responses import Ok
app = Lilya()
@app.get("/")
async def welcome():
return Ok({"message": "Welcome to Lilya"})
@app.get("/{user}")
async def user(user: str):
return Ok({"message": f"Welcome to Lilya, {user}"})
@app.get("/in-request/{user}")
async def user_in_request(request: Request):
user = request.path_params["user"]
return Ok({"message": f"Welcome to Lilya, {user}"})
```
Is this simple. Although there is a lot to unwrap here. Did you notice the path `/{user}` not only
does not require a `request` to be declared and instead, receives a `user: str`?
Well, Lilya does a lot of internal magic for you. If you don't declare a `request`, that is not a
problem as it will only pass it if its there.
If you have the path parameter declared in the function handler as well, Lilya will automatically
search for the parameters declared and match them against the path parameters declared in the `Path`
and inject them for you.
Pretty cool, right? This is just scratching the surface.
## Definitions
Lilya can be considered a framework or a toolkit and the reasoning for it its because each component
such as middlewares, permissions, Path, Router... can be seen as an independent ASGI application.
In other words, you can build a [middleware](https://lilya.dev/middleware) or a [permission](https://lilya.dev/permissions) and
share those with any other existing ASGI framework out there, meaning, you could design a Lilya
application, middlewares, permissions and any other component and re-use them in [Esmerald][esmerald]
or [FastAPI][fastapi] or any other, really.
**Lilya is not a full-fledge framework like [Esmerald][esmerald] or [FastAPI][fastapi], instead**
**its a lightweight toolkit/framework that can be used to build those as well as working on its own.**
**Example**
```python
from lilya.exceptions import PermissionDenied
from lilya.protocols.permissions import PermissionProtocol
from lilya.requests import Request
from lilya.types import ASGIApp, Receive, Scope, Send
class AllowAccess(PermissionProtocol):
def __init__(self, app: ASGIApp, *args, **kwargs):
super().__init__(app, *args, **kwargs)
self.app = app
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
request = Request(scope=scope, receive=receive, send=send)
if "allow-admin" in request.headers:
await self.app(scope, receive, send)
return
raise PermissionDenied()
```
## Run the application
To run the application from the example.
```shell
$ uvicorn myapp:app
INFO: Started server process [140552]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```
## Powered by
Worth mentioning who is helping us.
**JetBrains**
[](https://jb.gg/OpenSourceSupport)
[esmerald]: https://lilya.dev/esmerald
[fastapi]: https://fastapi.tiangolo.com
Raw data
{
"_id": null,
"home_page": null,
"name": "lilya",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "ai, aiohttp, anyio, aop, api, api-key, api-server, asgi, async, async-framework, asyncio, authentication, auto-documentation, autodoc, backend, background-tasks, caching, cloud-native, concurrency, controllers, cors, csrf, data-validation, dependency-injection, developer-friendly, django, dymmond, esmerald, event-driven, exception-handling, fastapi, flask, graphql, graphql-support, high-performance, http, hypercorn, interceptors, json, jwt, lilya, machine-learning, microservices, middlewares, ml, modern-python, non-blocking, oauth2, observables, openapi, openapi-schema, openapi3, pydantic, python, python-types, python3, quart, ravyn, ravyn-framework, redoc, request-handling, response-models, rest, rest-api, routing, security, serialization, sse, starlette, streaming, swagger, type-hints, typed-api, uvicorn, validation, web, web-framework, websocket, websocket-server",
"author": null,
"author_email": "Tiago Silva <tiago.arasilva@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/fe/60/8d3f3a1928e07461f490d5683bc14e30ea274a86ac9804a02eb2a442ecee/lilya-0.22.6.tar.gz",
"platform": null,
"description": "# Lilya\n\n<p align=\"center\">\n <a href=\"https://lilya.dev\"><img src=\"https://res.cloudinary.com/dymmond/image/upload/v1707501404/lilya/logo_quiotd.png\" alt='Lilya'></a>\n</p>\n\n<p align=\"center\">\n <em>\ud83d\ude80 Yet another ASGI toolkit that delivers. \ud83d\ude80</em>\n</p>\n\n<p align=\"center\">\n<a href=\"https://github.com/dymmond/lilya/actions/workflows/test-suite.yml/badge.svg?event=push&branch=main\" target=\"_blank\">\n <img src=\"https://github.com/dymmond/lilya/actions/workflows/test-suite.yml/badge.svg?event=push&branch=main\" alt=\"Test Suite\">\n</a>\n\n<a href=\"https://pypi.org/project/lilya\" target=\"_blank\">\n <img src=\"https://img.shields.io/pypi/v/lilya?color=%2334D058&label=pypi%20package\" alt=\"Package version\">\n</a>\n\n<a href=\"https://pypi.org/project/lilya\" target=\"_blank\">\n <img src=\"https://img.shields.io/pypi/pyversions/lilya.svg?color=%2334D058\" alt=\"Supported Python versions\">\n</a>\n</p>\n\n---\n\n**Documentation**: [https://lilya.dev](https://lilya.dev) \ud83d\udcda\n\n**Source Code**: [https://github.com/dymmond/lilya](https://github.com/dymmond/lilya)\n\n**The official supported version is always the latest released**.\n\n---\n\n## Motivation\n\nIn the world of ASGI, alternatives are always great to have and no tool serves it all.\nLilya, coming from the great inspirations of the ones who paved the way, its a more simple, accurate\nfast and easy to use Python toolkit/framework that aims for simplicity.\n\nA lot of times you won't be needing a fully fledge Python web framework as it can be overwhelming\nfor some simple tasks, instead you would prefer a simple ASGI toolkit that helps you designing\nproduction ready, fast, elegant, maintainable and modular applications.\n\nThis is where Lilya places itself.\n\nAlmost no hard dependencies, 100% pythonic, fully typed and ready for production.\n\n## What does it bring?\n\nLilya comes bearing fruits.\n\n* A lightweight ASGI toolkit/framework.\n* Support for HTTP/WebSocket.\n* Tasks (in ASGI known as background tasks).\n* Lifespan events (on_startup/on_shutdown and lifespan).\n* Native permission system.\n* Middlewares (Compressor, CSRF, Session, CORS...).\n* A native and **optional** [client](https://lilya.dev/lilya-cli).\n* **Directive management control system** for any custom scripts to run inside the application.\n* Little hard dependencies.\n* Compatibility with `trio` and `asyncio`.\n* Dynamic routing system with the help of the native **Include** and minimum boilerplate.\n* Native settings system. No more bloated instances.\n* Native dependency injection that is extremely scalable, clean and fast.\n* Dynamic, native and fast custom serializers.\n\n## Installation\n\nIf you want just the toolkit/framework.\n\n```shell\n$ pip install lilya\n```\n\nIf you want the Lilya client (for scaffolds, and other useful tools)\n\n```shell\n$ pip install lilya[standard]\n```\n\nIf you wish to use to extra functionalities such as the **shell** or **directives**\n(project scaffold generation to speed up).\n\n```shell\n$ pip install lilya[cli,ipython] # for ipython shell\n$ pip install lilya[cli,ptpython] # for ptpython shell\n```\n\nYou can learn more about the [client](https://lilya.dev/directives/discovery) in the documentation.\n\nOr if you want to install everything that will allow you to use all the resources of Lilya, such\nas some specific middlewares.\n\n```shell\n$ pip install lilya[all]\n```\n\n### Additional\n\nYou would want to install an ASGI server such as [uvicorn](https://www.uvicorn.org/) or\n[hypercorn](https://pgjones.gitlab.io/hypercorn/) as well.\n\n## Quickstart\n\nIf you are familiar with other Python frameworks and toolkits, Lilya provides you with the same\nfeeling.\n\nA Lilya also uses a [native settings system](https://lilya.dev/settings) which is something that can be extremely useful\nfor any application.\n\n### The normal way\n\n```python\nfrom lilya.apps import Lilya\nfrom lilya.requests import Request\nfrom lilya.responses import Ok\nfrom lilya.routing import Path\n\n\nasync def welcome():\n return Ok({\"message\": \"Welcome to Lilya\"})\n\n\nasync def user(user: str):\n return Ok({\"message\": f\"Welcome to Lilya, {user}\"})\n\n\nasync def user_in_request(request: Request):\n user = request.path_params[\"user\"]\n return Ok({\"message\": f\"Welcome to Lilya, {user}\"})\n\n\napp = Lilya(\n routes=[\n Path(\"/{user}\", user),\n Path(\"/in-request/{user}\", user_in_request),\n Path(\"/\", welcome),\n ]\n)\n```\n\n### Using Lilya to decorate\n\n```python\nfrom lilya.apps import Lilya\nfrom lilya.requests import Request\nfrom lilya.responses import Ok\n\napp = Lilya()\n\n\n@app.get(\"/\")\nasync def welcome():\n return Ok({\"message\": \"Welcome to Lilya\"})\n\n\n@app.get(\"/{user}\")\nasync def user(user: str):\n return Ok({\"message\": f\"Welcome to Lilya, {user}\"})\n\n\n@app.get(\"/in-request/{user}\")\nasync def user_in_request(request: Request):\n user = request.path_params[\"user\"]\n return Ok({\"message\": f\"Welcome to Lilya, {user}\"})\n```\n\nIs this simple. Although there is a lot to unwrap here. Did you notice the path `/{user}` not only\ndoes not require a `request` to be declared and instead, receives a `user: str`?\n\nWell, Lilya does a lot of internal magic for you. If you don't declare a `request`, that is not a\nproblem as it will only pass it if its there.\n\nIf you have the path parameter declared in the function handler as well, Lilya will automatically\nsearch for the parameters declared and match them against the path parameters declared in the `Path`\nand inject them for you.\n\nPretty cool, right? This is just scratching the surface.\n\n## Definitions\n\nLilya can be considered a framework or a toolkit and the reasoning for it its because each component\nsuch as middlewares, permissions, Path, Router... can be seen as an independent ASGI application.\n\nIn other words, you can build a [middleware](https://lilya.dev/middleware) or a [permission](https://lilya.dev/permissions) and\nshare those with any other existing ASGI framework out there, meaning, you could design a Lilya\napplication, middlewares, permissions and any other component and re-use them in [Esmerald][esmerald]\nor [FastAPI][fastapi] or any other, really.\n\n**Lilya is not a full-fledge framework like [Esmerald][esmerald] or [FastAPI][fastapi], instead**\n**its a lightweight toolkit/framework that can be used to build those as well as working on its own.**\n\n**Example**\n\n```python\nfrom lilya.exceptions import PermissionDenied\nfrom lilya.protocols.permissions import PermissionProtocol\nfrom lilya.requests import Request\nfrom lilya.types import ASGIApp, Receive, Scope, Send\n\n\nclass AllowAccess(PermissionProtocol):\n def __init__(self, app: ASGIApp, *args, **kwargs):\n super().__init__(app, *args, **kwargs)\n self.app = app\n\n async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:\n request = Request(scope=scope, receive=receive, send=send)\n\n if \"allow-admin\" in request.headers:\n await self.app(scope, receive, send)\n return\n raise PermissionDenied()\n```\n\n## Run the application\n\nTo run the application from the example.\n\n```shell\n$ uvicorn myapp:app\nINFO: Started server process [140552]\nINFO: Waiting for application startup.\nINFO: Application startup complete.\nINFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)\n```\n\n## Powered by\n\nWorth mentioning who is helping us.\n\n**JetBrains**\n\n[](https://jb.gg/OpenSourceSupport)\n\n[esmerald]: https://lilya.dev/esmerald\n[fastapi]: https://fastapi.tiangolo.com\n",
"bugtrack_url": null,
"license": null,
"summary": "Yet another ASGI toolkit that delivers",
"version": "0.22.6",
"project_urls": {
"Changelog": "https://lilya.dev/release-notes/",
"Documentation": "https://lilya.dev",
"Funding": "https://github.com/sponsors/tarsil",
"Homepage": "https://github.com/dymmond/lilya",
"Source": "https://github.com/dymmond/lilya"
},
"split_keywords": [
"ai",
" aiohttp",
" anyio",
" aop",
" api",
" api-key",
" api-server",
" asgi",
" async",
" async-framework",
" asyncio",
" authentication",
" auto-documentation",
" autodoc",
" backend",
" background-tasks",
" caching",
" cloud-native",
" concurrency",
" controllers",
" cors",
" csrf",
" data-validation",
" dependency-injection",
" developer-friendly",
" django",
" dymmond",
" esmerald",
" event-driven",
" exception-handling",
" fastapi",
" flask",
" graphql",
" graphql-support",
" high-performance",
" http",
" hypercorn",
" interceptors",
" json",
" jwt",
" lilya",
" machine-learning",
" microservices",
" middlewares",
" ml",
" modern-python",
" non-blocking",
" oauth2",
" observables",
" openapi",
" openapi-schema",
" openapi3",
" pydantic",
" python",
" python-types",
" python3",
" quart",
" ravyn",
" ravyn-framework",
" redoc",
" request-handling",
" response-models",
" rest",
" rest-api",
" routing",
" security",
" serialization",
" sse",
" starlette",
" streaming",
" swagger",
" type-hints",
" typed-api",
" uvicorn",
" validation",
" web",
" web-framework",
" websocket",
" websocket-server"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "324a4016274a792c4b8c813a2f36a8e90b832c5d9015baefeb78ab7479bc3ff2",
"md5": "3b0a0ca0ecf30c0532c013f14702764a",
"sha256": "a44445715a0f5e98b269a0bdcf1db2f3c747e4c970e159a1db4e4c60b77f8e84"
},
"downloads": -1,
"filename": "lilya-0.22.6-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3b0a0ca0ecf30c0532c013f14702764a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 363910,
"upload_time": "2025-10-22T09:21:38",
"upload_time_iso_8601": "2025-10-22T09:21:38.110979Z",
"url": "https://files.pythonhosted.org/packages/32/4a/4016274a792c4b8c813a2f36a8e90b832c5d9015baefeb78ab7479bc3ff2/lilya-0.22.6-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "fe608d3f3a1928e07461f490d5683bc14e30ea274a86ac9804a02eb2a442ecee",
"md5": "12c667616cb4e498714c7d9270edca2c",
"sha256": "ba3dfc96d5dda61e5cd55995abc378926a2bbad8fb0565ccbd5178732c861a15"
},
"downloads": -1,
"filename": "lilya-0.22.6.tar.gz",
"has_sig": false,
"md5_digest": "12c667616cb4e498714c7d9270edca2c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 257359,
"upload_time": "2025-10-22T09:21:39",
"upload_time_iso_8601": "2025-10-22T09:21:39.687804Z",
"url": "https://files.pythonhosted.org/packages/fe/60/8d3f3a1928e07461f490d5683bc14e30ea274a86ac9804a02eb2a442ecee/lilya-0.22.6.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-22 09:21:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sponsors",
"github_project": "tarsil",
"github_not_found": true,
"lcname": "lilya"
}