Ellar - Modern Python ASGI Framework¶
logo by: Azad
Overview¶
Ellar is a modern, fast, and lightweight ASGI framework for building scalable web applications and APIs with Python. Built on top of Starlette and inspired by the best practices of frameworks like NestJS, Ellar combines the power of async Python with elegant architecture patterns.
โจ Key Features¶
- ๐ High Performance: Built on ASGI standards for maximum performance and scalability
- ๐ Dependency Injection: Built-in DI system for clean and maintainable code architecture
- ๐ Type Safety: First-class support for Python type hints and Pydantic validation
- ๐ OpenAPI Integration: Automatic Swagger/ReDoc documentation generation
- ๐๏ธ Modular Architecture: Organize code into reusable modules inspired by NestJS
- ๐ Built-in Security: Comprehensive authentication and authorization system
- ๐จ Template Support: Integrated Jinja2 templating for server-side rendering
- ๐ WebSocket Support: Real-time bidirectional communication capabilities
- ๐งช Testing Utilities: Comprehensive testing tools for unit and integration tests
๐ Getting Started¶
Installation¶
# Create and activate virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
# Install Ellar
pip install ellar
Basic Example¶
from ellar.common import get, Controller, ControllerBase
from ellar.app import AppFactory
import uvicorn
@Controller()
class HomeController(ControllerBase):
@get('/')
async def index(self):
return {'message': 'Welcome to Ellar Framework!'}
app = AppFactory.create_app(controllers=[HomeController])
if __name__ == "__main__":
uvicorn.run("main:app", port=5000, reload=True)
๐ Complete Example¶
from ellar.common import Body, Controller, ControllerBase, delete, get, post, put, Serializer
from ellar.di import injectable, request_scope
from ellar.app import AppFactory
from pydantic import Field
# Define Data Model
class CreateCarSerializer(Serializer):
name: str
year: int = Field(..., gt=0)
model: str
# Define Service
@injectable(scope=request_scope)
class CarService:
def __init__(self):
self.detail = 'car service'
# Define Controller
@Controller
class CarController(ControllerBase):
def __init__(self, service: CarService):
self._service = service
@post()
async def create(self, payload: Body[CreateCarSerializer]):
result = payload.dict()
result.update(message='Car created successfully')
return result
@get('/{car_id:str}')
async def get_one(self, car_id: str):
return f"Retrieved car #{car_id}"
app = AppFactory.create_app(
controllers=[CarController],
providers=[CarService]
)
๐ง Requirements¶
Core Dependencies¶
- Python >= 3.8
- Starlette >= 0.27.0
- Pydantic >= 2.0
- Injector >= 0.19.0
- typing-extensions >= 4.5.0
Optional Dependencies¶
- jinja2 - For template rendering
- python-multipart - For form data parsing
- itsdangerous - For security features
๐ Documentation Structure¶
๐ค Contributing¶
We welcome contributions! Here's how you can help:
- Create an issue for bugs or feature requests
- Submit pull requests for improvements
- Create third-party modules
- Share your experience with Ellar
- Build and showcase your applications
See CONTRIBUTING.md for detailed guidelines.
๐ License¶
Ellar is MIT Licensed.
๐ค Author¶
Ezeudoh Tochukwu @eadwinCode