Python badge

Python is a first-class citizen in the supported stacks of SourceLair. This means that you can start developing your Python applications on SourceLair in seconds.

Python web applications

If you plan to work on a Python web application on SourceLair and start a project from scratch, it will work out of the box.

If you are creating a project by cloning an existing repo though, make sure to:

  • Bind your server to 0.0.0.0
  • Listen to the port exposed in the PORT environment variable (see table below)

Supported frameworks

SourceLair provides first-class support for Django and Flask, but you can use any Python framework to build your web applications.

You can let SourceLair know what framework you will use when creating your project to get a more tailored experience.

Exposing your application to its Public URL

You should bind on the port defined in the PORT environment variable, in order to be able to access your Python web applications via your project’s Public URL.

Below is the list of the ports that SourceLair exposes for each framework. You should use the PORT environment variable to determinal to which port you should listen.

Framework PORT environment variable value
Django 8000
Flask 5000
No framework 8000

Customizing how your web applications runs

To customize how your web application runs (e.g. set an explicit command to run your server or configure a worker process), make sure to:

Python versions

SourceLair supports the latest minor version for both Python 3 and 2. When a new Python minor version (e.g. 3.7) or bugfix (e.g. 3.6.2) release gets published, update all corresponding projects automatically (e.g. from 3.6 to 3.7, but not from 2.7 to 3.7).

Setting the Python version of your project

You can set the Python version of your project when creating it by:

  1. Clicking on the Customize tab
  2. Choosing Python as the language of your choice
  3. Choosing the Version of your choice
  4. Creating your project
Choose Python version screencast

Available versions

  • Python 3.6 (3.6.1)
  • Python 2.7 (2.7.13)

Version support roadmap

  • 📅 Monday 4 September 2017: Python 3 becomes the default Python version on SourceLair
  • ⚠️ Monday 6 January 2018: SourceLair drops option for Python 2 for new projects

Libraries

Python projects in SourceLair ship with pip preinstalled to let you install and manage Python libraries.

While you can run a command like pip install example-library in your terminal to install a library, we recommend putting them in a file named requirements.txt and install them by running pip install -r requirements.txt in your terminal.

This way you can be sure that you keep track of the different Python libraries your project depeneds on and keep consistency between your production system and SourceLair.

Example requirements.txt file

django==1.11.3
requests==2.18.1