Dev tools for aiohttp
Project description
Dev tools for aiohttp.
aiohttp-devtools provides a number of tools useful when developing applications with aiohttp and associated libraries.
Installation
pip install aiohttp-devtools
Usage
The aiohttp-devtools CLI (and it’s shorter alias adev) consist of two sub-commands: runserver and serve.
runserver
Provides a simple local server for running your application while you’re developing.
Usage is simply
adev runserver <app-path>
Note: adev runserver <app-path> will import the whole file, hence it doesn’t work with web.run_app(app). You can however use if __name__ == '__main__': web.run_app(app).
app-path can be a path to either a directory containing a recognized default file (app.py or main.py) or to a specific file. The --app-factory option can be used to define which method is called from the app path file, if not supplied some default method names are tried (namely app, app_factory, get_app and create_app, which can be variables, functions, or coroutines).
All runserver arguments can be set via environment variables.
runserver has a few useful features:
livereload will reload resources in the browser as your code changes without having to hit refresh, see livereload for more details.
static files are served separately from your main app (generally on 8001 while your app is on 8000) so you don’t have to contaminate your application to serve static files you only need locally.
For more options see adev runserver --help.
serve
Similar to runserver except just serves static files.
Usage is simply
adev serve <path-to-directory-to-serve>
Like runserver you get nice live reloading and access logs. For more options see adev serve --help.
Tutorial
To 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 got python, pip and virtualenv installed)
mkdir my_new_app && cd my_new_app
virtualenv -p `which python3` env
. env/bin/activate
pip install aiohttp-devtools create-aio-app
We’re now ready to build our new application with create-aio-app and we’ll name the project my_new_app after 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-app my_new_app --without-postgres
That’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 in requirements/development.txt by create-aio-app, to install simply run
pip install -r requirements/development.txt
You can then run your app with just:
adev runserver
With that:
your app should be being served at localhost:8000 (you can go and play with it in a browser).
Your static files are being served at localhost:8001, adev has configured your app to know that so it should be rendering properly.
any changes to your app’s code (.py files) should cause the server to reload, changes to any files (.py as well as .jinja, .js, .css etc.) will cause livereload to prompt your browser to reload the required pages.
That’s it, go develop.
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
Built Distribution
File details
Details for the file aiohttp-devtools-1.1.1.tar.gz
.
File metadata
- Download URL: aiohttp-devtools-1.1.1.tar.gz
- Upload date:
- Size: 37.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 735ab26b5f135a4058181924ccc839a3ca155bc1ce8aa0bd0e8c521591a9eb65 |
|
MD5 | 91cd70860263ff0cb1381aa234d957bf |
|
BLAKE2b-256 | 45dcb3f41aab488d024f4cff584241e4c9b9e2309750e391d5116cd6d640e3bc |
Provenance
File details
Details for the file aiohttp_devtools-1.1.1-py38.py39.py310.py311-none-any.whl
.
File metadata
- Download URL: aiohttp_devtools-1.1.1-py38.py39.py310.py311-none-any.whl
- Upload date:
- Size: 31.6 kB
- Tags: Python 3.10, Python 3.11, Python 3.8, Python 3.9
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9911da1dafe60b3c7011c88f6cfff130093e8dbc0168c99f008716d63cfadf80 |
|
MD5 | 78df8a04351c6da975eee60ef1ad12cd |
|
BLAKE2b-256 | 7bbe700b5df01e762e2464b644c03d4825c3837731a19568731c38eaf5c3f0b5 |