Skip to main content

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

Installation

pip install django-secrets

Usage

After installing the package please add it to your INSTALLED_APPS setting

INSTALLED_APPS = (
    ...
    'django_secrets',
)

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

if __name__ == "__main__":

    from django_secrets.startup import check
    check()

    ...

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

secrets
├── .gitignore
├── __init__.py
├── definitions.py
└── secrets.py

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

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

from my_secrets import secrets

SECRET_KEY = secrets.SECRET_KEY

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 files for django-secrets 1.0.1

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

Built distribution (wheel)

Table of built distributions (wheels) for django-secrets 1.0.1
File Interpreter ABI Platform
django_secrets-1.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Release files / django_secrets-1.0.1-py2.py3-none-any.whl

Download URL django_secrets-1.0.1-py2.py3-none-any.whl
Size 11.0 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ef8812dda13a6c9e4177f3f18206298fce944770277ab3e9bf4169bffb926a2e
BLAKE2b-256 checksum
How to use checksums
6af886b52b3f33fea725b341ea047eabd2835659ac34da5f403eb60d4ad08e88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

3.0.5

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

1 release file

3.0.1

2 release files

3.0.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

1 release file

This release

1.0.1 This release

1 release file

1.0.0

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.0

1 release file

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