Skip to main content

A simple, easy access key-value registry for Django.

Project description

DJ-Registry

This is a simple, easy access key-value registry for Django. Sometimes you would like to have some flexibility in your settings. Putting your settings in settings.py or as environment variables also mean an engineer familiar with code or command line is required to alter them.

This Django app leverage the built-in Django admin so changing settings is easier as you can use the web interface.

Requirements

  • Python = "^3.6"
  • Django = "^3"

Run the following command inside project's root folder to install it's dependencies with Poetry:

$ poetry install

You can specify to the command that you do not want the development dependencies installed by passing the --no-dev option.

If you have not yet installed Poetry, please refer to their official documentation.

Installation

Install DJ-Registry with your favorite Python package manager:

(venv)$ pip install dj_registry

Add registry to your INSTALLED_APPS settings:

INSTALLED_APPS = [
    # other apps...

    'registry',
]

Migrate the database

(venv)$ ./manage.py migrate

Then, we're all set!

Usage

Log in to the admin, and create some keys under the Django Registry > Entries section. Let's say, we create mailgun.key and mailgun.domain with the corresponding string type and values. We then create another entry with game.max_score as the key, 10000 as the value and integer as the type.

The following example shows you how to access them in code:

from registry.helper import reg

key = reg['mailgun.key']            # the key that you set
domain = reg['mailgun.domain']      # the domain that you set

max_score = reg['game.max_score']   # 10000, it is returned as an int

You can also use get if you want to have a default and avoid exceptions if the key is not available (not enabled or does not exist)

reg.get('game.levels', 10)          # return 10 if key not found or disabled
reg['game.levels']                  # KeyError if key not found or disabled

You can set or delete entry if you want

reg['game.levels'] = 12             # Set game.levels to 12 (integer) and save
del reg['game.levels']              # Delete game.levels

Enabled and comment field

If you want to disable a key, just toggle the enabled boolean in the admin interface. It would be treated as if the key didn't exist. This is something meant to be used in the admin interface. If you want to manipulate this in the code, you will have to access the raw model like the following:

from registry.models import Entry

e = Entry.objects.get('game.levels')
e.enabled = False
e.save()

The comment field is also meant to be used in the admin interface. It is a convenient cell for user to put comments regarding to the settings, something like the following:

50: average use case.
9999: maximum special case

Types

integer, float, string, and boolean are the supported types for now.

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

matt_dj_registry-0.2.5.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

matt_dj_registry-0.2.5-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file matt_dj_registry-0.2.5.tar.gz.

File metadata

  • Download URL: matt_dj_registry-0.2.5.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.2 Linux/5.11.0-1028-azure

File hashes

Hashes for matt_dj_registry-0.2.5.tar.gz
Algorithm Hash digest
SHA256 b31bb6e6b7511a9a58648d150692a3fe47a981a7474c5c93249a55ca3c9fc77c
MD5 ae9f74233fd719c34aca103b19acf9ec
BLAKE2b-256 25d8dc70ce0f92f93017aab44cf9fb7b833d9ad567c3f2608786b66b1d0e14d3

See more details on using hashes here.

File details

Details for the file matt_dj_registry-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: matt_dj_registry-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.2 Linux/5.11.0-1028-azure

File hashes

Hashes for matt_dj_registry-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 cea54f14228ab8b31b503c9c9b3011eb7ef5803ae545ce8cf1f6da01d9cedacf
MD5 7d5d01f69bd19d59785a295c3e9862b5
BLAKE2b-256 263b8b10564f2ea02dbb3b58461a2b048390cc2902e1f56d415c40891a4cb96d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page