djangokeys

Module and CLI tool for handling Django keys.


License
MIT
Install
pip install djangokeys==0.1.1

Documentation

Djangokeys

This Python module is used to generate and handle secret keys for Django.

  • It comes with a CLI tool to generate secret keys for Django.
  • It can be used to store and retrieve Django's secret key.

Command-Line Tool

This module also implements a CLI tool, that can be used to generate secret keys for Django. For more information, use the following command:

code-block :: console

$ python3 -m djangokeys --help

For example, one could generate a new key and store it in the file secret.key by using the command below:

code-block :: console

$ python3 -m djangokeys --length 128 > secret.key

Python Module

The python module also provides the functionality for reading the secret from a file. In the example below, the secret key is stored in the file data/secret.txt relative to Django's manage.py file. By setting the strict parameter to True, it is required that the file exists. If it cannot be found, an exception is raised.

code-block :: python

# file: config/settings.py

import djangokeys

SECRET_KEY = djangokeys.retrieve_secret_key_from_file(
os.path.join(BASE_DIR, "data/secret.txt"), strict=True)

If the strict parameter is not provided, and the file is not found, a new secret key is automatically generated, and stored in a new file with the given filepath.