Light-weight and flexible ASGI API Framework
Project description
Starlite
Starlite is a light, opinionated and flexible ASGI API framework built on top of pydantic and Starlette.
Check out the Starlite documentation 📚
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 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
Installation
Using your package manager of choice:
pip install starlite
OR
poetry add starlite
OR
pipenv install starlite
Minimal Example
Define your data model using pydantic or any library based on it (see for example ormar, beanie, SQLModel etc.):
from pydantic import BaseModel, UUID4
class User(BaseModel):
first_name: str
last_name: str
id: UUID4
You can alternatively use a dataclass, either the standard library one or the one from pydantic:
from uuid import UUID
# from pydantic.dataclasses import dataclass
from dataclasses import dataclass
@dataclass
class User:
first_name: str
last_name: str
id: UUID
Define a Controller for your data model:
from typing import List
from pydantic import UUID4
from starlite import Controller, Partial, get, post, put, patch, delete
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]:
...
@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_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:
...
Import your controller into your application's entry-point and pass it to Starlite when instantiating your app:
from starlite import Starlite
from my_app.controllers.user import UserController
app = Starlite(route_handlers=[UserController])
To run your application, use an ASGI server such as uvicorn:
uvicorn my_app.main:app --reload
Contributing
Starlite is open to contributions big and small. You can always join our discord server to discuss contributions and project maintenance. For guidelines on how to contribute, please see the contribution guide.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file starlite-0.4.2.tar.gz
.
File metadata
- Download URL: starlite-0.4.2.tar.gz
- Upload date:
- Size: 40.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.9 Linux/5.11.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 31918b83112cf0571eea1c3d6326aaf06d3050da04b6328c5f882920f5704a52 |
|
MD5 | 4984cfb7a3ccbe6a95da6937d65c45bb |
|
BLAKE2b-256 | c9bdefb032e26b84ba29e4d587a764dc4625092533c4fbc6229151ea3afede42 |
File details
Details for the file starlite-0.4.2-py3-none-any.whl
.
File metadata
- Download URL: starlite-0.4.2-py3-none-any.whl
- Upload date:
- Size: 50.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.9.9 Linux/5.11.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3602c63f2f6b9e13e58c68a6b9373632c1b7a35147a8d13b9d73734668161c0 |
|
MD5 | 78dcfb1a8c3eae62bdb5ba9351a25076 |
|
BLAKE2b-256 | 3c62a1a84c1d21c23df29a11bbf3af7a06aaa617b5b85ee6e8b4627f81fe6922 |