Skip to main content

A tiny helper to validate required environment variables for Django.

Project description

🛡️ django-env-check

Validate your environment variables before Django starts

PyPI version Python 3.8+ License: MIT Downloads

A tiny, zero-dependency helper that ensures all required environment variables are present before your Django app starts.

InstallationUsageFeaturesContributing


🎯 Why django-env-check?

Every Django project relies on environment variables, but most developers never validate whether they exist. This leads to:

  • ❌ Missing SECRET_KEY or DATABASE_URL
  • ❌ Silent misconfigurations in production
  • ❌ Email failures due to missing credentials
  • ❌ API integration issues
  • ❌ Hard-to-debug runtime errors

django-env-check solves this with one line of code.


🚀 Installation

pip install django-env-check

📖 Usage

Basic Usage

Add this at the top of your settings.py:

from env_check import check_env

check_env([
    "SECRET_KEY",
    "DATABASE_URL",
    "EMAIL_HOST_USER",
    "EMAIL_HOST_PASSWORD"
])

If any variable is missing, Django will refuse to start:

[django-env-check] Missing environment variables: SECRET_KEY, DATABASE_URL

🟡 Warning Mode (Development)

In development, you may want warnings instead of hard failures:

check_env(["SECRET_KEY"], warn_only=True)

Output:

⚠️  WARNING: [django-env-check] Missing environment variables: SECRET_KEY

💡 Auto-enable Warning Mode in DEBUG

from django.conf import settings

check_env(
    ["SECRET_KEY", "DATABASE_URL"],
    warn_only=settings.DEBUG
)

✨ Features

✅ Return Value

check_env(...) returns True when:

  • All variables exist OR
  • warn_only=True (even if variables are missing)

Use this in custom logic:

if check_env(["API_KEY"], warn_only=True):
    # Continue with setup
    pass

❗ Custom Exception Handling

Missing variables raise EnvMissingError:

from env_check import check_env, EnvMissingError

try:
    check_env(["SECRET_KEY"])
except EnvMissingError as e:
    print(f"⚠️  Config error: {e}")

🧪 Testing Your Installation

Test warning mode:

python -c "from env_check import check_env; check_env(['X'], warn_only=True)"

Test error mode (should raise EnvMissingError):

python -c "from env_check import check_env; check_env(['X'])"

📁 Project Structure

django-env-check/
├── env_check/
│   ├── __init__.py
│   └── checker.py
├── pyproject.toml
├── README.md
└── LICENSE

🤝 Contributing

Contributions are welcome! 🎉


📜 License

MIT License – Free to use, modify, and distribute.


⭐ Support the Project

If django-env-check helps you catch bugs early and ship safer code, please:

  • Star this repo on GitHub
  • 🐦 Share it with your Django community
  • 💬 Leave feedback or suggestions

Your support encourages new features & improvements! ❤️


Made with ❤️ for the Django community

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

django_env_check-0.1.2.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

django_env_check-0.1.2-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file django_env_check-0.1.2.tar.gz.

File metadata

  • Download URL: django_env_check-0.1.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for django_env_check-0.1.2.tar.gz
Algorithm Hash digest
SHA256 331d31b3cfa22b5532ef1697a09ff08540e3f8bfbb4b227394870c96a936d22a
MD5 6b3e4cf5b6deaa3ae113d5a5d3a08df4
BLAKE2b-256 74ae4b926dbcf94c821fbb8e162bc5606e823e6694d1403cd9f1d1dea5042aa7

See more details on using hashes here.

File details

Details for the file django_env_check-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_env_check-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 406941f4328c92209c82aecf41c06b36738ef1aabfc56cce2ca0ddbc4cf4a723
MD5 a796fefc83310b82136421b1fd649128
BLAKE2b-256 dd874cf72eec6f2924105bd839cb2a06834602f1dd580ba98f06f96600f1788a

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