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

๐Ÿ˜€ Quick Start โ€‹

bash
# Create virtual environment
python -m venv venv
source venv/bin/activate  # or `venv\Scripts\activate` on Windows

# Install Nexios
pip install nexios
python
from nexios import NexiosApp

app = NexiosApp()

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

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="127.0.0.1", port=8000)
python
from nexios import NexiosApp, MakeConfig

config = MakeConfig({
    "debug": True,
    "cors_enabled": True,
    "allowed_hosts": ["localhost", "example.com"]
})

app = NexiosApp(
    config=config,
    title="My API",
    version="1.0.0"
)

๐ŸŽ‰ Quick Development

Use nexios run --reload for automatic reloading during development. ๐Ÿ”„

๐Ÿš€ Key Features โ€‹

Simple and easy Routing โ€‹

python
from nexios import NexiosApp

app = NexiosApp()

@app.get("/users/{user_id:int}")
async def get_user(request, response, user_id: int):
    return response.json({"id": user_id}) # user_id is automatically converted to int
python
from pydantic import BaseModel

class User(BaseModel):
    id: int
    name: str
    email: str

@app.post("/users")
async def create_user(request, response):
    data = await request.json
    user = User(**data)  # Automatic validation
    return response.json(user.dict())
python
from nexios import NexiosApp
from uuid import UUID

app = NexiosApp()

@app.get("/users/{user_id:int}/posts/{post_id:uuid}")
async def get_user_post(request, response):
    user_id = request.path_params.user_id
    post_id = request.path_params.post_id
    return response.json({
        "user_id": user_id,
        "post_id": str(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({"echo": data})
    except WebSocketDisconnect:
        print("Client disconnected")
python
from nexios.websockets import Channel

@app.ws_route("/chat/{room_id}")
async def chat_room(websocket, room_id: str):
    channel = Channel(f"room:{room_id}")
    await channel.connect(websocket)

    try:
        while True:
            message = await websocket.receive_json()
            await channel.broadcast(message)
    except WebSocketDisconnect:
        await channel.disconnect(websocket)

๐Ÿ› ๏ธ Middleware System โ€‹

python

async def basic_middleware(request, response, call_next):
  print("do something before handler")
  await call_next()
  print("do something after handler")


app.add_middleware(basic_middleware())
python
from nexios.middleware import BaseMiddleware
class BasicMiddleware(BaseMiddleware):

  async def process_request(request, response, call_next):
    print("do something before handler")
    await call_next()
  async def process_response(request, response, call_next):
    print("do something after handler")
python
from nexios.auth.middleware import AuthenticationMiddleware
from nexios.auth.backends.jwt import JWTAuthBackend
from nexios.auth.decorator import auth


auth = AuthenticationMiddleware(
    backend = JWTAuthBackend(),
    user_model = UserModel
)

app.add_middleware(auth)

@app.get("/protected")
@auth(["jwt"])
async def protected(request, response):
    user = request.user
    return response.json({"message": f"Hello {user.username}"})

Dependency Injection โ€‹

python
from nexios import Depend

# Both generator and async generator dependencies are supported.
# Cleanup in the finally block is always run after the request.

def get_db():
    db = connect()
    try:
        yield db
    finally:
        db.close()

async def get_async_db():
    db = await async_connect()
    try:
        yield db
    finally:
        await db.close()

@app.get("/users")
async def list_users(
    request,
    response,
    db=Depend(get_db)  # or db=Depend(get_async_db)
):
    users = await db.query("SELECT * FROM users")
    return response.json(users)
python
from nexios.dependecies import Context
async def get_current_user(
    ctx = Context()
):  request = ctx.request
    token = request.headers.get("Authorization")
    return await auth.get_user(token)

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

Production Ready

Nexios is built for production use with:

  • Comprehensive error handling
  • Security best practices
  • Performance optimizations
  • Monitoring support

Python Version

Nexios requires Python 3.9+ for:

  • Native async/await
  • Type hints
  • Modern language features

Nexios CLI โ€‹

Nexios comes with a powerful command-line interface that makes development and deployment a breeze. The Nexios CLI is your primary tool for managing Nexios applications throughout their lifecycle.

Key Features โ€‹

  • Project Scaffolding: Quickly bootstrap new projects with a modern structure
  • Development Server: Run and test your application with hot reload
  • Code Generation: Generate components, models, and controllers with a single command
  • Database Tools: Handle migrations and database operations
  • Testing: Run tests with detailed reporting
  • Build & Deploy: Prepare and deploy your application

Basic Usage โ€‹

bash
# Create a new Nexios project
nexios new my-awesome-app

Important Note

Do not use the Nexios CLI if you are still learning Python.

For complete documentation on using the Nexios CLI, check out the CLI Documentation.

๐Ÿง˜ The Zen of Nexios โ€‹

Nexios embraces the Zen of Python, particularly the second principle: "Explicit is better than implicit." Here's how:

  • Explicit Routing ๐Ÿ›ฃ๏ธ: Every route is explicitly defined, making it clear what endpoints are available
  • Dependency Injection ๐Ÿ’‰: Dependencies are explicitly declared and injected
  • Type Annotations ๐Ÿ“: Full support for Python's type hints throughout the framework
  • Configuration Over Convention โš™๏ธ: While we provide sensible defaults, we don't hide important behavior behind "magic"

๐Ÿš€ Key Features โ€‹

Performance Optimized โšก โ€‹

  • Designed for blazing-fast, production-ready performance ๐Ÿš€
  • Async-first architecture for handling thousands of concurrent connections ๐ŸŒŠ
  • Middleware system for fine-grained performance optimization ๐Ÿ› ๏ธ

Developer Experience ๐Ÿ’ป โ€‹

  • Automatic API documentation with OpenAPI/Swagger ๐Ÿ“–
  • Built-in testing utilities ๐Ÿงช
  • Detailed error messages and stack traces ๐Ÿ“ข
  • Interactive API documentation at /docs ๐ŸŒ

Extensibility ๐Ÿ”Œ โ€‹

  • Plugin system for adding custom functionality ๐Ÿงฉ
  • Support for WebSockets and HTTP/2 ๐Ÿ“ก
  • Custom middleware support ๐Ÿ› ๏ธ
  • Background tasks and scheduled jobs โฐ

Security First ๐Ÿ” โ€‹

  • Built-in CSRF protection ๐Ÿ›ก๏ธ
  • JWT Authentication ๐Ÿ†”
  • CORS middleware ๐ŸŒ
  • Secure by default configurations โš™๏ธ