Install the Python agent

Install the Python agent on your system.


Quickstart

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

We support two ways of protecting your app:

  • Use our command-line launcher to launch your application
  • Change your WSGI file to include the Sqreen code

Standard Python application

If you control the way your web application (or WSGI server) starts follow the simple instructions below.

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:

pip install sqreen

Then in your application root directory use the following command to set up your Sqreen configuration:

# Replace the Sqreen application name and token with yours
cat > sqreen.ini <<EOF
[sqreen]
app_name: YOUR_APPLICATION_NAME
token: SQREEN_TOKEN
EOF

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

# Replace the application module by yours
sqreen-start gunicorn YOUR_APP_MODULE.wsgi

Start Sqreen from code

Alternatively, you can start Sqreen with a change in your application file (typically a wsgi.py or app.py file in your application root directory) by inserting these two lines at the top before every other import lines:

import sqreen
sqreen.start()

Install the agent on non production environments

Typically you install the Sqreen agent in your production environment, but you can create several applications by specifying the environment in the application name.

# Replace the Sqreen application name and token with yours
cat > sqreen.ini <<EOF
[sqreen]
app_name: YOUR_APPLICATION_NAME (staging)
token: SQREEN_TOKEN
EOF

Use environment variables for configuration

The Sqreen agent stores your configuration in the sqreen.ini file.

Instead of using the Sqreen configuration file, you can also use the SQREEN_TOKEN and SQREEN_APP_NAME environment variables to set up your token and the application name.

export SQREEN_APP_NAME="YOUR_APPLICATION_NAME"
export SQREEN_TOKEN="SQREEN_TOKEN"

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

Install the agent on Alpine Linux

On Alpine, you need to install Sqreen a bit differently. First, run the following command:

apk add libgcc libstdc++

Then, Sqreen can be installed with:

pip install --extra-index-url https://download.sqreen.com/python/alpine sqreen

Or, if you use a requirements.txt file to install your dependencies, the following lines are to be added:

--extra-index-url https://download.sqreen.com/python/alpine
sqreen

Uninstall the agent

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

Notes

The Sqreen Python agent is available in the 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.