Skip to main content

aiohug

Project description

aiohug

pipeline status coverage report

Tasks:

  • Unpack aiohttp request to arguments with annotations

  • Validate handlers arguments

  • Generate swagger specification

Examples

Run ping pong application

from aiohttp import web
from aiohug import RouteTableDef

routes = RouteTableDef()


@routes.get("/ping/")
async def ping():
  return "pong"


app = web.Application()
app.add_routes(routes)


if __name__ == "__main__":
    web.run_app(app)

There is no more request object in handler.

Arguments from path and query

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

Body with schema

from aiohttp import web
from aiohug import RouteTableDef

routes = RouteTableDef()

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

@routes.get("/")
async def with_body(body: PayloadSchema()):
    return body

app = create_app()
app.add_routes(routes)

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

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

TODO:

  • don’t pass default arguments

  • pretty error message

  • default websocket handler with ping/pong and schemas support

ws = aiohug.WSHandler()


@ws("hello")  # match message by `type` field
async def hello(name: str, greeting: str="Hi"):
    """ Just send {"type": "hello", "name": "Lucy", "greeting": "Hi"} """
    return {"text", f"{greeting}, {name}"}


app = create_app()
app.add_routes([web.get('/ws', ws)])
  • optional response code shortcut

@routes.get("/ping/")
async def ping():
  return 201, "pong"

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.3.1.dev28385241.tar.gz (8.5 kB view details)

Uploaded Source

File details

Details for the file aiohug-0.3.1.dev28385241.tar.gz.

File metadata

  • Download URL: aiohug-0.3.1.dev28385241.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.7.0

File hashes

Hashes for aiohug-0.3.1.dev28385241.tar.gz
Algorithm Hash digest
SHA256 530e0be47adea5530e29bf9a282248f59b1adb7016e467d491253743e4fe8756
MD5 cc1cb423609593847944ea3e5b1d16ae
BLAKE2b-256 7f029bd526102519ed34af1cce879e16e009f4ecc307c710a12b25e0cf5b72da

See more details on using hashes here.

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