Skip to main content

Decouple config with support for secrets directory (e.g., Docker secrets)

Project description

decouplet

A tiny wrapper around python-decouple that adds first-class support for reading secrets from a directory (e.g. Docker secrets mounted at /run/secrets/).

Drop-in replacement for python-decouple's config — same API, extra secrets support.

Installation

pip install decouplet

Usage

from decouplet import config

# Read a value — checked in secrets dir first, then env vars / .env file
DATABASE_PASSWORD = config("DATABASE_PASSWORD")

# With a default
DEBUG = config("DEBUG", default="False")

# With type casting (inherited from python-decouple)
PORT = config("PORT", default=8000, cast=int)
IS_ENABLED = config("IS_ENABLED", default=False, cast=bool)

Priority order

When looking up a key, decouplet checks sources in this order:

  1. Secrets directory — files in /run/secrets/ (or the path set via SECRETS_PATH)
  2. Environment variables
  3. .env file (standard python-decouple behaviour)
  4. Default value (if provided)

Secrets always win. This matches the expected behaviour when deploying with Docker Swarm or Kubernetes secrets.

Secrets directory

Each secret is stored as a plain-text file whose filename (uppercased) becomes the key and whose contents become the value. Trailing whitespace/newlines are stripped automatically.

/run/secrets/
    database_password   →  key: DATABASE_PASSWORD
    api_key             →  key: API_KEY

Changing the secrets path

Set the SECRETS_PATH environment variable to point to a different directory:

SECRETS_PATH=/my/secrets python app.py

Or in your .env file:

SECRETS_PATH=/my/secrets

If the directory does not exist, decouplet silently skips it and falls back to env vars / .env.

Docker example

# docker-compose.yml
services:
  app:
    image: myapp
    secrets:
      - database_password

secrets:
  database_password:
    file: ./secrets/database_password.txt
# app.py
from decouplet import config

DB_PASSWORD = config("DATABASE_PASSWORD")  # read from /run/secrets/database_password

Requirements

  • Python >= 3.9
  • python-decouple >= 3.8

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

decouplet-0.2.3.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

decouplet-0.2.3-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file decouplet-0.2.3.tar.gz.

File metadata

  • Download URL: decouplet-0.2.3.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for decouplet-0.2.3.tar.gz
Algorithm Hash digest
SHA256 ebc03a71f1e47b42f38e48d89f6c9f3220c1720d1b1cf57ac795897c3bea494e
MD5 18e7932efc1322b88f0ea938e49ddc88
BLAKE2b-256 e42f4a7b1d3267ce8764d33d65e20eaa4e9516442f23ba5d0d896783c7c10a55

See more details on using hashes here.

File details

Details for the file decouplet-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: decouplet-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for decouplet-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3902486234d1381e79bebb05ccc389c98f01132380ad74d4c60b595a3e319282
MD5 754842a106519b63a23d6704b7f5e77b
BLAKE2b-256 cfccf953f01a44c87c6fce6d5542f374461c37d9cb4d9a5b059ac22d33cf38b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page