Ellar is a lightweight ASGI framework for building efficient and scalable server-side python applications. It supports both OOP (Object-Oriented Programming) and FP (Functional Programming). Built with passion for programming
logo by: Azad
Ellar - Python ASGI web framework for building fast, efficient, and scalable RESTful APIs and server-side applications.
Ellar is a lightweight ASGI framework designed to simplify the development of efficient and scalable server-side Python
applications. Whether you’re building web services, APIs, or full-fledged web applications,
Ellar offers a high level of abstraction and powerful features to streamline your development process.
Ellar allows developers to embrace both Object-Oriented Programming (OOP) and Functional Programming (FP) paradigms.
It is built on top of Starlette, a renowned ASGI toolkit, ensuring robust asynchronous request-handling capabilities.
You can install Ellar using pip:
# 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
# main.py
from ellar.common import get, Controller, ControllerBase
from ellar.app import AppFactory
@Controller()
class HomeController(ControllerBase):
@get('/')
async def index(self):
return {'message': 'Welcome to Ellar Framework!'}
app = AppFactory.create_app(controllers=[HomeController])
# Run the application
if __name__ == "__main__":
uvicorn.run("main:app", port=5000, reload=True)
# Example code showcasing Ellar usage
# (Please ensure you have properly installed Ellar first)
import uvicorn
from ellar.common import Body, Controller, ControllerBase, delete, get, post, put, Serializer, Inject
from ellar.app import AppFactory
from ellar.di import injectable, request_scope
from ellar.openapi import OpenAPIDocumentModule, OpenAPIDocumentBuilder, SwaggerUI
from pydantic import Field
from pathlib import Path
# Define a serializer for creating a car
class CreateCarSerializer(Serializer):
name: str
year: int = Field(..., gt=0)
model: str
# Define a service class for car operations
@injectable(scope=request_scope)
class CarService:
def __init__(self):
self.detail = 'a service'
# Define a controller for car operations
@Controller
class MotoController(ControllerBase):
def __init__(self, service: CarService):
self._service = service
@post()
async def create(self, payload: Body[CreateCarSerializer]):
assert self._service.detail == 'a service'
result = payload.dict()
result.update(message='This action adds a new car')
return result
@put('/{car_id:str}')
async def update(self, car_id: str, payload: Body[CreateCarSerializer]):
result = payload.dict()
result.update(message=f'This action updated #{car_id} car resource')
return result
@get('/{car_id:str}')
async def get_one(self, car_id: str, service: Inject[CarService]):
assert self._service == service
return f"This action returns a #{car_id} car"
@delete('/{car_id:str}')
async def delete(self, car_id: str):
return f"This action removes a #{car_id} car"
# Create the Ellar application
app = AppFactory.create_app(
controllers=[MotoController],
providers=[CarService],
base_directory=str(Path(__file__).parent),
config_module=dict(REDIRECT_SLASHES=True),
template_folder='templates'
)
# Build OpenAPI documentation
document_builder = OpenAPIDocumentBuilder()
document_builder.set_title('Ellar API') \
.set_version('1.0.2') \
.set_contact(name='Author', url='https://www.yahoo.com', email='[email protected]') \
.set_license('MIT Licence', url='https://www.google.com')
document = document_builder.build_document(app)
# Setup OpenAPI documentation module
OpenAPIDocumentModule.setup(
app=app,
docs_ui=SwaggerUI(),
document=document,
guards=[]
)
# Run the application
if __name__ == "__main__":
uvicorn.run("main:app", port=5000, reload=True)
Now we can test our API at http://127.0.0.1:5000/docs
You can also try the quick-project setup to get a good idea of the library.
Ellar has the following core dependencies:
Optional dependencies:
Contributions are Welcome! You can contribute in the following ways.
Thanks to all contributors!
Ezeudoh Tochukwu https://github.com/eadwinCode
Ellar is MIT License.