Skip to main content

Light-weight and flexible ASGI API Framework

Project description

Starlite logo

PyPI - License PyPI - Python Version

Coverage Vulnerabilities Quality Gate Status Maintainability Rating Reliability Rating Security Rating

Discord

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
  • 👉 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 you 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

This version

0.1.4

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.4.tar.gz (30.7 kB view details)

Uploaded Source

Built Distribution

starlite-0.1.4-py3-none-any.whl (38.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: starlite-0.1.4.tar.gz
  • Upload date:
  • Size: 30.7 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.4.tar.gz
Algorithm Hash digest
SHA256 359515ac7f74040fff1e1523cceacc244911e2f35b578ea22e7db8dc64198e09
MD5 519f5cf09b2b252daa759da22e637ea8
BLAKE2b-256 4254f93ab41bd75e1fa68e30b42ff57701247c8f93a606235fdfc5b1fe14369d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: starlite-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 38.7 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ae986324d7ba685090f42ffed581d858dc418f56519b6236dd1ecdf8f1d1fc57
MD5 7296bdbc83a9c94c6a769058b5c8eaec
BLAKE2b-256 9c9a59e437312f4b1fa4d1d6da02d57f0b610f0cdefe9c338174c17b52d3bb28

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