Skip to main content

Provides integrations of classic libs with Falcon web framework

Project description

Classic Falcon Integration

Предоставляет простую интеграцию веб-фреймворка Falcon, orjson и classic-error-handling.

Установка

pip install classic-falcon-integration

Quickstart

from falcon import App, Request, Response
from pydantic import BaseModel
import waitress

from classic.components import component
from classic.falcon_integration import register_all
from classic import db_tools


class Pet(BaseModel):
    id: int
    name: str
    age: int


class FilterPets(BaseModel):
    name__contains: list[str] | None = None
    age__le: int | None = None
    age__gt: int | None = None
    id: int | None = None


class NewPet(BaseModel):
    name: str
    age: int


@component
class PetsResource:
    db: db_tools.Engine

    def on_get(self, request: Request, response: Response):
        # Валидация по спецификации отключена по умолчанию,
        # потому вызов валидации обязательно добавлять вручную.
        # Валидацию лучше сего проводить через model_validate,
        # так как далее данные все равно будут переданы в виде dict
        FilterPets.model_validate(request.params)

        # Здесь приведен пример работы с БД с classic-db-tools,
        # но здесь может быть что угодно
        with self.db:
            response.media = self.db.queries.filter_pets(
                **request.params
            ).return_as(
                db_tools.ToCls(Pet, id='id'),
                returns=Pet,
            ).many()

    def on_post(self, request: Request, response: Response):
        NewPet.model_validate(request.media)
        with self.db:
            response.media = self.db.queries.save_pet(
                **request.media,
            )


if __name__ == '__main__':
    app = App()
    app.add_route('/api/pets', PetsResource())
    register_all(app)

    waitress.serve(
        app,
        host='127.0.0.1',
        port='8000',
    )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

classic_falcon_integration-2.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

classic_falcon_integration-2.0.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file classic_falcon_integration-2.0.0.tar.gz.

File metadata

File hashes

Hashes for classic_falcon_integration-2.0.0.tar.gz
Algorithm Hash digest
SHA256 fed07fe0bfc6cca94152fb91fabb5a69041e4afc5a310dab57ffd6dcae8b62ba
MD5 44df9090812d9967f1d48163e92d0d7b
BLAKE2b-256 873b8248f44f3287c482169a1d2a6df4fa17fd334934dea1fcc6ebfa802dfc69

See more details on using hashes here.

Provenance

The following attestation bundles were made for classic_falcon_integration-2.0.0.tar.gz:

Publisher: publish.yml on variasov/classic-falcon-integration

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file classic_falcon_integration-2.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for classic_falcon_integration-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f58d5f29a461799f75c2e3ebc92bde3587c3fd5c40ac901fa723ce270ac82a26
MD5 a128e2d385506164ecdd900c2822c039
BLAKE2b-256 12c467cecc9b36dff11b2b2e0e8a079cfa9d6c6e16ed3879497f0c4eb7d88ba0

See more details on using hashes here.

Provenance

The following attestation bundles were made for classic_falcon_integration-2.0.0-py3-none-any.whl:

Publisher: publish.yml on variasov/classic-falcon-integration

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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