Flask — Lescopr SDK

Integrate the Lescopr SDK into your Flask application for automatic log capture, exception tracking, and real-time monitoring.

Introduction

The Lescopr Python SDK integrates with Flask by hooking into Python's logging module — no extensions, no app.config changes.

Add lescopr.logs() at the top of your application factory or app.py and every log call in your Flask app will be forwarded automatically to your Lescopr dashboard.

The package is available on PyPI and is compatible with Flask 2.0+, Gunicorn, uWSGI, and any WSGI server.

Requirements

Before installing the Lescopr SDK, make sure your environment meets the following requirements:

  • Python >= 3.8
  • Flask >= 2.0
  • A valid LESCOPR_SDK_KEY and API key (available from your Lescopr dashboard)

Optional: Install lescopr[psutil] for enhanced daemon process detection.

Installation

Install the package from PyPI:

Or with the optional psutil dependency:

Terminal
bash
pip install lescopr
Terminal
bash
pip install lescopr[psutil]

Configuration

Initialise the SDK in your project directory:

Then add lescopr.logs() to the top of your app.py or application factory:

Available options (direct instantiation):

  • sdk_key — Your Lescopr SDK key (required)
  • api_key — Your Lescopr API key (required)
  • environment — development (default) or production
  • auto_logging — Attach to root logger immediately (default: True)
  • auto_grpc — Connect to daemon immediately (default: True)
Terminal
bash
lescopr init --sdk-key YOUR_SDK_KEY
app.py
python
import lescopr
lescopr.logs()

from flask import Flask
app = Flask(__name__)

@app.route('/')
def index():
    return 'Hello World'

Usage

Once lescopr.logs() is called, all logging calls are forwarded automatically — including Flask's internal logger and any third-party library logs:

The SDK works identically with Flask's development server, Gunicorn workers, uWSGI, and any other WSGI server — no extra configuration needed per environment.

app.py
python
import logging
logger = logging.getLogger(__name__)

@app.route('/orders', methods=['POST'])
def create_order():
    logger.info('Order received')
    try:
        result = process_order(request.json)
        return jsonify(result)
    except Exception as e:
        logger.error('Order failed', exc_info=True)
        raise

Advanced

Application factory pattern

For apps using the factory pattern, call lescopr.logs() before create_app() to ensure the handler is installed before any logger is instantiated:

Direct instantiation

For full control, bypass .lescopr.json and instantiate directly:

Debug mode

Enable verbose internal output to troubleshoot the connection:

CLI commands

  • lescopr init --sdk-key KEY — Initialise and register the project
  • lescopr start / stop / status — Manage the background daemon
  • lescopr diagnose --verbose --check-server — Full connectivity report
app.py
python
import lescopr
lescopr.logs()   # before create_app()

def create_app(config=None):
    app = Flask(__name__)
    # ...
    return app
app.py
python
from lescopr import Lescopr

client = Lescopr(
    sdk_key='YOUR_SDK_KEY',
    api_key='YOUR_API_KEY',
    environment='production',
)
app.py
python
import lescopr
lescopr.set_debug_mode()
lescopr.logs()