Skip to main content


Project description


version pipeline status coverage report


  • Unpack aiohttp (>=3.1) request to arguments with annotations
  • Validate handlers arguments
  • Generate swagger specification


Arguments from path and query

from aiohttp import web
from aiohug import RouteTableDef

routes = RouteTableDef()

async def hello(name: fields.String(), greeting: fields.String() = "Hello"):
    return {"msg": f"{greeting}, {name}"}

app = web.Application()

if __name__ == "__main__":

There is no request object in handler signature anymore - only required arguments.

Body with schema

from aiohttp import web
from aiohug import RouteTableDef

routes = RouteTableDef()

class PayloadSchema(Schema):
    count = fields.Int()

async def with_body(body: PayloadSchema()):
    return body

app = create_app()

client = await test_client(app)
resp = await client.get("/", json={"count": "5", "another": 7})

assert await resp.json() == {"count": 5}

Another shortcuts"/ping/")
async def ping():
  return 201, "pong"


Use aiohug_swagger package.


Because of the way aiohttp routing works all decorators to resource handlers must be applied BEFORE aiohug’s routing decorator, i.e.

def some_decorator(func):

 def wrapper(request, *args, **kwargs):
     # Some logic for decorator
     return func(*args, **kwargs)

 return wrapper

 async def hello():
     return "pong"

Moreover, make sure to decorate wrapper functions with wraps decorator from functools module - otherwise aiohug won’t be able to access original handler’s arguments and annotations.

Why aiohug?

It’s just hug API implementation for aiohttp


  • don’t pass default arguments

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

aiohug-0.7.1.tar.gz (7.4 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page