Skip to main content

Secure your django sensible settings

Project description


Secure Django settings (Works with other Python scripts)

This module creates a cryptokey outside the django project directory, encrypts with that cryptokey your django sensible settings and stores the encrypted values.

You can use it at your project file * Note: Before running the django site with gunicorn or similar for the first time, you must run somme manage command to be prompt for the sensible settings * Developed for Linux/Python2.7, Python3.5


pip install djangosecure



import djangosecure

SECRET_KEY_FILE_PATH = '/some/path/to/store/file.secret'
SECRET_KEY = djangosecure.get_secret_key(SECRET_KEY_FILE_PATH)
  • Note: If the secret key file path does not exist it will try to create it,

  • Note: The secret file will be automatically created the first time you call get_secret_key()

  • Note: You can do something like:

import os
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SECRET_FILE = os.path.join(PROJECT_DIR, '.secret.txt')
SECRET_KEY = djangosecure.get_secret_key(SECRET_FILE)


The first time you run python runserver you will be prompted for your database settings. They will be saved encrypted with the generated cryptokey generated by django-secure module.

You can have as many database configurations, change the parameter to change the configuration and running python runserver you will be prompted again for the new settings

import djangosecure

    'default': djangosecure.get_database('production', path='your/database/config/path.cfg'),

S3 IAM Settings

In your include:

from djangosecure import get_s3_config

# S3 Config
S3_CFG = /path/to/s3_config_file.cfg
AWS_ACCESS_KEY_ID = get_s3_config(AWS_STORAGE_BUCKET_NAME, 'S3_access_IAM_Key_Id', S3_CFG)
AWS_SECRET_ACCESS_KEY = get_s3_config(AWS_STORAGE_BUCKET_NAME, 'S3_access_IAM_Secret_Key', S3_CFG)
  • Note: File and path are automatically created at first call

Hidden setting

To encrypt any other setting use hidde_setting, for example

from djangosecure import hidden_setting
CELERY_BROKER = 'amqp://{0}:{1}@localhost//'.format(
    hidden_setting('celery', 'broker_username', config_file="config/file/path/here.cfg"),
    hidden_setting('celery', 'broker_password')
  • Note: File and path are automatically created at first call

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

djangosecure-0.0.3.tar.gz (7.3 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page