Skip to main content

envsettings

  • Update django settings from environment variables by updating sys.modules
  • Mostly using ast.literal_eval to convert string to python object.
  • Tested by converting all default django settings to string and back to python object and then running django command.

todo

  • simplify code
  • verify settings after they are casted to python object
  1. Usage:
    • in myproject.settings:
      import os
      import sys
      import ast
      
      from djangobuk_envsettings import update_from_env
      
      update_from_env(
          sys.modules[__name__],
          # default prefix for all variables
          pre='DJANGO_',
          # settings that can be updated from env
          # by default all settings are allowed (this option overrides)
          allowed=[
              'SECRET_KEY',
              'SITE_ID',
          ],
          # optional
          # extra settings and their types (to be used with extra_allowed)
          extra_mapping={
              'DATABASE_PATH': ast.literal_eval,
          },
          # optional
          # extra settings that can be updated from env
          extra_allowed=[
              'DATABASE_PATH',
          ]
      )
      
      # nothing more required
      DATABASES = {
          'default': {
              'ENGINE': 'django.db.backends.sqlite3',
              'NAME': DATABASE_PATH,
          }
      }
      

Metadata

Release files for djangobuk-envsettings 0.4.1

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

Source distribution (sdist)

Source distribution for djangobuk-envsettings 0.4.1
File Size Uploaded
djangobuk_envsettings-0.4.1.tar.gz 5.0 kB Details

Release files / djangobuk_envsettings-0.4.1.tar.gz

Download URL djangobuk_envsettings-0.4.1.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
807333471e2f31a713c775387bef05cde7205b8c8f6010bbdb39cf29c7078bd7
BLAKE2b-256 checksum
How to use checksums
7a7526c69fba96c19ea65f66c9d104542559b622c12313095919f47aa32f7ee7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.4.1 This release

1 release file

0.4.0

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

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