Skip to main content

Modest utility collection for development with AIOHTTP framework.

Project description

Read The Docs build Release MIT License Python version support PyPI downloads count GitHub continuous integration

Modest utility collection for development with AIOHTTP framework.

Documentation

https://aiohttp-things.readthedocs.io

Installation

Installing aiohttp-things with pip:

pip install aiohttp-things

Simple example

Example of AIOHTTP application

import json
import uuid
import aiohttp_things as ahth
from aiohttp import web


def safe_json_value(value):
    try:
        json.dumps(value)
        return value
    except (TypeError, OverflowError):
        return str(value)


class Base(web.View, ahth.JSONMixin, ahth.PrimaryKeyMixin):
    async def get(self):
        self.context['Type of primary key'] = safe_json_value(type(self.pk))
        self.context['Value of primary key'] = safe_json_value(self.pk)
        return await self.finalize_response()


class IntegerExample(Base):
    pk_adapter = int


class UUIDExample(Base):
    pk_adapter = uuid.UUID


UUID = '[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}'
ROUTES = [
    web.view('/integer/{pk:[0-9]+}', IntegerExample),
    web.view(f'/uuid/{{pk:{UUID}}}', UUIDExample),
]


async def app_factory():
    app = web.Application()
    app.add_routes(ROUTES)
    return app


if __name__ == '__main__':
    web.run_app(app_factory())

Examples HTTP requests and response

  • http://0.0.0.0:8080/integer/1

    {
      "Type of primary key": "<class 'int'>",
      "Value of primary key": 1
    }
  • http://0.0.0.0:8080/integer/9999999999999

    {
      "Type of primary key": "<class 'int'>",
      "Value of primary key": 9999999999999
    }
  • http://0.0.0.0:8080/integer/a352da04-c1af-4a44-8a94-c37f8f37b2bc

    404: Not Found
  • http://0.0.0.0:8080/integer/abc

    404: Not Found
  • http://0.0.0.0:8080/uuid/a352da04-c1af-4a44-8a94-c37f8f37b2bc

    {
      "Type of primary key": "<class 'uuid.UUID'>",
      "Value of primary key": "a352da04-c1af-4a44-8a94-c37f8f37b2bc"
    }
  • http://0.0.0.0:8080/uuid/13d1d0e0-4787-4feb-8684-b3da32609743

    {
      "Type of primary key": "<class 'uuid.UUID'>",
      "Value of primary key": "13d1d0e0-4787-4feb-8684-b3da32609743"
    }
  • http://0.0.0.0:8080/uuid/1

    404: Not Found
  • http://0.0.0.0:8080/uuid/abc

    404: Not Found

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

aiohttp_things-1.2.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiohttp_things-1.2.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp_things-1.2.0.tar.gz.

File metadata

  • Download URL: aiohttp_things-1.2.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.3 Linux/6.8.0-90-generic

File hashes

Hashes for aiohttp_things-1.2.0.tar.gz
Algorithm Hash digest
SHA256 b96a75e8985eb79dd501347d019d12c525121355314d26e1a360791a326895e5
MD5 956fbec70a84223d8355b9e7f5efc530
BLAKE2b-256 a796c05ccd1970cb9caf422b2f2dad8a1ce98bf15a70f15662ca56a272d404e9

See more details on using hashes here.

File details

Details for the file aiohttp_things-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: aiohttp_things-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.3 Linux/6.8.0-90-generic

File hashes

Hashes for aiohttp_things-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f693215701a63e666691b2371814dfa3be71f897734407ae0cb29e7b6bc79e3e
MD5 0a15501e48739674395d57ccedabf460
BLAKE2b-256 9f26e9d40b88253901ed6a9f48d947cb36eeafd9216b3531e019a42bcd79d3be

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page