Back to Guides
Python Integration Guide
Learn how to integrate Sift Dev logging with your Python applications.
🚀 Using a Python Framework?
Get framework-specific instructions with our dedicated integration guides:
1. Installation
Install the Sift Dev Logger SDK using pip:
pip install sift-dev-logger
2. Environment Setup
Create a .env
file in your project root.
Loading...
# Your Sift Dev endpoint and api key
SIFT_DEV_ENDPOINT=http://<YOUR-ORG-ID>.app.trysift.dev:8000
SIFT_DEV_INGEST_KEY=<YOUR-API-KEY>
# Optional configuration (defaults shown below)
SIFT_DEV_SERVICE_NAME=python-app
SIFT_DEV_SERVICE_INSTANCE_ID=instance-1
ENV=unspecified
3. Configuration (Optional)
💡 Configuration Options
- Environment variables are automatically detected from your system environment if present
- Manual configuration via code will override environment variables
- Configure must be called before using getLogger
Configuration options and defaults
1from sift_dev_logger import SiftDevConfig, configure
2
3# All configuration options with their defaults
4configure(SiftDevConfig(
5 sift_dev_endpoint="Initialize here, or set SIFT_DEV_ENDPOINT env var",
6 sift_dev_ingest_key="Initialize here, or set SIFT_DEV_INGEST_KEY env var",
7 service_name="python-app",
8 service_instance_id="instance-1",
9 env="unspecified",
10 batch_delay_millis=5000
11))
4. Usage
Start logging with structured data in your application
1from sift_dev_logger import getLogger
2
3# Basic logging with attributes
4logger = getLogger()
5logger.info("User logged in", extra={
6 "user_id": "123",
7 "action": "login"
8})
9
10# Warning level logging
11logger.warn("High memory usage detected", extra={
12 "memory_used_mb": 850,
13 "threshold_mb": 800
14})
15
16# Error logging with exception
17try:
18 raise Exception("Database connection failed")
19except Exception as error:
20 logger.error("Connection error", exc_info=error)
Using with existing Python logging setup
If you already have loggers set up with Python's logging module, you can add Sift Dev logging by attaching our handler to your existing loggers:
1import logging
2from sift_dev_logger import SiftDevHandler, get_current_config
3
4# Get your existing logger
5logger = logging.getLogger("my-app")
6logger.setLevel(logging.INFO)
7
8# Add the SiftDev handler
9sift_dev_handler = SiftDevHandler(config=SiftDevConfig()) # If no config provided, previous config or default used
10logger.addHandler(sift_dev_handler)
5. Advanced Usage
Next Steps
Now that you've set up logging in your Python application:
- View your logs in the Logs Dashboard
- Set up alerts and notifications
- Configure custom log attributes for better filtering
- Explore our other framework integrations