Package: ellar
logo by:AzadEllar - Python ASGI web framework for building fast, efficient, and scalable RESTful APIs and server-side applications.Project StatusBeta versionDocumentation - 97% completeAuthorization Documentation - (in progress)ResourcesDocumentationIntroductionEllar 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)Ellar is based onStarlette (ASGI toolkit), a lightweight ASGI framework/toolkit well-suited for developing asynchronous web services with Python.Features SummaryEasy to Use: Ellar has a simple and intuitive API that makes it easy to get started with building a fast and scalable web applications or web APIs in Python.Dependency Injection (DI): It comes with DI system makes it easy to manage dependencies and reduce coupling between components.Pydantic Integration: It is properly integrated with Pydantic, a popular Python library for data validation, to ensure that input data is valid.Templating with Jinja2: Ellar provides built-in support for Jinja2 templates, making it easy to create dynamic web pages.OpenAPI Documentation: It comes with built-in support for OpenAPI documentation, making it easy to generateSwaggerorReDocdocumentation for your API. And more can be added with ease if necessary.Controller (MVC) Architecture: Ellar's controller architecture follows the Model-View-Controller (MVC) pattern, making it easy to organize your code.Guards for Authentication and Authorization: It provides built-in support for guards, allowing you to easily implement authentication and authorization in your application.Modularity: Ellar follows a modular architecture inspired by NestJS, making it easy to organize your code into reusable modules.Asynchronous programming: It allows you to takes advantage of Python'sasync/awaitfeature to write efficient and fast code that can handle large numbers of concurrent requestsDependenciesPython >= 3.7StarletteInjectorPydanticInstallation$(venv)pipinstallellarTry Thisimportuvicornfromellar.commonimportBody,Controller,ControllerBase,delete,get,post,put,Serializer,Injectfromellar.appimportAppFactoryfromellar.diimportinjectable,request_scopefromellar.openapiimportOpenAPIDocumentModule,OpenAPIDocumentBuilder,SwaggerUIfrompydanticimportFieldfrompathlibimportPathclassCreateCarSerializer(Serializer):name:stryear:int=Field(...,gt=0)model:str@injectable(scope=request_scope)classCarService:def__init__(self):self.detail='a service'@ControllerclassMotoController(ControllerBase):def__init__(self,service:CarService):self._service=service@post()asyncdefcreate(self,payload:Body[CreateCarSerializer]):assertself._service.detail=='a service'result=payload.dict()result.update(message='This action adds a new car')returnresult@put('/{car_id:str}')asyncdefupdate(self,car_id:str,payload:Body[CreateCarSerializer]):result=payload.dict()result.update(message=f'This action updated #{car_id}car resource')returnresult@get('/{car_id:str}')asyncdefget_one(self,car_id:str,service:Inject[CarService]):assertself._service==servicereturnf"This action returns a #{car_id}car"@delete('/{car_id:str}')asyncdefdelete(self,car_id:str):returnf"This action removes a #{car_id}car"app=AppFactory.create_app(controllers=[MotoController],providers=[CarService],base_directory=str(Path(__file__).parent),config_module=dict(REDIRECT_SLASHES=True),template_folder='templates')document_builder=OpenAPIDocumentBuilder()document_builder.set_title('Ellar API')\.set_version('1.0.2')\.set_contact(name='Author',url='https://www.yahoo.com',email='author@gmail.com')\.set_license('MIT Licence',url='https://www.google.com')document=document_builder.build_document(app)module=OpenAPIDocumentModule.setup(app=app,docs_ui=SwaggerUI(),document=document,guards=[])if__name__=="__main__":uvicorn.run("main:app",port=5000,reload=True)Now we can test our API athttp://127.0.0.1:5000/docsYou can also try thequick-projectsetup to get a good idea of the library.HTML TemplatingEllar has built-in support for Jinja2, which is a popular template engine for HTML. This feature allows for easy and efficient HTML templating similar to that of Flask. Jinja2 can be used to create reusable templates, and to insert dynamic data into HTML pages. It also has support for template inheritance, control structures, and other useful features that can help to simplify and streamline the process of creating HTML templates.<html><body><ul>{% for item in items %}<li>{{ item }}</li>{% endfor %}</ul></body></html>ResourcesDocumentation