Installation of the Python agent


TL;DR

Installing the Sqreen Python agent enables you to monitor the security of your application and block attacks in real-time. Installing Sqreen in your Python application takes less than a minute:

  • Sign up to Sqreen to create your account
  • Pick up your first application name and language. The name of the application can be the name of the repository, or anything that will help you identify the app in your Sqreen dashboard
  • Follow the procedure detailed below

We support two ways of protecting your app: * Modify your wsgi file to include our code * Use our command-line launcher to launch your application

Standard Python Application

If you control the way your web application (or WSGI server) is started, you can follow the simple instructions below, using the Sqreen launcher.

pip > 8.1.0 required

Make sure you have a pip version > 8.1.0.

pip install -U pip

In a terminal, install Sqreen using pip tool:

pip install sqreen

Then, still from the terminal, in your application root directory, type the following command to set up your Sqreen configuration (the Sqreen token will be provided from your user interface):

echo -e "[sqreen]\ntoken: mysecrettoken" > sqreen.ini

Finally, from your application root directory, modify your application file (typically wsgi.py or app.py file) by inserting these two lines at the (very) top:

import sqreen
sqreen.start()

You can also set your token as an environment variable:

Command-line Sqreen launcher

You can use our CLI (command-line) launcher to start your application with Sqreen from a terminal:

sqreen-start gunicorn YOUR_APP.wsgi

Install the agent outside production environment

Typically you will install the Sqreen Python agent in your production environment, but you can create several applications using your Sqreen dashboard, and specifying the environment (development, staging, production). A unique Sqreen token will be provided for each of your applications.

Basic configuration

After installing the agent, your configuration will be stored in the configuration file sqreen.ini. It basically contains your Sqreen token.

Instead of using the Sqreen configuration file sqreen.ini, you can also use SQREEN_TOKEN environment variable to set up your token (from a terminal):

export SQREEN_TOKEN=mysecrettoken 

Sqreen Python agent provides flexible configuration settings. Refer to Configuration of the Python agent for more detailed information.

Uninstall the Agent

To uninstall the Sqreen agent, simply remove the module from your application.

Notes

The Sqreen Python agent is available on PyPI repository.

Use different Sqreen Applications for different environments

We recommend you to use different Sqreen applications on your different environments: Production, Staging and Development.