Skip to main content

RESTful endpoints for aoihttp that bind directly to a model

Project description

aiohttp_rest makes it easy to create RESTful aiohttp endpoints that bind directly to models with minimal modification.


Create your model:

class Person:
    def __init__(self, name, age): = name
        self.age = age

Create an aiohttp application that makes use of a aiohttp_rest.RestResource:

from aiohttp.web import Application, run_app
from aiohttp_rest import RestResource

from person import Person

people = {}

app = Application()
person_resource = RestResource('people', people, Person, ('name', 'age'), 'name')


Interact with the API:

http POST localhost:8000/people name=andrew age=24
http localhost:8000/people/andrew
http PUT localhost:8000/people/andrew/age age=25
http DELETE localhost:8000/people/andrew

Several things are required by the RestResource to make all this work:

  • A name for the resource, this will form the base of the URL.
  • A factory method for the model, as seen above, this can simply be the init method for the model or something more complex.
  • A collection to store the models, this should be a dict-like object.
  • A list of properties to expose to the API.
  • A property to treat as the id for the collection. In the above example we used the name as the id, so that’s what we used in our URLs to refer to a specific instance in the collection.


git clone
cd aiohttp_rest
python install


pip install -r build-requirements.txt
py.test tests



Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for aiohttp-rest, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size aiohttp-rest-0.1.0.tar.gz (6.8 kB) File type Source Python version None Upload date Hashes View

Supported by

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