Skip to main content

Dev tools for aiohttp

Project description

Travis status for master branch AppVeyor status for master branch Coverage pypi license

Dev tools for aiohttp.

(Note: aiohttp-devtools>=0.8 only supports aiohttp>=3.0, if you’re using older aiohttp, please use an older version of aiohtt-devtools, see History.rst for details.)

aiohttp-devtools provides a number of tools useful when developing applications with aiohttp and associated libraries.

Installation

Requires python 3.5 or python 3.6.

pip install aiohttp-devtools

Usage

The aiohttp-devtools CLI (and it’s shorter alias adev) consist of three sub-commands: runserver, serve and start.

runserver

Provides a simple local server for running your application while you’re developing.

Usage is simply

adev runserver <app-path>

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.

All runserver arguments can be set via environment variables, the start command creates a script suitable for setting up your environment such that you can run the dev server with just adev runserver.

runserver has a few of 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.

start

Creates a new bare bones aiohttp app similar to django’s “startproject”.

Usage is simply

adev start <path-to-directory-to-create-project-in>

You’re then asked a bunch of questions about the the application you’re about to create, you get to choose:

  • Template Engine, options are

    • jinja views are rendered using Jinja2 templates via aiohttp_jinja2.

    • none views are rendered directly.

  • Session, options are

    • secure will implemented encrypted cookie sessions using aiohttp_session.

    • none - session are not implemented

  • Database, options are:

    • pg-sqlalchemy will use postgresql via aiopg and the SqlAlchemy ORM.

    • none will use no database, persistence in examples is achieved by simply writing to file. This is a quick way to get started but is obviously not suitable for production use!

  • Example, the newly created app can include some basic functionality

    • message board: which demonstrates a little of aiohttp’s usage. Messages can be added via posting to a form, are stored in the database and then displayed in a list, if available the session is used to pre-populate the user’s name.

    • none: no example, just a single simple view is created.

For more options see adev start --help, or just run adev start foobar and follow instructions.

Tutorial

To demonstrate what adev can do, let’s walk through creating a new application:

First let’s create a clean python environment to work in and install aiohttp-devtools.

(it is assumed you’ve already got python 3.5, pip and virtualenv installed)

mkdir my_new_app && cd my_new_app
virtualenv -p `which python3.5` env
. env/bin/activate
pip install aiohttp-devtools

We’re now ready to build our new application with start, using the current directory . will put files where we want them and will prompt adev to 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.

adev start . --database none

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.txt by start, to install simply run

pip install -r requirements.txt

(If you went off-piste and choose to use a database you’ll need to edit activate.settings.sh to configure connection settings, then run make reset-database to create a database.)

You can then run your app with just:

source activate.settings.sh
adev runserver

runserver uses the environment variables set in activate.settings.sh to decide how to serve your app.

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


Download files

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

Source Distribution

aiohttp-devtools-0.10.4.tar.gz (35.1 kB view details)

Uploaded Source

Built Distribution

aiohttp_devtools-0.10.4-py35.py36-none-any.whl (45.8 kB view details)

Uploaded Python 3.5 Python 3.6

File details

Details for the file aiohttp-devtools-0.10.4.tar.gz.

File metadata

  • Download URL: aiohttp-devtools-0.10.4.tar.gz
  • Upload date:
  • Size: 35.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for aiohttp-devtools-0.10.4.tar.gz
Algorithm Hash digest
SHA256 38b8fa340b3bfa077483f1b46f7386d6aac787cef2b6e44d116eec69dbeb1b04
MD5 e5cf69b6edca2d9e1d04b05592306939
BLAKE2b-256 7a0ba08a87e55f2aa53e31c8d0df5e35f1be816e90a6a284fe081dcf17252617

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp_devtools-0.10.4-py35.py36-none-any.whl.

File metadata

  • Download URL: aiohttp_devtools-0.10.4-py35.py36-none-any.whl
  • Upload date:
  • Size: 45.8 kB
  • Tags: Python 3.5, Python 3.6
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3

File hashes

Hashes for aiohttp_devtools-0.10.4-py35.py36-none-any.whl
Algorithm Hash digest
SHA256 ac5c58896d17be48225a32e8435beffd63f749d92dbc1c4fdc58700dffd7248d
MD5 7d258739cbc5009ddc85a922ab5af48c
BLAKE2b-256 05a9610dd63ee8c3953226eba565ebb1e98667e6f538a8e0db9aafd514d400ef

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page