🔐 python-decouple: Clean and Safe Configs with .env

Hardcoding secrets or config values in your Python code?
Stop doing that. python-decouple is a dead-simple way to keep your configuration clean, secure, and environment-specific.


✅ Why use it?

  • Load values from a .env file or environment variables

  • Keep secrets out of version control

  • Cast types automatically (str, int, bool, etc.)


🧪 Example

pythonCopyEdit# config.py
from decouple import config

DEBUG = config("DEBUG", default=False, cast=bool)
DB_URL = config("DATABASE_URL")

And in your .env file:

iniCopyEditDEBUG=True
DATABASE_URL=postgresql://user:pass@localhost:5432/dbname

🧼 Simple, readable, and safe

Use it in any Python project — even without frameworks.
It’s great for scripts, CLI tools, microservices, or anything that needs clean configs.

0
Subscribe to my newsletter

Read articles from Pedro Buzzi Filho directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Pedro Buzzi Filho
Pedro Buzzi Filho