Fat and opinionated cookiecutter template for building async Web Apps powered by Aiohttp, SQLAlchemy and Swagger.
Check out the features section below for a short description of what this box packs for you.
Makefilealready implemented for you
make helpto get more info about the CLI features
make helpto display all available commands
make installcommand: creates the app virtualenv and resolves its dependencies
make install-dev: creates the testing virtualenv and resolves its dev-dependencies, i.e.: pytest … etc
First, grab cookiecutter if you don’t have it and start the generation process:
$ pip install cookiecutter $ cookiecutter https://github.com/aalhour/cookiecutter-aiohttp-sqlalchemy
Second, setup virtual environment and install requirements:
$ make install
Third, copy the config file template over to
~/.config/<your-app-name>.conf. It is important that the file name matches the application name you entered in the cookiecutter generation process:
$ cp config/example.conf ~/.config/<your-app-name>.conf
Next thing is, you need to customize your config file and enter your database details under the
[db] section, please follow the config file:
$ cat ~/.config/<your-app-name>.conf [db] host = localhost port = 5432 name = <database_name> schema = <schema_name> user = <database_user>
Fourth and last step, start the application using the Pythonic entry point:
The following is an example API code that tries to query the database using an SQLAlchemy Declarative Model:
class UsersApi: async def get_user_by_id(self, request): user_id = request.match_info.get('id') async with transactional_session() as db: # `User` is an SQLAlchemy declarative class user = await User.get_by_id(user_id, db) return self.json_response(user.serialized)
If you want to see a working example web app generated using this cookiecutter-template, then please head over to /examples directory.