The Problem: FastAPI is Great, but Scaling is Hard
FastAPI is undoubtedly one of the fastest and most developer-friendly frameworks in Python. However, as projects grow into enterprise-level applications, maintaining a clean structure can become a challenge. Many developers coming from the Node.js ecosystem miss the Modular Architecture and Dependency Injection patterns of NestJS.
The Solution: Introducing FastNest
I built FastNest to bridge this gap. Itβs a progressive Python framework built on top of FastAPI that enforces a structured approach without sacrificing performance.
Key Features π
Modular System: Organize your code into isolated, reusable modules using the @Module decorator.
Powerful Dependency Injection: A built-in IoC container that manages service lifecycles and injections automatically.
Real-time Ready: Native WebSocket Gateways with event-based decorators (@SubscribeMessage).
Enterprise Patterns: Standardized interfaces for Guards (Authentication/Authorization), Interceptors, and Pipes (Validation).
π οΈ Quick Start
Want to see it in action? Here is how you can set up a modular application in seconds.
- Install FastNest Bash
pip install fastnest
- Create your first Module Python
from fastnest.core import Module, Controller, Get
@Controller('/hello')
class AppController:
@Get('/')
def get_hello(self):
return {"message": "Hello from FastNest!"}
@Module(
controllers=[AppController],
providers=[]
)
class AppModule:
pass
- Bootstrap and Run Python
from fastnest.core import FastNestFactory
from .app_module import AppModule
app = FastNestFactory.create(AppModule)
π°οΈ Real-time WebSockets
One of the most exciting features of FastNest is how it handles WebSockets. You no longer need to manage complex connection loops manually.
Python
@WebSocketGateway("/chat")
class ChatGateway(OnGatewayConnection):
async def on_connection(self, websocket: WebSocket):
await websocket.accept()
@SubscribeMessage("events")
async def handle_event(self, client: WebSocket, data: any):
return {"event": "reply", "data": data}
π Project Structure
FastNest encourages a clean, professional layout:
core/: The DI engine and decorators.
common/: Reusable Guards, Pipes, and Interceptors.
example/: Fully working implementations to get you started.
π€ Roadmap & Contributing
FastNest is currently in version 0.1.1. Iβm planning to add more built-in decorators for database integration and enhanced CLI tools.
If you like the project, feel free to give it a βοΈ on GitHub or open an issue for suggestions!
GitHub: hamza-elmoudden/fastnest
PyPI: fastnest 0.1.1
Top comments (0)