Skip to main content

Light-weight and flexible ASGI API Framework

Project description

Starlite logo

PyPI - License PyPI - Python Version Discord Quality Gate Status Coverage Bugs Vulnerabilities Maintainability Rating Reliability Rating Security Rating

Starlite

Starlite is a light, opinionated and flexible ASGI API framework built on top of pydantic and Starlette.

Check out the Starlite documentation.

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 pydantic import UUID4
from starlite.controller import Controller
from starlite.handlers import get, post, put, patch, delete
from starlite.types import Partial

from my_app.models import User


class UserController(Controller):
    path = "/users"

    @post()
    async def create(self, data: User) -> User:
        ...

    @get()
    async def get_users(self) -> list[User]:
        ...

    @patch(path="/{user_id:uuid}")
    async def partial_update_user(self, user_id: UUID4, data: Partial[User]) -> User:
        ...

    @put(path="/{user_id:uuid}")
    async def update_user(self, user_id: UUID4, data: list[User]) -> list[User]:
        ...

    @get(path="/{user_id:uuid}")
    async def get_user_by_id(self, user_id: UUID4) -> User:
        ...

    @delete(path="/{user_id:uuid}")
    async def delete_user_by_id(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 you application, use an ASGI server such as uvicorn:

uvicorn my_app.main:app --reload

Project and Roadmap

This project builds on top the Starlette ASGI toolkit and pydantic modelling to create a higher-order opinionated framework. The idea to use these two libraries as a basis is of course not new - it was first done in FastAPI, which in this regard (and some others) was a source of inspiration for this framework. Nonetheless, Starlite is not FastAPI - it has a different design, different project goals and a completely different codebase.

  1. The goal of this project is to become a community driven project. That is, not to have a single "owner" but rather a core team of maintainers that leads the project, as well as community contributors.
  2. Starlite draws inspiration from NestJS - a contemporary TypeScript framework - which places opinions and patterns at its core. As such, the design of the API breaks from the Starlette design and instead offers an opinionated alternative.
  3. Finally, Python OOP is extremely powerful and versatile. While still allowing for function based endpoints, Starlite seeks to build on this by placing class based Controllers at its core.

Features and roadmap

  • sync and async API endpoints
  • fast json serialization using orjson
  • class based controllers
  • decorators based configuration
  • rigorous typing and type inference
  • layered dependency injection
  • automatic OpenAPI schema generation
  • support for pydantic models and pydantic dataclasses
  • support for vanilla python dataclasses
  • extended testing support
  • built-in Redoc based OpenAPI UI
  • route guards
  • detailed documentation
  • schemathesis integration

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

starlite-0.1.0.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

starlite-0.1.0-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

Details for the file starlite-0.1.0.tar.gz.

File metadata

  • Download URL: starlite-0.1.0.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.9 Linux/5.11.0-1022-azure

File hashes

Hashes for starlite-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0de86febbe70341ecdd7b2965c8e002598832396cdb325d34d05faf436bc96c0
MD5 d8756e889b44c3641471ea52d689dd06
BLAKE2b-256 ad5ac258a7aacdc80c4c180bcc249b522057ea4c53af2e24e2ea575a9ebf159b

See more details on using hashes here.

File details

Details for the file starlite-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: starlite-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 39.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.9.9 Linux/5.11.0-1022-azure

File hashes

Hashes for starlite-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9dda8a51bfb405ee208d22851f73dc7102869937b9a61679b9e3b4ffc1a5ab2
MD5 7982541af76bf0eed154a11e172243c4
BLAKE2b-256 623d37383e4635b2a99067352bb0dd941b7a915c721ff8e1af6f3f53fbdcd816

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page