Skip to main content

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.

Source code: https://gitlab.com/mdigital-public/backend/decouplet

Documentation

Installation

pip install decouplet

Install directly from the public GitLab repository:

pip install "git+https://gitlab.com/mdigital-public/backend/decouplet.git"

Usage

from decouplet import config

# Read a value — checked in secrets dir first, then env vars / .env or settings.ini
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. settings.ini or .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

Or in settings.ini:

[settings]
SECRETS_PATH=/my/secrets

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

Encoding

decouplet follows python-decouple's lazy loading behavior, so you can set file encoding before the first lookup:

from decouplet import config

config.encoding = "cp1251"
SECRET_KEY = config("SECRET_KEY")

Docker example

See the runnable Docker Compose example in examples/docker-secrets-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

Metadata

Release files for decouplet 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for decouplet 0.2.4
File Size Uploaded Provenance Actions
decouplet-0.2.4.tar.gz 11.0 kB Without provenance Details for decouplet-0.2.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for decouplet 0.2.4
File Interpreter ABI Platform Actions
decouplet-0.2.4-py3-none-any.whl Python 3 none any Details for decouplet-0.2.4-py3-none-any.whl

Total release size: 16.5 kB

Release files / decouplet-0.2.4.tar.gz

Download URL decouplet-0.2.4.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d1724299db0f614e8451a64a8e8887f0c789aba8357fbb7454bcb543659954e1
BLAKE2b-256 checksum
How to use checksums
a037f8ddd447cf705233e86723819f2c06abeda63c9a720b0d68c7fdd2221831
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / decouplet-0.2.4-py3-none-any.whl

Download URL decouplet-0.2.4-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7105da8c26910d40d5c8721415570d47ce88e6d8a7cae9d3dd35e755fa5cf654
BLAKE2b-256 checksum
How to use checksums
7f003ecfd6eb349d79c084290b5d896b09c733588ef57753657063c0c575890e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for decouplet 0.2.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page