Skip to content

A Django package to validate environment variables given a schema of rules

License

Notifications You must be signed in to change notification settings

72mins/django-env-validator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Project Description

Django env validator is a package used to validate the .env file in a Django project using a set schema of rules.

Installation

The package can be installed and used in your Django app with pip:

pip install django-env-validator

Edit your settings.py file to include ‘django_env_validator’ in the INSTALLED_APPS listing.

INSTALLED_APPS = [
    ...
    'django_env_validator',
]

Usage

Define the variable ENV_VALIDATOR_RULES in your settings.py

The current available rules are:

  • required (boolean -- is the environment variable a required one or not)
  • min_length (integer -- minimum character length of the environment variable)
  • max_length (integer -- maximum character length of the environment variable)
  • choices (list, tuple, set -- specific values the environment variable can be)

Example:

ENV_VALIDATOR_RULES = {
    "API_KEY": {
        "required": True,
        "min_length": 15,
        "max_length": 50,
    },
    "CURRENT_ENVIRONMENT": {
        "required": True,
        "choices": ["dev", "staging", "testing", "production"],
    }
}

About

A Django package to validate environment variables given a schema of rules

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages