Django — Lescopr SDK

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

Introduction

The Lescopr Python SDK integrates with Django by hooking directly into Python's logging module — no middleware, no extra configuration.

A single call to lescopr.logs() in settings.py is all it takes. The SDK captures every logging.getLogger(...) call in your entire codebase and forwards them in real-time to your Lescopr dashboard.

The package is available on PyPI and requires Python 3.8+ and Django 3.2+.

Requirements

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

  • Python >= 3.8
  • Django >= 3.2
  • A valid LESCOPR_SDK_KEY and API key (available from your Lescopr dashboard)
  • pip >= 21.0

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

Installation

Install the package from PyPI:

Or with the optional psutil dependency for daemon detection:

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

Configuration

Initialise the SDK in your project directory — this registers the project and starts the background daemon:

Then add a single import to the top of your settings.py:

Alternatively, you can initialise directly in wsgi.py or asgi.py:

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
settings.py
python
import lescopr
lescopr.logs()

INSTALLED_APPS = [
    # ...
]
wsgi.py
python
import lescopr
lescopr.logs()

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

Usage

Once lescopr.logs() is called, all existing logging calls are captured automatically — no changes needed in your views, models, or tasks:

Uncaught exceptions are also captured via Django's got_request_exception signal. The SDK reconnects the log handler automatically after any hot-reload in development.

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

def checkout(request):
    logger.info('Checkout started', extra={'user_id': request.user.id})
    try:
        process_order(request)
    except Exception as e:
        logger.error('Order failed', exc_info=True)
        raise

Advanced

Direct instantiation

For full control over the SDK configuration, 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

Environment variables

  • LESCOPR_DAEMON_MODE=true — Prevents the SDK from starting inside its own daemon process
settings.py
python
from lescopr import Lescopr

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