Igor Davydenko:Igor Davydenko Open Source Projects

rororo

OpenAPI 3 schema support for aiohttp.web applications.

Usage

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")
        return web.json_response({"message": f"Hello, {name}!"})


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

aiohttp-middlewares

Collection of useful middlewares for aiohttp.web applications.

Usage

from aiohttp import web
from aiohttp_middlewares import (
    cors_middleware,
    error_middleware,
    https_middleware,
    IDEMPOTENT_METHODS,
    shield_middleware,
    timeout_middleware
)


app = web.Application(
    middlewares=(
        # Change schema of current request if
        # X-Forwarded-Schema: https header is present
        https_middleware(),

        # Allow CORS headers for all requests from
        # http://localhost:800
        cors_middleware(origins=("http://localhost:8000",)),

        # Ensure all exceptions will result in predefined
        # JSON response
        error_middleware(),

        # Shield idempotent methods against canceled errors
        shield_middleware(methods=IDEMPOTENT_METHODS),

        # Ensure that handler will not execute for more
        # than 29.5 seconds
        timeout_middleware(29.5),
    )
)

Others

Over the years I’ve contributed to several Open Source projects, most notably of: aiohttp & typeshed.

I have also created some extensions for Django & Flask web frameworks & other libraries for Python developers. However, many of those projects are not in use anymore and as result are not actively maintained.

For full list of my projects, please go to my Github profile: @playpauseandstop. You might interested in my gists as well.