<img alt="Starlite logo" src="./docs/images/SVG/starlite-banner.svg" width="100%" height="auto">
<div align="center">
![PyPI - License](https://img.shields.io/pypi/l/starlite?color=blue)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/starlite)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=Goldziher_starlite&metric=coverage)](https://sonarcloud.io/summary/new_code?id=Goldziher_starlite)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=Goldziher_starlite&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=Goldziher_starlite)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=Goldziher_starlite&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=Goldziher_starlite)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=Goldziher_starlite&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=Goldziher_starlite)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=Goldziher_starlite&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=Goldziher_starlite)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=Goldziher_starlite&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=Goldziher_starlite)
[![Discord](https://img.shields.io/discord/919193495116337154?color=blue&label=chat%20on%20discord&logo=discord)](https://discord.gg/X3FJqy8d2j)
[![Medium](https://img.shields.io/badge/Medium-12100E?style=flat&logo=medium&logoColor=white)](https://itnext.io/introducing-starlite-3928adaa19ae)
</div>
# Starlite
Starlite is a light and flexible ASGI API framework. Using [Starlette](https://github.com/encode/starlette)
and [pydantic](https://github.com/samuelcolvin/pydantic) as foundations.
Check out the [Starlite documentation ð](https://starlite-api.github.io/starlite/)
## Core Features
- ð Class based controllers
- ð Decorators based configuration
- ð Extended testing support
- ð Extensive typing support including inference, validation and parsing
- ð Full async (ASGI) support
- ð Layered dependency injection
- ð OpenAPI 3.1 schema generation with [Redoc](https://github.com/Redocly/redoc) UI
- ð Route guards based authorization
- ð Simple middleware and authentication
- ð Support for pydantic models and pydantic dataclasses
- ð Support for standard library dataclasses
- ð Support for SQLAlchemy declarative classes
- ð Plugin system to allow extending supported classes
- ð Ultra-fast json serialization and deserialization using [orjson](https://github.com/ijl/orjson)
## Installation
```shell
pip install starlite
```
## Relation to Starlette and FastAPI
Although Starlite uses the Starlette ASGI toolkit, it does not simply extend Starlette, as FastAPI does. Starlite uses
selective pieces of Starlette while implementing its own routing and parsing logic, the primary reason for this is to
enforce a set of best practices and discourage misuse. This is done to promote simplicity and scalability - Starlite is
simple to use, easy to learn, and unlike both Starlette and FastAPI - it keeps complexity low when scaling.
Additionally, Starlite is [faster than both FastAPI and Starlette](https://github.com/Goldziher/api-performance-tests):
![plain text requests processed](static/result-plaintext.png)
Legend:
- a-: async, s-: sync
- np: no params, pp: path param, qp: query param, mp: mixed params
### Class Based Controllers
While supporting function based route handlers, Starlite also supports and promotes python OOP using class based
controllers:
```python title="my_app/controllers/user.py"
from typing import List, Optional
from pydantic import UUID4
from starlite import Controller, Partial, get, post, put, patch, delete
from datetime import datetime
from my_app.models import User
class UserController(Controller):
path = "/users"
@post()
async def create_user(self, data: User) -> User:
...
@get()
async def list_users(self) -> List[User]:
...
@get(path="/{date:int}")
async def list_new_users(self, date: datetime) -> List[User]:
...
@patch(path="/{user_id:uuid}")
async def partially_update_user(self, user_id: UUID4, data: Partial[User]) -> User:
...
@put(path="/{user_id:uuid}")
async def update_user(self, user_id: UUID4, data: User) -> User:
...
@get(path="/{user_name:str}")
async def get_user_by_name(self, user_name: str) -> Optional[User]:
...
@get(path="/{user_id:uuid}")
async def get_user(self, user_id: UUID4) -> User:
...
@delete(path="/{user_id:uuid}")
async def delete_user(self, user_id: UUID4) -> User:
...
```
### Data Parsing, Type Hints and Pydantic
One key difference between Starlite and Starlette/FastAPI is in parsing of form data and query parameters- Starlite
supports mixed form data and has faster and better query parameter parsing.
Starlite is rigorously typed, and it enforces typing. For example, if you forget to type a return value for a route
handler, an exception will be raised. The reason for this is that Starlite uses typing data to generate OpenAPI specs,
as well as to validate and parse data. Thus typing is absolutely essential to the framework.
Furthermore, Starlite allows extending its support using plugins.
### SQL Alchemy Support, Plugin System and DTOs
Starlite has a plugin system that allows the user to extend serialization/deserialization, OpenAPI generation and other
features. It ships with a builtin plugin for SQL Alchemy, which allows the user to use SQL Alchemy declarative classes
"natively", i.e. as type parameters that will be serialized/deserialized and to return them as values from route
handlers.
Starlite also supports the programmatic creation of DTOs with a `DTOFactory` class, which also supports the use of plugins.
### OpenAPI
Starlite has custom logic to generate OpenAPI 3.1.0 schema, the latest version. The schema generated by Starlite is
significantly more complete and more correct than those generated by FastAPI, and they include optional generation of
examples using the `pydantic-factories` library.
### Dependency Injection
Starlite has a simple but powerful DI system inspired by pytest. You can define named dependencies - sync or async - at
different levels of the application, and then selective use or overwrite them.
### Middleware
Starlite supports the Starlette Middleware system while simplifying it and offering builtin configuration of CORS and
some other middlewares.
### Route Guards
Starlite has an authorization mechanism called `guards`, which allows the user to define guard functions at different
level of the application (app, router, controller etc.) and validate the request before hitting the route handler
function.
### Request Life Cycle Hooks
Starlite supports request life cycle hooks, similarly to Flask - i.e. `before_request` and `after_request`
## Contributing
Starlite is open to contributions big and small. You can always [join our discord](https://discord.gg/X3FJqy8d2j) server
to discuss contributions and project maintenance. For guidelines on how to contribute, please
see [the contribution guide](CONTRIBUTING.md).
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
最新资源
- Java毕业设计-springboot-vue-综合小区管理系统(源码+sql脚本+29页零基础部署图文详解+33页论文+环境工具+教程+视频+模板).zip
- Java毕业设计-springboot-vue-足球社区管理系统(源码+sql脚本+29页零基础部署图文详解+35页论文+环境工具+教程+视频+模板).zip
- Java毕业设计-springboot-vue-足球俱乐部管理系统(源码+sql脚本+29页零基础部署图文详解+31页论文+环境工具+教程+视频+模板).zip
- cursor使用学习研究ai-intelligent-assistant-master.zip
- Snipaste-1.16.2-x64-win 截图 贴图工具
- 信捷PLC与威纶通触摸屏控制非标设备机架旋铆机:多点位设定、运动控制与配方宏功能实现,信捷PLC程序 信捷PLC+威纶通触摸屏 非标设备机架旋铆机,可设定多点位,示教功能,配方功能
- python + nodejs实现数据采集
- Hypermesh与Dyna联合构建的整车碰撞模型仿真与实验对标研究报告:对标Honda Accord车型碰撞模型和报告分析(详尽版),Hypermesh+dyna整车碰撞模型( 仿真+试验对标) 国
- 基于Matlab与Yalmip求解器的智能软开关配电网重构模型:考虑二阶锥与多种约束条件的连通性和辐射性研究,智能软开关 配电网重构matlab 二阶锥 编程方法:matlab+yalmip(cple
- 计及条件风险价值的电气综合能源系统能量与备用调度分布鲁棒优化模型,matlab代码:计及条件风险价值的电气综合能源系统能量-备用分布鲁棒优化 关键词:wasserstein距离 CVAR条件风险价值
- 基于 DeepSeek-V2 和 LangGraph 为 Python 代码自动编写单元测试的源码
- 基于Moire光子晶体的大容量、高性能能带结构分析与研究-自由度高达300万次的独特挑战,Moire光子晶体能带 300w+自由度,需自己执行!!! ,核心关键词:Moire光子晶体;能带;300
- PowerBI svg 折线面积图
- 高频注入模型的脉振永磁同步电机无传感器矢量控制:可加载与转速辨识功能,高频注入模型,可加载,可加载,可加载 (1)基于脉振高频注入的永磁同步电机无速度传感器矢量控制MATLAB仿真模型; (2)模型可
- 新能源汽车车载充放电机系统MATLAB仿真模型:双向AC DC与双向DC DC技术结合V2G功能,新能源汽车车载双向OBC,PFC,LLC,V2G 双向 充电桩 电动汽车 车载充电机 充放电机 MAT
- 高频隔离型光伏离网单相逆变器控制算法:高频移相全桥升压+谐振控制器+SOGI双闭环dq解耦技术+仿真验证,高频隔离型光伏离网单相逆变器的控制算法的C代码+仿真模型,DC70~150V输入,AC220V
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈