Modest utility collection for development with AIOHTTP framework.
Project description
Modest utility collection for development with AIOHTTP framework.
Documentation
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
Release history Release notifications | RSS feed
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.0.1.tar.gz
(5.2 kB
view details)
Built Distribution
File details
Details for the file aiohttp_things-1.0.1.tar.gz
.
File metadata
- Download URL: aiohttp_things-1.0.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-45-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c38935f36337083cf379aa5bb524752f8ea25e6d5f041e8664e4344d76325b5e |
|
MD5 | 76a3aa6054a33fa75a880d39d80c4434 |
|
BLAKE2b-256 | bad5fb9b4872d10bf913088e083e4935e9238b27cd3ea4867f11ed9da601911f |
File details
Details for the file aiohttp_things-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: aiohttp_things-1.0.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-45-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2cf8c5c44748b7516587793c19042db4dc68689fc91a1add4356d126923acffe |
|
MD5 | 04d657b57c059c716a5cedf90e1055e9 |
|
BLAKE2b-256 | 3663d556370e7d0ee6d8fe3ee2d5da00fe7e8c1d1db721452eecba5376ceab42 |