Install the Python microagent

Install the Python microagent on your system using one of three methods:

  • If you control the way your web application or WSGI server starts, use the command-line (CLI) launcher to install the microagent and launch your application.
  • Change your application to include the Sqreen microagent code.
  • Install with Alpine Linux.

Install with CLI launcher

  1. Review Python microagent compatibility to confirm that the Sqreen Microagent for Python is compatible with your Python application.
  2. Sign up to create your Sqreen account.
  3. Fetch your organization token. From the Sqreen Dashboard, access Account Settings > Environments & Tokens. Your token begins with env_org_. Take note of the token.
  4. From Terminal, install the microagent using pip. (Requires pip 8.1.0 or later: pip install _U pip).
    pip install sqreen
    
  5. In your application's root directory, use the following command to set up the Sqreen token and application name:
    # Replace the values for app_name and token with your own
    cat > sqreen.ini <<EOF
    [sqreen]
    app_name: YOUR_APPLICATION_NAME
    token: SQREEN_TOKEN
    EOF
    
  6. From Terminal, use the CLI launcher to start your application with the microagent.
    # Replace the application module name with yours
    sqreen-start gunicorn YOUR_APP_MODULE.wsgi
    

The Sqreen Microagent for Python is also available in the PyPI repository.

Install by including code

  1. Follow steps 1 - 3 above.
  2. Add two lines of code to your application's wsgi.py or app.py file in the root directory. Before all other import lines, add:
    import sqreen
    sqreen.start()
    

Install on Alpine Linux

  1. Follow steps 1 - 3 above.
  2. From Terminal, run the following command:
    apk add libgcc libstdc++
    
  3. Install the Sqreen microagent using pip. (Requires pip 8.1.0 or later: pip install _U pip).
    pip install --extra-index-url https://download.sqreen.com/python/alpine sqreen
    
  4. If you use a requirements.txt file to install your dependencies, add the following:
    --extra-index-url https://download.sqreen.com/python/alpine
    sqreen
    

Install in multiple 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 the values for app_name and token with your own
cat > sqreen.ini <<EOF
[sqreen]
app_name: YOUR_APPLICATION_NAME (staging)
token: SQREEN_TOKEN
EOF

Uninstall

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