Skip to content

NexiosAsync Python Web Framework

Nexios is a fast, minimalist Python framework for building async APIs with clean architecture, zero boilerplate, and a Pythonic feel.

Nexios

Getting Started

Install Nexios using pip:

sh
pip install nexios

Create a basic application:

python
from nexios import NexiosApp

app = NexiosApp()

@app.get("/")
async def index(request, response):
    return response.json({
        "message": "Welcome to Nexios!"
    })

@app.get("/items/{item_id:int}")
async def get_item(request, response):
    item_id = request.path_params.item_id
    return response.json({
        "id": item_id,
        "name": f"Item {item_id}"
    })

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="127.0.0.1", port=8000)

Key Features

Type-Safe Routing

python
@app.get("/users/{user_id:int}/posts/{post_id:uuid}")
async def get_user_post(request, response):
    user_id = request.path_params.user_id  # Automatically converted to int
    post_id = request.path_params.post_id  # Automatically converted to UUID
    return response.json({"user_id": user_id, "post_id": post_id})

WebSocket Support

python
@app.ws_route("/ws")
async def websocket_endpoint(websocket):
    await websocket.accept()
    try:
        while True:
            data = await websocket.receive_json()
            await websocket.send_json({"message": f"Received: {data}"})
    except WebSocketDisconnect:
        print("Client disconnected")

Middleware System

python
from nexios.middlewares import BaseMiddleware

class LoggingMiddleware(BaseMiddleware):
    async def __call__(self, request, response, call_next):
        print(f"Request to {request.url}")
        response = await call_next()
        print(f"Response status: {response.status_code}")
        return response

app.add_middleware(LoggingMiddleware())

Dependency Injection

python
from nexios import Depend

async def get_current_user(request):
    user_id = request.headers.get("X-User-Id")
    return await fetch_user(user_id)

@app.get("/profile")
async def profile(request, response, user=Depend(get_current_user)):
    return response.json(user.to_dict())
py
from NexiosApp()

app = NexiosApp

@app.get("/")
async def index(request, response):

  return {"message" : "Nexios , Fast Async , Minimal"}