litestar
Production-ready, Light, Flexible and Extensible ASGI API framework | Effortlessly Build Performant APIs
Science Score: 54.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
3 of 241 committers (1.2%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (4.6%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Production-ready, Light, Flexible and Extensible ASGI API framework | Effortlessly Build Performant APIs
Basic Info
- Host: GitHub
- Owner: litestar-org
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://litestar.dev/
- Size: 145 MB
Statistics
- Stars: 7,363
- Watchers: 47
- Forks: 455
- Open Issues: 257
- Releases: 0
Topics
Metadata Files
README.md
Litestar is a powerful, flexible yet opinionated ASGI framework, focused on building APIs. It offers high-performance data validation, dependency injection, first-class ORM integration, authorization primitives, a rich plugin API, middleware, and much more that's needed to get applications up and running.
Check out the documentation 📚 for a detailed overview of its features!
Additionally, the Litestar fullstack repository can give you a good impression how a fully fledged Litestar application may look.
Table of Contents
- [Installation](#installation) - [Quick Start](#quick-start) - [Core Features](#core-features) - [Example Applications](#example-applications) - [Features](#features) - [Class-based Controllers](#class-based-controllers) - [Data Parsing, Type Hints, and Msgspec](#data-parsing-type-hints-and-msgspec) - [Plugin System, ORM support, and DTOs](#plugin-system-orm-support-and-dtos) - [OpenAPI](#openapi) - [Dependency Injection](#dependency-injection) - [Middleware](#middleware) - [Route Guards](#route-guards) - [Request Life Cycle Hooks](#request-life-cycle-hooks) - [Performance](#performance) - [Contributing](#contributing)Installation
shell
pip install litestar
or to include the CLI and a server (uvicorn) for running your application:
shell
pip install 'litestar[standard]'
Quick Start
```python title="app.py" from litestar import Litestar, get
@get("/") async def hello_world() -> dict[str, str]: """Keeping the tradition alive with hello world.""" return {"hello": "world"}
app = Litestar(routehandlers=[helloworld]) ```
And run it with
bash
litestar run
Core Features
- Class based controllers
- Dependency Injection
- Layered Middleware
- Plugin System
- OpenAPI 3.1 schema generation
- Life Cycle Hooks
- Route Guards based Authorization
- Support for
dataclasses,TypedDict,msgspec, pydantic version 1 and version 2 (even within the same application) and (c)attrs msgspec and attrs - Layered parameter declaration
- Support for RFC 9457 standardized "Problem Detail" error responses
- Automatic API documentation with:
- Trio support (built-in, via AnyIO)
- Ultra-fast validation, serialization and deserialization using msgspec
- SQLAlchemy integration
Example Applications
Pre-built Example Apps
- [litestar-hello-world](https://github.com/litestar-org/litestar-hello-world): A bare-minimum application setup. Great for testing and POC work. - [litestar-fullstack](https://github.com/litestar-org/litestar-fullstack): A reference application that contains most of the boilerplate required for a web application. It features a Litestar app configured with best practices, SQLAlchemy 2.0 and SAQ, a frontend integrated with Vitejs and Jinja2 templates, Docker, and more. Like all Litestar projects, this application is open to contributions, big and small.Sponsors
Litestar is an open-source project, and we enjoy the support of our sponsors to help fund the exciting work we do.
A huge thanks to our sponsors:
Check out our sponsors in the docs
If you would like to support the work that we do please consider becoming a sponsor via Polar.sh (preferred), GitHub or Open Collective.
Also, exclusively with Polar, you can engage in pledge-based sponsorships.
Features
Class-based Controllers
While supporting function-based route handlers, Litestar also supports and promotes python OOP using class based controllers:
Example for class-based controllers
```python title="my_app/controllers/user.py" from typing import List, Optional from datetime import datetime from litestar import Controller, get, post, put, patch, delete from litestar.dto import DTOData from pydantic import UUID4 from my_app.models import User, PartialUserDTO 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}", dto=PartialUserDTO) async def partial_update_user( self, user_id: UUID4, data: DTOData[PartialUserDTO] ) -> 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) -> None: ... ```Data Parsing, Type Hints, and Msgspec
Litestar 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 Litestar uses typing data to generate OpenAPI specs, as well as to validate and parse data. Thus, typing is essential to the framework.
Furthermore, Litestar allows extending its support using plugins.
Plugin System, ORM support, and DTOs
Litestar 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 SQLAlchemy declarative classes "natively" i.e., as type parameters that will be serialized/deserialized and to return them as values from route handlers.
Litestar also supports the programmatic creation of DTOs with a DTOFactory class, which also supports the use of
plugins.
OpenAPI
Litestar has custom logic to generate OpenAPI 3.1.0 schema, include optional generation of examples using the
polyfactory library.
ReDoc, Swagger-UI and Stoplight Elements API Documentation
Litestar serves the documentation from the generated OpenAPI schema with:
All these are available and enabled by default.
Dependency Injection
Litestar 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.
Example for DI
```python from litestar import Litestar, get from litestar.di import Provide async def my_dependency() -> str: ... @get("/") async def index(injected: str) -> str: return injected app = Litestar([index], dependencies={"injected": Provide(my_dependency)}) ```Middleware
Litestar supports typical ASGI middleware and ships with middlewares to handle things such as
- CORS
- CSRF
- Rate limiting
- GZip and Brotli compression
- Client- and server-side sessions
Route Guards
Litestar 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.
Example for route guards
```python from litestar import Litestar, get from litestar.connection import ASGIConnection from litestar.handlers.base import BaseRouteHandler from litestar.exceptions import NotAuthorizedException async def is_authorized(connection: ASGIConnection, handler: BaseRouteHandler) -> None: # validate authorization # if not authorized, raise NotAuthorizedException raise NotAuthorizedException() @get("/", guards=[is_authorized]) async def index() -> None: ... app = Litestar([index]) ```Request Life Cycle Hooks
Litestar supports request life cycle hooks, similarly to Flask - i.e. before_request and after_request
Performance
Litestar is fast. It is on par with, or significantly faster than comparable ASGI frameworks.
You can see and run the benchmarks here, or read more about it here in our documentation.
Contributing
Litestar is open to contributions big and small. You can always join our discord server or join our Matrix space to discuss contributions and project maintenance. For guidelines on how to contribute, please see the contribution guide.
Contributors ✨
Thanks goes to these wonderful people:
Emoji KeyOwner
- Name: Litestar
- Login: litestar-org
- Kind: organization
- Email: hello@litestar.dev
- Location: Internet
- Website: https://litestar.dev
- Twitter: LitestarAPI
- Repositories: 45
- Profile: https://github.com/litestar-org
Effortlessly Build Performant APIs
Citation (CITATION.cff)
cff-version: 1.2.0 title: Litestar message: 'If you use this software, please cite it as below.' type: software authors: - given-names: Janek Nouvertné - given-names: Peter Schutt - given-names: Cody Fincher - given-names: Visakh Unnikrishnan - given-names: Jacob Coffee - given-names: Na'aman Hirschfeld repository-code: 'https://github.com/litestar-org/litestar' url: 'https://docs.litestar.dev/latest/' abstract: >- Litestar is a powerful, flexible, and highly performant Python web framework for building modern APIs and applications. With an emphasis on developer experience and performance, Litestar provides a rich set of features out of the box, including automatic API documentation, data validation and serialization, ORM integration, dependency injection, caching, websockets, and more. Litestar's layered architecture and open ecosystem enable seamless integration with popular libraries like Pydantic, SQLAlchemy, and msgspec. It offers both asynchronous and synchronous execution models without performance penalties. With Litestar, you can effortlessly build and deploy production-ready APIs and web applications, leveraging features like interactive API documentation, middlewares for common tasks, session and JWT-based authentication, and strict runtime validation for enhanced safety. Experience the perfect blend of ease of use, flexibility and performance with Litestar. keywords: - python - web - framework - typing - dependency injection - api license: MIT version: v2.8.0 date-released: '2024-04-05'
Committers
Last synced: 8 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Na'aman Hirschfeld | n****d@g****m | 577 |
| Janek Nouvertné | 2****t | 548 |
| Peter Schutt | p****r@t****u | 350 |
| allcontributors[bot] | 4****] | 283 |
| Cody Fincher | 2****n | 138 |
| Jacob Coffee | j****b@z****g | 132 |
| Na'aman Hirschfeld | N****d@s****m | 126 |
| sobolevn | m****l@s****e | 48 |
| dependabot[bot] | 4****] | 31 |
| guacs | 1****s | 30 |
| euri10 | b****t@g****m | 30 |
| Alc-Alc | 4****c | 29 |
| Konstantin Mikhailov | j****b | 25 |
| seladb | p****s@g****m | 24 |
| kedod | 3****d | 18 |
| Ashwin Vinod | a****a@g****m | 18 |
| dkress59 | 2****9 | 18 |
| Arseny Boykov | 3****m | 13 |
| Abdulhaq Emhemmed | a****d@g****m | 12 |
| yudjinn | y****g@g****m | 11 |
| infohash | 4****h | 11 |
| George Sakkis | g****s@g****m | 11 |
| Tory Clasen | T****n@G****m | 9 |
| Boseong Choi | 3****m | 8 |
| Kyle Smith | s****6@g****m | 8 |
| Dane Solberg | d****g@g****m | 8 |
| jderrien | j****n@g****m | 7 |
| Tim Wedde | t****e@i****m | 7 |
| Harshal Laheri | 7****7 | 7 |
| Jon Daly | j****y@s****m | 6 |
| and 211 more... | ||
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 851
- Total pull requests: 2,219
- Average time to close issues: about 2 months
- Average time to close pull requests: 6 days
- Total issue authors: 310
- Total pull request authors: 202
- Average comments per issue: 2.33
- Average comments per pull request: 2.61
- Merged pull requests: 1,714
- Bot issues: 19
- Bot pull requests: 317
Past Year
- Issues: 201
- Pull requests: 554
- Average time to close issues: 9 days
- Average time to close pull requests: 3 days
- Issue authors: 106
- Pull request authors: 74
- Average comments per issue: 0.85
- Average comments per pull request: 2.06
- Merged pull requests: 403
- Bot issues: 0
- Bot pull requests: 54
Top Authors
Issue Authors
- peterschutt (72)
- JacobCoffee (64)
- provinzkraut (39)
- sobolevn (24)
- euri10 (23)
- gsakkis (21)
- cofin (20)
- byte-bot-app[bot] (19)
- tuukkamustonen (18)
- umarbutler (13)
- Goldziher (12)
- guacs (11)
- v3ss0n (11)
- Alc-Alc (11)
- floxay (10)
Pull Request Authors
- provinzkraut (444)
- peterschutt (242)
- allcontributors[bot] (183)
- cofin (177)
- JacobCoffee (143)
- sourcery-ai[bot] (89)
- sobolevn (72)
- euri10 (69)
- Alc-Alc (50)
- dependabot[bot] (45)
- guacs (42)
- Goldziher (37)
- kedod (36)
- jderrien (18)
- abdulhaq-e (17)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 4
-
Total downloads:
- pypi 823,459 last-month
- Total docker downloads: 308
-
Total dependent packages: 40
(may contain duplicates) -
Total dependent repositories: 166
(may contain duplicates) - Total versions: 410
- Total maintainers: 3
- Total advisories: 5
pypi.org: starlite
Performant, light and flexible ASGI API Framework
- Homepage: https://litestar.dev
- Documentation: https://docs.litestar.dev/1/
- License: MIT
-
Latest release: 1.51.16
published almost 2 years ago
Rankings
Maintainers (3)
Advisories (3)
pypi.org: litestar
Litestar - A production-ready, highly performant, extensible ASGI API Framework
- Homepage: https://litestar.dev/
- Documentation: https://docs.litestar.dev/
- License: MIT
-
Latest release: 2.17.0
published 6 months ago
Rankings
Maintainers (3)
Funding
- https://github.com/sponsors/litestar-org
Advisories (4)
proxy.golang.org: github.com/litestar-org/litestar
- Documentation: https://pkg.go.dev/github.com/litestar-org/litestar#section-documentation
- License: mit
-
Latest release: v2.17.0+incompatible
published 6 months ago
Rankings
conda-forge.org: starlite
- Homepage: https://litestar.dev
- License: MIT
-
Latest release: 1.39.0
published over 3 years ago
Rankings
Dependencies
- aiomcache *
- anyio >=3
- brotli *
- click *
- cryptography *
- fast-query-parsers *
- httpx >=0.22
- importlib-metadata *
- jinja2 >=3.1.2
- jsbeautifier *
- mako >=1.2.4
- msgspec >=0.11.0
- multidict >=6.0.2
- opentelemetry-instrumentation-asgi *
- picologging *
- pydantic *
- pydantic-factories *
- pydantic-openapi-schema >=1.5.0
- python >=3.8,<4.0
- python-jose *
- pyyaml *
- redis *
- rich >=13.0.0
- structlog *
- typing-extensions *
- actions/cache v3 composite
- actions/checkout v4 composite
- actions/download-artifact v3 composite
- actions/setup-python v4 composite
- actions/upload-artifact v3 composite
- github/codeql-action/analyze v2 composite
- github/codeql-action/init v2 composite
- pdm-project/setup-pdm v3 composite
- sonarsource/sonarcloud-github-action master composite
- JamesIves/github-pages-deploy-action v4 composite
- actions/checkout v4 composite
- actions/github-script v6 composite
- dawidd6/action-download-artifact v2 composite
- JamesIves/github-pages-deploy-action v4 composite
- actions/checkout v4 composite
- actions/setup-python v4 composite
- pdm-project/setup-pdm v3 composite
- amannn/action-semantic-pull-request v5 composite
- actions/checkout v4 composite
- actions/setup-python v4 composite
- pdm-project/setup-pdm v3 composite
- pypa/gh-action-pypi-publish release/v1 composite
- actions/checkout v4 composite
- actions/setup-python v4 composite
- actions/upload-artifact v3 composite
- pdm-project/setup-pdm v3 composite
- actions/checkout v4 composite
- github/codeql-action/analyze v2 composite
- github/codeql-action/init v2 composite
- gcr.io/cloud-spanner-emulator/emulator latest
- gcr.io/google.com/cloudsdktool/cloud-sdk 332.0.0-slim
- gvenzl/oracle-xe 18-slim-faststart
- mysql latest
- postgres latest
- redis latest
- python ${VARIANT} build