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, we will 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 pipenv, the officially recommended Python packaging tool from Python.org, preinstalled to let you install and manage Python libraries.

To install a Python library (e.g. Django) in your SourceLair project, just run the following command in your terminal:

pipenv install django

This will install Django in your SourceLair project’s workspace, add Django as a dependency in your Pipfile and Pipfile.lock files to make sure you install the same libraries and library versions across your development and production systems.

You can also use pip out of the box as well, but we recommend using pipenv instead, as it’s superior.