Skip to main content

aiohttp.web OpenAPI 3 schema first server applications.

Project description

CI Workflow pre-commit black Latest Version Python versions BSD License Coverage Documentation

Implement aiohttp.web OpenAPI 3 server applications with schema first approach.

As well as bunch other utilities to build effective server applications with Python 3 & aiohttp.web.

Quick Start

rororo relies on valid OpenAPI 3 schema file (both JSON or YAML formats supported).

Example below, illustrates on how to handle operation hello_world from openapi.yaml schema file.

from pathlib import Path
from typing import List

from aiohttp import web
from rororo import (
    openapi_context,
    OperationTableDef,
    setup_openapi,
)


operations = OperationTableDef()


@operations.register
async def hello_world(request: web.Request) -> web.Response:
    with openapi_context(request) as context:
        name = context.parameters.query.get("name", "world")
        email = context.parameters.query.get(
            "email", "world@example.com"
        )
        return web.json_response(
            {"message": f"Hello, {name}!", "email": email}
        )


def create_app(argv: List[str] = None) -> web.Application:
    return setup_openapi(
        web.Application(),
        Path(__file__).parent / "openapi.yaml",
        operations,
        server_url="/api",
    )

Schema First Approach

Unlike other popular Python OpenAPI 3 solutions, such as Django REST Framework, FastAPI, flask-apispec, or aiohttp-apispec rororo requires you to provide valid OpenAPI 3 schema first. This makes rororo similar to connexion, pyramid_openapi3 and other schema first libraries.

Class Based Views

rororo supports class based views as well. Todo-Backend example illustrates how to use class based views for OpenAPI 3 servers.

In snippet below, rororo expects that OpenAPI 3 schema contains operation ID UserView.get,

@operations.register
class UserView(web.View):
    async def get(self) -> web.Response:
        ...

More Examples

Check examples folder to see other examples on how to build aiohttp.web OpenAPI 3 server applications.

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

rororo-3.0.1.tar.gz (38.7 kB view details)

Uploaded Source

Built Distribution

rororo-3.0.1-py3-none-any.whl (43.3 kB view details)

Uploaded Python 3

File details

Details for the file rororo-3.0.1.tar.gz.

File metadata

  • Download URL: rororo-3.0.1.tar.gz
  • Upload date:
  • Size: 38.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for rororo-3.0.1.tar.gz
Algorithm Hash digest
SHA256 c53e062dc78e1c4b9e1d8eb1bc446c99dadec33b24dbb2ed8cea6201ec3035e3
MD5 ff9445592719fa808858c33afb6581e1
BLAKE2b-256 d466010bc8ccdb78625d76fd335671a82ad609e8447e475f80e5ea3d039e6c6c

See more details on using hashes here.

Provenance

File details

Details for the file rororo-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: rororo-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 43.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for rororo-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cc6c0a555072e374763c41932428e7c046d392c43576aa2ae5ae32a2cdb24197
MD5 0a963648d3186106fe4e249df6580a03
BLAKE2b-256 d32a081fe95d8436246266a84ace1fdfad84b34e89872436e0188c36d1b2d857

See more details on using hashes here.

Provenance

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