Install
$python -m venv venv
$source venv/bin/activate
# On Windows, `venv\Scripts\activate`
$pip install lila-framework
$lila-init
$python main.py
Built-in Tailwind CSS v4 Support
Lila includes native, top-tier integration with **Tailwind CSS v4** + **Vite** right out-of-the-box.
- Zero-Config CDN Fallback: When starting your application for the first time or if you do not want to use Node.js/Vite, Lila automatically detects the absence of
package-lock.jsoninDEBUGmode and seamlessly loads Tailwind CSS from the official Play CDN. Your styles will look gorgeous instantly without running any npm command! - Vite Hot Reload: As soon as you run
npm installand start the Vite dev server withnpm run dev, Lila automatically upgrades the styling engine to use the local high-performance Vite compiler with full Hot Module Replacement (HMR)! - Production Ready: Building your assets with
npm run buildcompiles fully optimized, minified, and hashed CSS files mapped via the production assets manifest. - Customization & Removal: If you prefer to use another CSS framework (such as Lila CSS or Bootstrap), simply edit your main layout base file at
resources/html/lila/base.htmland 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