Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

The easy way of handling Django secrets.

Project Description

This little app helps you to not commit your secrets to a repo and adds a nice way of exporting/importing secrets for a new deployment or automated testing with environment variables.

Though this never happened to me during coding, Travis had some problems to reliably execute the tests and hot load the new secrets, so I had move the secrets module into the my_secrets package to not have two modules named secrets. Python obviously cant handle that. Lesson learned after about 40 Travis builds. :(

django-secrets is working under Django 1.5+ and Python 2.7, 3.5 and 3.6


pip install django-secrets


After installing the package please add it to your INSTALLED_APPS setting


Because we want to be able to hide our secret settings, we have to alter to run some code before the Django magic happens. Open and alter it like this:

if __name__ == "__main__":

    from django_secrets.startup import check


Now that the check is in place, run to initialize your project. This wll create a new secrets package in your project root with the following contents:

├── .gitignore

The package also features a .gitignore file to prevent you from checking in any secrets to git. Now open to add your secrets to the list. Start with the Django secret key for example. When your done adding all secrets, run again and you wil be asked to enter your secrets.

Now you can remove your secrets from and instead replace them like this:

from my_secrets import secrets


Since the secrets are saved in a normal python package, you can just use them the normal way, but now they are save! :)

Import / Export

This package adds a new management command: export_secrets. This will print out export statements so you can easily create environment variables on a new machine and let the check function do the rest for you, because it will also read in any known environment variables as secret values. This is quite handy for dynamically spawned instances or CI testing.

Have fun and stay safe!

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(10.9 kB) Copy SHA256 Hash SHA256
Wheel py2.py3 Feb 23, 2018

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers