Package: aiohttp-devtools
Dev tools foraiohttp.aiohttp-devtoolsprovides a number of tools useful when developing applications with aiohttp and associated
libraries.Installationpipinstallaiohttp-devtoolsUsageTheaiohttp-devtoolsCLI (and it’s shorter aliasadev) consist of two sub-commands:runserverandserve.runserverProvides a simple local server for running your application while you’re developing.Usage is simplyadevrunserver<app-path>Note:adev runserver<app-path>will import the whole file, hence it doesn’t work
withweb.run_app(app). You can however useif __name__ == '__main__': web.run_app(app).app-pathcan be a path to either a directory containing a recognized default file (app.pyormain.py) or to a specific file. The--app-factoryoption can be used to define which method is called
from the app path file, if not supplied some default method names are tried
(namelyapp,app_factory,get_appandcreate_app, which can be
variables, functions, or coroutines).Allrunserverarguments can be set via environment variables.runserverhas a few useful features:livereloadwill reload resources in the browser as your code changes without having to hit refresh, seelivereloadfor more details.static filesare served separately from your main app (generally on8001while your app is on8000) so you don’t have to contaminate your application to serve static files you only need locally.For more options seeadev runserver--help.serveSimilar torunserverexcept just serves static files.Usage is simplyadevserve<path-to-directory-to-serve>Likerunserveryou get nice live reloading and access logs. For more options seeadev serve--help.TutorialTo demonstrate what adev can do when combined with create-aio-app, let’s walk through creating a new application:First let’s create a clean python environment to work in and install aiohttp-devtools and create-aio-app.(it is assumed you’ve already gotpython,pipandvirtualenvinstalled)mkdirmy_new_app&&cdmy_new_appvirtualenv-p`whichpython3`env.env/bin/activatepipinstallaiohttp-devtoolscreate-aio-appWe’re now ready to build our new application withcreate-aio-appand we’ll name the
projectmy_new_appafter the current directory.We’re going to explicitly choose no database here to make this tutorial easier, but you can remove that option
and choose to use a proper database if you like.You can just hit return to choose the default for all the options.create-aio-appmy_new_app--without-postgresThat’s it, your app is now created. You might want to have a look through the local directory’s file tree.Before you can run your app you’ll need to install the other requirements, luckily they’ve already been listed inrequirements/development.txtbycreate-aio-app, to install simply runpipinstall-rrequirements/development.txtYou can then run your app with just:adevrunserverWith that:your app should be being served atlocalhost:8000(you can go and play with it in a browser).Your static files are being served atlocalhost:8001, adev has configured your app to know that so it should be rendering properly.any changes to your app’s code (.pyfiles) should cause the server to reload, changes to any files
(.pyas well as.jinja,.js,.cssetc.) will cause livereload to prompt your browser to reload the required pages.That’s it, go develop.