Install the Python microagent

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

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. Install the following runtime dependencies:
    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 microagent in your production environment, but you can install it in multiple environments. Use a unique name describing the application and different token for each environment such as production, staging, and development.

  1. From the Sqreen Dashboard, navigate to Account Settings > Environments & Tokens to fetch a token associated to an existing environment or add a new one.
  2. When creating a new environment, Sqreen automatically creates a new token and associates it with it. Take note of the new token.
  3. Set up your application name and SQREEN_TOKEN in the Sqreen microagent configuration file.
# Replace the the values for app_name and token with your own
cat > sqreen.ini <<EOF
[sqreen]
app_name: YOUR_APPLICATION_NAME
token: SQREEN_TOKEN
EOF

Uninstall

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