Doppler Python SDK
Doppler's SDK provides convenient access to the Doppler API from applications written in Python. It allows developers to manage and synchronize secrets and configuration across environments, with features like collaboration, access controls, and versioning. The current version is 1.3.0, released in April 2024, with a release cadence that includes minor and patch updates based on new API features and bug fixes.
Common errors
-
An error occurred: Invalid Auth token
cause The provided Doppler Service Token (or personal token) is incorrect, malformed, expired, or does not have the necessary permissions.fixGenerate a new Service Token from your Doppler dashboard for the specific project and config you are trying to access. Carefully copy the entire token, ensuring no extra characters or duplicates, and use it when initializing the `DopplerSDK` client. -
Client.Timeout exceeded while awaiting headers
cause The Python SDK (or underlying network calls) is unable to resolve `api.doppler.com` or establish a connection within the timeout period, often due to DNS issues or network egress restrictions.fixChange your system's DNS settings to a public resolver like Cloudflare (1.1.1.1) or Google Public DNS (8.8.8.8). If using the Doppler CLI for setup, you can set `DOPPLER_DNS_RESOLVER=1.1.1.1` in your environment or use the `--dns-resolver 1.1.1.1` flag with CLI commands. -
Token not found in system keyring
cause This error typically occurs when the local Doppler CLI token (if used for implicit authentication) has become out of sync with your operating system's keyring.fixFirst, find the scope of your token (usually `/`) using `cat ~/.doppler/.doppler.yaml`. Then, unset the token with `doppler configure unset token --scope /` (adjust scope if different). Finally, re-authenticate using `doppler login`. If issues persist, try `doppler configure reset` as a last resort.
Warnings
- breaking Version 1.3.0 introduced changes to the `Secrets` type within `SecretsUpdateRequest` and added a `change_request` field. Users directly manipulating these types might need to adjust their code upon upgrading.
- deprecated The `doppler-client` package (a distinct, older library) is deprecated and no longer functional. Do not confuse it with `doppler-sdk`.
- gotcha For local development and debugging in IDEs (like PyCharm, VS Code), direct `doppler run` command invocation might not work for secret injection. The `doppler-env` package is often necessary.
- gotcha Network connectivity issues, particularly related to DNS resolution, can cause 'Client.Timeout exceeded' errors when the SDK attempts to connect to the Doppler API, especially with certain network configurations (e.g., Google WiFi, VPNs).
Install
-
pip install --upgrade doppler-sdk
Imports
- DopplerSDK
from dopplersdk import DopplerSDK
Quickstart
import os
from pprint import pprint
from dopplersdk import DopplerSDK
# Ensure your Doppler Service Token is set as an environment variable (e.g., DOPPLER_TOKEN)
# For local development, it's recommended to use `doppler run -- python your_app.py`
# or the doppler-env package for IDE integration.
# Alternatively, you can set it directly from an environment variable for server-side use.
DOPPLER_TOKEN = os.environ.get('DOPPLER_TOKEN', '')
if not DOPPLER_TOKEN:
print("Error: DOPPLER_TOKEN environment variable not set.")
print("Please ensure you have authenticated the Doppler CLI (doppler login, doppler setup) ")
print("or set the DOPPLER_TOKEN environment variable.")
else:
try:
doppler = DopplerSDK(access_token=DOPPLER_TOKEN)
# Example: List all projects
results = doppler.projects.list()
print("Successfully fetched Doppler projects:")
pprint(results.to_dict()) # Use .to_dict() to convert the object to a dictionary for pprint
except Exception as e:
print(f"An error occurred: {e}")