Skip to main content

django-environ

django-environ is the Python package that allows you to use Twelve-factor methodology to configure your Django application with environment variables.

This is the PPB extension of it adding _VAULT and _FILE support to environment variable name parsing to read the setting from (respectivelly) that vault key or that file.

This should probably be a fork of the package instead of keeping it as a separate package.. TODO.

Usage

Refer to testapp for a working example.

As in testapp settings, initialize environ:

import ppbenviron

ENV_VAR = ppbenviron.CustomEnv()
ENV_VAR.read_env(BASE_DIR / 'local.env')

ENV_VAR.setup_vault(
    'ENVTEST_VAULT_URL',
    'ENVTEST_VAULT_TOKEN',
    'ENVTEST_VAULT_MOUNT',
    'ENVTEST_VAULT_PATHS',
    default_url='http://vault.local',
    default_token='tok3n',
    default_mount='/secrets',
    default_paths='staging,production',
)

Define settings:

TEST_SETTING_STR = ENV_VAR('ENVTEST_STR', default='missed')
TEST_SETTING_LIST = ENV_VAR('ENVTEST_LIST', default=['missed'])

Create a testapp/local.env or define the environment variabls in the current shell:

ENVTEST_VAULT_TOKEN_FILE=/home/myuser/.vault-token
ENVTEST_VAULT_MOUNT=other_mount
ENVTEST_VAULT_PATHS=dev,prd

ENVTEST_STR_FILE=/path/to/file will load /path/to/file in TEST_SETTING_STR.

ENVTEST_STR_VAULT=somepath will load /other_mount/prd[somepath] in TEST_SETTING_STR if it exists otherwise fallback to /other_mount/qa[somepath]

Download files

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

Source Distribution

django_environ_ppb-1.0.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

django_environ_ppb-1.0.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file django_environ_ppb-1.0.1.tar.gz.

File metadata

  • Download URL: django_environ_ppb-1.0.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for django_environ_ppb-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f65ce56c7329e3feb028d44b2b1ff6ecffb932b733294403ee49348ce3656cd3
MD5 70dccc73efc75397303a8aff09e408d5
BLAKE2b-256 963f317dd3c6afeb34136a04fe201005b8f2eaddfa45b762d45a8b16726753cb

See more details on using hashes here.

File details

Details for the file django_environ_ppb-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_environ_ppb-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f52b3ec6711f88bccddd40677b67abc6e964a1e683eead698fa958f3f99422d5
MD5 0942d67a5051fca00d2414618ed8081c
BLAKE2b-256 2a5bb840eb581e1824435a2a30b831ce8ebb29e259680088669f6b2eb6b1f40f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 files

1.0.0

2 files

0.0.1

2 files

Supported by

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