Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

aiohug
======

|pipeline status| |coverage report|

.. |pipeline status| image:: https://gitlab.com/nonamenix/aiohug/badges/master/pipeline.svg
:target: https://gitlab.com/nonamenix/aiohug/commits/master
.. |coverage report| image:: https://gitlab.com/nonamenix/aiohug/badges/master/coverage.svg
:target: https://gitlab.com/nonamenix/aiohug/commits/master

Goals:
=====

- Unpack aiohttp request to arguments with annotations
- Validate handlers arguments
- Generate swagger specification

Examples
========

Run ping pong application
-------------------------

.. code:: python

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
-----------------------------

.. code:: python


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

Body with schema
----------------

.. code:: python

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}

Another shortcuts
-----------------

.. code:: python

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

Swagger
-------

Use aiohug_swagger_ package.

.. _aiohug_swagger: https://github.com/nonamenix/aiohug_swagger


Why aiohug?
===========

It's just hug_ API implementation for aiohttp

.. _hug: https://github.com/timothycrosley/hug

TODO:
=====

- don’t pass default arguments
- default websocket handler with ping/pong and schemas support

.. code:: python

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)])

Release files for aiohug 0.4.0.dev37785294

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiohug 0.4.0.dev37785294
File Size Uploaded
aiohug-0.4.0.dev37785294.tar.gz 6.3 kB Details

Release files / aiohug-0.4.0.dev37785294.tar.gz

Download URL aiohug-0.4.0.dev37785294.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e93f506c1f93cde477bd21e36be41af1e20815eac0a8a57f7819e85102c34bf4
BLAKE2b-256 checksum
How to use checksums
f927d1a52c124c5e31e8b731dac94cd42cb052b9ddd4dc1be4fe6179a5be5845
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1

Release history Release notifications | RSS feed

0.7.1

1 release file

0.7

1 release file

0.6.4

1 release file

0.6.1

1 release file

0.5

1 release file

0.4.2

1 release file

0.4.0

1 release file

This release

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page