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_KEYand 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:
pip install lescoprpip 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) orproductionauto_logging— Attach to root logger immediately (default:True)auto_grpc— Connect to daemon immediately (default:True)
lescopr init --sdk-key YOUR_SDK_KEYimport lescopr
lescopr.logs()
INSTALLED_APPS = [
# ...
]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.
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)
raiseAdvanced
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 projectlescopr start / stop / status— Manage the background daemonlescopr diagnose --verbose --check-server— Full connectivity report
Environment variables
LESCOPR_DAEMON_MODE=true— Prevents the SDK from starting inside its own daemon process
from lescopr import Lescopr
client = Lescopr(
sdk_key='YOUR_SDK_KEY',
api_key='YOUR_API_KEY',
environment='production',
)import lescopr
lescopr.set_debug_mode()
lescopr.logs()