Install
$python -m venv venv
$source venv/bin/activate
# On Windows, `venv\Scripts\activate`
$pip install lila-framework
$lila-init
$python main.py
Zero-Dependency CDN Style Delivery
Lila includes a zero-dependency, build-free styling system right out-of-the-box.
- Google Fonts & Play CDN: By default, Lila loads the premium fonts Outfit and Inter alongside the official Tailwind CSS Play CDN dynamically in the browser. You do not need to install Node.js, Vite, or any npm dependencies.
- Custom Component Layer: The styling engine automatically injects the Lila design system components (such as cards, premium inputs, buttons, and layouts) with complete support for light and dark modes natively.
- Customization & Removal: If you prefer to use another CSS framework (such as Bootstrap or pure CSS), simply edit your main layout base file at
resources/html/lila/base.jinjaand change or remove the{{ asset('css/tailwind.css') | safe }}call!
️ Application Configuration
Purpose: Configure and start the application. main.py is the main entry point where the application is configured and initialized.
Production Configuration Caching (`config_cache.py`)
Lila is built with maximum performance in mind. Reading from a `.env` file on every request is a known disk I/O bottleneck in python web applications. To eliminate this, Lila features an intelligent, automated config caching mechanism:
- How it works: In production mode (when `DEBUG=False` in your `.env`), Lila reads the environment variables from `.env` once and compiles them into a static Python file named
config_cache.pyinside your `app/` folder. - High-Speed Imports: On subsequent requests/startups, Lila completely bypasses the `.env` disk reader and directly imports
app.config_cacheat compiled CPython speeds. - Smart Invalidation: Lila automatically detects if your `.env` file has been modified since the cache was generated by comparing their file modification times, automatically regenerating the cache file on-the-fly when changes are detected.
- Development Friendly: When `DEBUG=True`, the caching system is completely disabled so you always see your configuration changes instantly without having to clear any cache.
main.py Explanation
from lila.core.app import App
from app.routes.routes import routes
from app.routes.api import routes as api_routes
from lila.core.middleware import Middleware
from app.config import PORT, HOST, DEBUG,JIT
from app.middlewares.security import (
LoggingMiddleware,
SecurityHeadersMiddleware,
SecurityShieldMiddleware,
RateLimitMiddleware,
ErrorHandlerMiddleware,
)
from lila.core.logger import delete_old_logs
import itertools
import uvicorn
import asyncio
import os
# English: Combining application and API routes into a single list.
# Español: Combinando las rutas de la aplicación y la API en una única lista.
all_routes = list(itertools.chain(routes, api_routes))
#English : Marker for the api routes in main.py (also used by scaffold generator)
#Español: Marcardor para añadir automaticamente rutas api en main.py (también usado por generador de scaffold)
# api_marker
#English : Marker for the auth routes in main.py
#Español: Marcardor para añadir automaticamente rutas auth en main.py
# auth_marker
# English: Marker for the admin routes in main.py.
# Español: Marcador para las rutas de administrador en main.py.
# admin_marker
cors = None
# English: CORS usage example
# Español : Ejemplo de utilización de CORS
# cors={
# "origin": ["*"],
# "allow_credentials" : True,
# "allow_methods":["*"],
# "allow_headers": ["*"]
# }
# app = App(debug=True, routes=all_routes,cors=cors)
#English : Example middlewares with logger,security,ip rate limit ,error handler,Xss
#Español : Ejemplo de middlewares con logger, security,ip rate limit,error hanlder, Xss
# middlewares = [
# Middleware(LoggingMiddleware),
# Middleware(SecurityHeadersMiddleware),
# Middleware(SecurityShieldMiddleware),
# Middleware(RateLimitMiddleware),
# Middleware(ErrorHandlerMiddleware)
# ]
middlewares = [
Middleware(ErrorHandlerMiddleware)
]
# English: Initializing the application with debugging enabled and the combined routes.
# Español: Inicializando la aplicación con la depuración activada y las rutas combinadas.
app = App(debug=DEBUG, routes=all_routes, cors=cors, middleware=middlewares, on_startup=[delete_old_logs])
def main():
# English: Starting the Uvicorn server with the application instance.
# Español: Iniciando el servidor Uvicorn con la instancia de la aplicación.
uvicorn.run("main:app", host=HOST, port=PORT, reload=DEBUG)
if __name__ == "__main__":
try:
if JIT:
os.environ["PYTHON_JIT"] = "1"
main()
except KeyboardInterrupt:
print("Shutting down the application...")
pass