Python Instance


  • Familiarity with the Python coding language and WSGI protocol
  • Your application must have a WSGI entry point
  • You must be familiar with Git

Version support

At the time of this article's writing, Gandi's Python instance supports Python versions 3.6 and 2.7. To choose, see "Python Version Selection" below.

Basic Use

Your Python app must contain at least one file named, which itself must contain the application object, in accordance with the PEP agreement specified here:

The Vhosts

Unlike PHP instances, adding a site to a Python instance via the Gandi interface does not involve creating a new directory on the instance to store the application source code. There is instead only one “default” vhost, where you can upload and store application code. Also in contrast to other instance types, Python instances support only one application per instance. This application can be used to control the allocation of virtual hosts, allowing you the same scaling of sites and vhosts as the other instance types.

It will still be necessary to add the various sites to the instance in DNS, using the procedure described here.

A simple example:

Directory layout

    def application(environ, start_response):
        start_response('200 OK', [('Content-Type', 'text/html; charset=utf-8')])
        return ['<!DOCTYPE html><html><meta charset="utf-8"><title>It works',
                '</title><h1>It works!</h1>']

Application dependencies

Your application's dependencies have to be installable with “pip”, and must be specified in a file named “requirements.txt”. For the dependencies to be automatically installed, you need to deploy the code with GIt. As you develop your application on a local machine, install the dependencies with “pip install”. Then, when your application is ready to go into production , run the following command locally to generate a file containing all the dependencies:

$ pip freeze > requirements.txt

This command will populate the ' requirements.txt ' file with modules and dependencies based on those you have installed on your development environment. This file should then be placed on the Simple Hosting instance, at the root of the 'default' directory to ensure dependencies are installed automatically when you deploy the application. You must use Git to commit and push this file to the instance for it to be used.

For more information, see:

For more information on deploying your application with Git, see: your Git access

Python version selection

It is possible to choose the version of Python that you want to use to execute your application from the available versions we offer. To do this, you will need to specify the Python version that you want to use in the “gandi.yml” file that is located at the root of your project, via the “python” field:


  version: 3.6

The above example will force the usage of Python 3.6. If the file exists but there is no “python” field, or in the event that the yaml format is invalid, the default version will be used. If an invalid value is specified, your application will not boot and an error message will be displayed in the deployment logs of your application and in the boot logs of your instance.

This file, as every other files composing your project, needs to be tracked by Git and pushed to your Simple Hosting remote repository before issuing a deploy command.

Static Files

Place all of your static content in the '/static/' and '/media/' directories, so the Apache HTTPD server can pick them up.


The standard error output from your application will be sent to the following files on your instance's disk:

  • from the SSH console: /srv/data/var/log/www/uwsgi.log
  • over SFTP: /lamp0/var/log/www/uwsgi.log

You can use these files to monitor the successful start of your application.

You also have the option of configuring the logger to fit your needs. Add a file called 'logging.ini ' to the 'default' root to do so.

For more information, see:


An example Flask application

Directory layout
├── requirements.txt
├── static/
├── templates/

    from minitwit import app as application



A Django example

Directory layout
├── media/
├── cms/
│   ├──
│   └── cms/
│       ├──
│       ├──
│       ├── templates/
│       └──
├── requirements.txt
├── static/

    import sys
    import os
    import os.path
    sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__),
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cms.settings')
    from django.core.wsgi import get_wsgi_application
    application = get_wsgi_application()



Character encoding

To enable special character support in uwsgi, for example within filenames, add the following statements to the file:

Last modified: 10/16/2017 at 17:32 by Alexandre L. (Gandi)