starlite-saqlalchemy


Namestarlite-saqlalchemy JSON
Version 0.30.0 PyPI version JSON
download
home_pagehttps://github.com/topsport-com-au/starlite-saqlalchemy
SummaryStarlite config plugin with SAQ and SQLAlchemy boilerplate
upload_time2023-03-10 23:53:06
maintainer
docs_urlNone
authorPeter Schutt
requires_python>=3.10,<4.0
licenseMIT
keywords api rest http asgi starlite saq sqlalchemy plugin python
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <h1 align="center">starlite-saqlalchemy</h1>
<p align="center">
  <img src="https://www.topsport.com.au/assets/images/logo_pulse.svg" width="200" alt="TopSport Pulse"/>
</p>

<p align="center">
  <a href="https://pypi.org/project/starlite-saqlalchemy">
    <img src="https://img.shields.io/pypi/v/starlite-saqlalchemy" alt="PYPI: starlite-saqlalchemy"/>
  </a>
  <a href="https://github.com/topsport-com-au/starlite-saqlalchemy/blob/main/LICENSE">
    <img src="https://img.shields.io/pypi/l/starlite-saqlalchemy?color=blue" alt="License: MIT"/>
  </a>
  <a href="https://python.org">
    <img src="https://img.shields.io/pypi/pyversions/starlite-saqlalchemy" alt="Python: supported versions"/>
  </a>
  <a href="https://results.pre-commit.ci/latest/github/topsport-com-au/starlite-saqlalchemy/main">
    <img alt="pre-commit.ci status" src="https://results.pre-commit.ci/badge/github/topsport-com-au/starlite-saqlalchemy/main.svg"/>
  </a>
  <a href="https://bestpractices.coreinfrastructure.org/projects/6646">
    <img alt="OpenSSF Best Practices" src="https://bestpractices.coreinfrastructure.org/projects/6646/badge">
  </a>
  <a href="https://github.com/topsport-com-au/starlite-saqlalchemy/actions/workflows/ci.yml">
    <img alt="Actions: CI" src="https://github.com/topsport-com-au/starlite-saqlalchemy/actions/workflows/ci.yml/badge.svg?branch=main&event=push"/>
  </a>
</p>
<p align="center">
  <a href="https://sonarcloud.io/summary/new_code?id=topsport-com-au_starlite-saqlalchemy">
    <img alt="Reliability Rating" src="https://sonarcloud.io/api/project_badges/measure?project=topsport-com-au_starlite-saqlalchemy&metric=reliability_rating"/>
  </a>
  <a href="https://sonarcloud.io/summary/new_code?id=topsport-com-au_starlite-saqlalchemy">
    <img alt="Quality Gate Status" src="https://sonarcloud.io/api/project_badges/measure?project=topsport-com-au_starlite-saqlalchemy&metric=alert_status"/>
  </a>
  <a href="https://sonarcloud.io/summary/new_code?id=topsport-com-au_starlite-saqlalchemy">
    <img alt="Quality Gate Status" src="https://sonarcloud.io/api/project_badges/measure?project=topsport-com-au_starlite-saqlalchemy&metric=coverage"/>
  </a>
  <a href="https://sonarcloud.io/summary/new_code?id=topsport-com-au_starlite-saqlalchemy">
    <img alt="Quality Gate Status" src="https://sonarcloud.io/api/project_badges/measure?project=topsport-com-au_starlite-saqlalchemy&metric=sqale_rating"/>
  </a>
  <a href="https://sonarcloud.io/summary/new_code?id=topsport-com-au_starlite-saqlalchemy">
    <img alt="Quality Gate Status" src="https://sonarcloud.io/api/project_badges/measure?project=topsport-com-au_starlite-saqlalchemy&metric=security_rating"/>
  </a>
  <a href="https://sonarcloud.io/summary/new_code?id=topsport-com-au_starlite-saqlalchemy">
    <img alt="Quality Gate Status" src="https://sonarcloud.io/api/project_badges/measure?project=topsport-com-au_starlite-saqlalchemy&metric=bugs"/>
  </a>
  <a href="https://sonarcloud.io/summary/new_code?id=topsport-com-au_starlite-saqlalchemy">
    <img alt="Quality Gate Status" src="https://sonarcloud.io/api/project_badges/measure?project=topsport-com-au_starlite-saqlalchemy&metric=vulnerabilities"/>
  </a>
</p>

Configuration for a [Starlite](https://github.com/starlite-api/starlite) application that features:

- SQLAlchemy 2.0
- SAQ async worker
- Lots of features!

## Installation

This will install `starlite-saqlalchemy` with minimal dependencies.

```console
poetry add starlite-saqlalchemy
```

You can also install additional dependencies depending on the features you need:

```console
# Repository implementation, DTOs
poetry add starlite-saqlalchemy[sqlalchemy]
# Async worker using saq
poetry add starlite-saqlalchemy[worker]
# Redis cache backend
poetry add starlite-saqlalchemy[cache]
# Sentry integration for starlite
poetry add starlite-saqlalchemy[sentry]

# or to install them all:
poetry add starlite-saqlalchemy[all]
```

## Example

```python
from starlite import Starlite, get

from starlite_saqlalchemy import ConfigureApp


@get("/example")
def example_handler() -> dict:
    """Hello, world!"""
    return {"hello": "world"}


app = Starlite(route_handlers=[example_handler], on_app_init=[ConfigureApp()])
```

## Features

The application configured in the above example includes the following configuration.

### Logging after exception handler

Receives and logs any unhandled exceptions raised out of route handling.

### Redis cache

Integrates a Redis cache backend with Starlite first-class cache support.

### Collection route filters

Support filtering collection routes by created and updated timestamps, list of ids, and limit/offset
pagination.

Includes an aggregate `filters` dependency to easily inject all filters into a route handler, e.g,:

```python
from starlite import get
from starlite_saqlalchemy.dependencies import FilterTypes


@get()
async def get_collection(filters: list[FilterTypes]) -> list[...]:
    ...
```

### Gzip compression

Configures Starlite's built-in Gzip compression support.

### Exception handlers

Exception handlers that translate non-Starlite repository and service object exception
types into Starlite's HTTP exceptions.

### Health check

A health check route handler that returns some basic application info.

### Logging

Configures logging for the application including:

- Queue listener handler, appropriate for asyncio applications
- Health check route filter so that health check requests don't clog your logs
- An informative log format
- Configuration for dependency logs

### Openapi config

Configures OpenAPI docs for the application, including config by environment to allow for easy
personalization per application.

### Starlite Response class

A response class that can handle serialization of SQLAlchemy/Postgres UUID types.

### Sentry configuration

Just supply the DSN via environment, and Sentry is configured for you.

### SQLAlchemy

Engine, logging, pooling etc all configurable via environment. We configure starlite and include a
custom `before_send` wrapper that inspects the outgoing status code to determine whether the
transaction that represents the request should be committed, or rolled back.

### Async SAQ worker config

A customized SAQ queue and worker that is started and shutdown using the Starlite lifecycle event
hooks - no need to run your worker in another process, we attach it to the same event loop as the
Starlite app uses. Be careful not to do things in workers that will block the loop!

## Extra Features

In addition to application config, the library include:

### Repository

An abstract repository object type and a SQLAlchemy repository implementation.

### DTO Factory

A factory for building pydantic models from SQLAlchemy 2.0 style declarative classes. Use these to
annotate the `data` parameter and return type of routes to control the data that can be modified per
route, and the information included in route responses.

### HTTP Client and Endpoint decorator

`http.Client` is a wrapper around `httpx.AsyncClient` with some extra features including unwrapping
enveloped data, and closing the underlying client during shutdown of the Starlite application.

### ORM Configuration

A SQLAlchemy declarative base class that includes:

- a mapping of the builtin `UUID` type to the postgresql dialect UUID type.
- an `id` column
- a `created` timestamp column
- an `updated` timestamp column
- an automated `__tablename__` attribute
- a `from_dto()` class method, to ease construction of model types from DTO objects.

We also add:

- a `before_flush` event listener that ensures that the `updated` timestamp is touched on instances
  on their way into the database.
- a constraint naming convention so that index and constraint names are automatically generated.

### Service object

A Service object that integrates with the Repository ABC and provides standard logic for typical
operations.

### Settings

Configuration by environment.

## Contributing

All contributions big or small are welcome and appreciated! Please check out `CONTRIBUTING.md` for
specific information about configuring your environment and workflows used by this project.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/topsport-com-au/starlite-saqlalchemy",
    "name": "starlite-saqlalchemy",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "api,rest,http,asgi,starlite,saq,sqlalchemy,plugin,python",
    "author": "Peter Schutt",
    "author_email": "peter.github@proton.me",
    "download_url": "https://files.pythonhosted.org/packages/c7/f1/f2ec272c39789c2d01bae17f58e836abedba1f82fb64cc7dfaa0369a3cb5/starlite_saqlalchemy-0.30.0.tar.gz",
    "platform": null,
    "description": "<h1 align=\"center\">starlite-saqlalchemy</h1>\n<p align=\"center\">\n  <img src=\"https://www.topsport.com.au/assets/images/logo_pulse.svg\" width=\"200\" alt=\"TopSport Pulse\"/>\n</p>\n\n<p align=\"center\">\n  <a href=\"https://pypi.org/project/starlite-saqlalchemy\">\n    <img src=\"https://img.shields.io/pypi/v/starlite-saqlalchemy\" alt=\"PYPI: starlite-saqlalchemy\"/>\n  </a>\n  <a href=\"https://github.com/topsport-com-au/starlite-saqlalchemy/blob/main/LICENSE\">\n    <img src=\"https://img.shields.io/pypi/l/starlite-saqlalchemy?color=blue\" alt=\"License: MIT\"/>\n  </a>\n  <a href=\"https://python.org\">\n    <img src=\"https://img.shields.io/pypi/pyversions/starlite-saqlalchemy\" alt=\"Python: supported versions\"/>\n  </a>\n  <a href=\"https://results.pre-commit.ci/latest/github/topsport-com-au/starlite-saqlalchemy/main\">\n    <img alt=\"pre-commit.ci status\" src=\"https://results.pre-commit.ci/badge/github/topsport-com-au/starlite-saqlalchemy/main.svg\"/>\n  </a>\n  <a href=\"https://bestpractices.coreinfrastructure.org/projects/6646\">\n    <img alt=\"OpenSSF Best Practices\" src=\"https://bestpractices.coreinfrastructure.org/projects/6646/badge\">\n  </a>\n  <a href=\"https://github.com/topsport-com-au/starlite-saqlalchemy/actions/workflows/ci.yml\">\n    <img alt=\"Actions: CI\" src=\"https://github.com/topsport-com-au/starlite-saqlalchemy/actions/workflows/ci.yml/badge.svg?branch=main&event=push\"/>\n  </a>\n</p>\n<p align=\"center\">\n  <a href=\"https://sonarcloud.io/summary/new_code?id=topsport-com-au_starlite-saqlalchemy\">\n    <img alt=\"Reliability Rating\" src=\"https://sonarcloud.io/api/project_badges/measure?project=topsport-com-au_starlite-saqlalchemy&metric=reliability_rating\"/>\n  </a>\n  <a href=\"https://sonarcloud.io/summary/new_code?id=topsport-com-au_starlite-saqlalchemy\">\n    <img alt=\"Quality Gate Status\" src=\"https://sonarcloud.io/api/project_badges/measure?project=topsport-com-au_starlite-saqlalchemy&metric=alert_status\"/>\n  </a>\n  <a href=\"https://sonarcloud.io/summary/new_code?id=topsport-com-au_starlite-saqlalchemy\">\n    <img alt=\"Quality Gate Status\" src=\"https://sonarcloud.io/api/project_badges/measure?project=topsport-com-au_starlite-saqlalchemy&metric=coverage\"/>\n  </a>\n  <a href=\"https://sonarcloud.io/summary/new_code?id=topsport-com-au_starlite-saqlalchemy\">\n    <img alt=\"Quality Gate Status\" src=\"https://sonarcloud.io/api/project_badges/measure?project=topsport-com-au_starlite-saqlalchemy&metric=sqale_rating\"/>\n  </a>\n  <a href=\"https://sonarcloud.io/summary/new_code?id=topsport-com-au_starlite-saqlalchemy\">\n    <img alt=\"Quality Gate Status\" src=\"https://sonarcloud.io/api/project_badges/measure?project=topsport-com-au_starlite-saqlalchemy&metric=security_rating\"/>\n  </a>\n  <a href=\"https://sonarcloud.io/summary/new_code?id=topsport-com-au_starlite-saqlalchemy\">\n    <img alt=\"Quality Gate Status\" src=\"https://sonarcloud.io/api/project_badges/measure?project=topsport-com-au_starlite-saqlalchemy&metric=bugs\"/>\n  </a>\n  <a href=\"https://sonarcloud.io/summary/new_code?id=topsport-com-au_starlite-saqlalchemy\">\n    <img alt=\"Quality Gate Status\" src=\"https://sonarcloud.io/api/project_badges/measure?project=topsport-com-au_starlite-saqlalchemy&metric=vulnerabilities\"/>\n  </a>\n</p>\n\nConfiguration for a [Starlite](https://github.com/starlite-api/starlite) application that features:\n\n- SQLAlchemy 2.0\n- SAQ async worker\n- Lots of features!\n\n## Installation\n\nThis will install `starlite-saqlalchemy` with minimal dependencies.\n\n```console\npoetry add starlite-saqlalchemy\n```\n\nYou can also install additional dependencies depending on the features you need:\n\n```console\n# Repository implementation, DTOs\npoetry add starlite-saqlalchemy[sqlalchemy]\n# Async worker using saq\npoetry add starlite-saqlalchemy[worker]\n# Redis cache backend\npoetry add starlite-saqlalchemy[cache]\n# Sentry integration for starlite\npoetry add starlite-saqlalchemy[sentry]\n\n# or to install them all:\npoetry add starlite-saqlalchemy[all]\n```\n\n## Example\n\n```python\nfrom starlite import Starlite, get\n\nfrom starlite_saqlalchemy import ConfigureApp\n\n\n@get(\"/example\")\ndef example_handler() -> dict:\n    \"\"\"Hello, world!\"\"\"\n    return {\"hello\": \"world\"}\n\n\napp = Starlite(route_handlers=[example_handler], on_app_init=[ConfigureApp()])\n```\n\n## Features\n\nThe application configured in the above example includes the following configuration.\n\n### Logging after exception handler\n\nReceives and logs any unhandled exceptions raised out of route handling.\n\n### Redis cache\n\nIntegrates a Redis cache backend with Starlite first-class cache support.\n\n### Collection route filters\n\nSupport filtering collection routes by created and updated timestamps, list of ids, and limit/offset\npagination.\n\nIncludes an aggregate `filters` dependency to easily inject all filters into a route handler, e.g,:\n\n```python\nfrom starlite import get\nfrom starlite_saqlalchemy.dependencies import FilterTypes\n\n\n@get()\nasync def get_collection(filters: list[FilterTypes]) -> list[...]:\n    ...\n```\n\n### Gzip compression\n\nConfigures Starlite's built-in Gzip compression support.\n\n### Exception handlers\n\nException handlers that translate non-Starlite repository and service object exception\ntypes into Starlite's HTTP exceptions.\n\n### Health check\n\nA health check route handler that returns some basic application info.\n\n### Logging\n\nConfigures logging for the application including:\n\n- Queue listener handler, appropriate for asyncio applications\n- Health check route filter so that health check requests don't clog your logs\n- An informative log format\n- Configuration for dependency logs\n\n### Openapi config\n\nConfigures OpenAPI docs for the application, including config by environment to allow for easy\npersonalization per application.\n\n### Starlite Response class\n\nA response class that can handle serialization of SQLAlchemy/Postgres UUID types.\n\n### Sentry configuration\n\nJust supply the DSN via environment, and Sentry is configured for you.\n\n### SQLAlchemy\n\nEngine, logging, pooling etc all configurable via environment. We configure starlite and include a\ncustom `before_send` wrapper that inspects the outgoing status code to determine whether the\ntransaction that represents the request should be committed, or rolled back.\n\n### Async SAQ worker config\n\nA customized SAQ queue and worker that is started and shutdown using the Starlite lifecycle event\nhooks - no need to run your worker in another process, we attach it to the same event loop as the\nStarlite app uses. Be careful not to do things in workers that will block the loop!\n\n## Extra Features\n\nIn addition to application config, the library include:\n\n### Repository\n\nAn abstract repository object type and a SQLAlchemy repository implementation.\n\n### DTO Factory\n\nA factory for building pydantic models from SQLAlchemy 2.0 style declarative classes. Use these to\nannotate the `data` parameter and return type of routes to control the data that can be modified per\nroute, and the information included in route responses.\n\n### HTTP Client and Endpoint decorator\n\n`http.Client` is a wrapper around `httpx.AsyncClient` with some extra features including unwrapping\nenveloped data, and closing the underlying client during shutdown of the Starlite application.\n\n### ORM Configuration\n\nA SQLAlchemy declarative base class that includes:\n\n- a mapping of the builtin `UUID` type to the postgresql dialect UUID type.\n- an `id` column\n- a `created` timestamp column\n- an `updated` timestamp column\n- an automated `__tablename__` attribute\n- a `from_dto()` class method, to ease construction of model types from DTO objects.\n\nWe also add:\n\n- a `before_flush` event listener that ensures that the `updated` timestamp is touched on instances\n  on their way into the database.\n- a constraint naming convention so that index and constraint names are automatically generated.\n\n### Service object\n\nA Service object that integrates with the Repository ABC and provides standard logic for typical\noperations.\n\n### Settings\n\nConfiguration by environment.\n\n## Contributing\n\nAll contributions big or small are welcome and appreciated! Please check out `CONTRIBUTING.md` for\nspecific information about configuring your environment and workflows used by this project.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Starlite config plugin with SAQ and SQLAlchemy boilerplate",
    "version": "0.30.0",
    "split_keywords": [
        "api",
        "rest",
        "http",
        "asgi",
        "starlite",
        "saq",
        "sqlalchemy",
        "plugin",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ad9b2930a0e974023a68fe0d9acf570baf093683d83ffa0a2aa9663750573be6",
                "md5": "a8c99f1bbd22163cd55b55b31cdab16f",
                "sha256": "ca826dab832863674d6ab192c355ba62864336cfbbee90c7b8cbaba275db00f6"
            },
            "downloads": -1,
            "filename": "starlite_saqlalchemy-0.30.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a8c99f1bbd22163cd55b55b31cdab16f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 60674,
            "upload_time": "2023-03-10T23:53:05",
            "upload_time_iso_8601": "2023-03-10T23:53:05.249513Z",
            "url": "https://files.pythonhosted.org/packages/ad/9b/2930a0e974023a68fe0d9acf570baf093683d83ffa0a2aa9663750573be6/starlite_saqlalchemy-0.30.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c7f1f2ec272c39789c2d01bae17f58e836abedba1f82fb64cc7dfaa0369a3cb5",
                "md5": "806f0c4a20d08267614717f23db9f0d2",
                "sha256": "1768015734ac9e155c023ad00b58c5cf588b8ca31aaaadd6f558408a36787532"
            },
            "downloads": -1,
            "filename": "starlite_saqlalchemy-0.30.0.tar.gz",
            "has_sig": false,
            "md5_digest": "806f0c4a20d08267614717f23db9f0d2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 46196,
            "upload_time": "2023-03-10T23:53:06",
            "upload_time_iso_8601": "2023-03-10T23:53:06.887740Z",
            "url": "https://files.pythonhosted.org/packages/c7/f1/f2ec272c39789c2d01bae17f58e836abedba1f82fb64cc7dfaa0369a3cb5/starlite_saqlalchemy-0.30.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-10 23:53:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "topsport-com-au",
    "github_project": "starlite-saqlalchemy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "starlite-saqlalchemy"
}
        
Elapsed time: 0.04301s