Skip to main content

Keep your secrets secret! BuildStatus Coverage

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 currently tested with Python 3.12, 3.13, and 3.14, and with Django 4.x, 5.x, and 6.x.

Supported versions

The CI matrix currently covers:

  • Python 3.12, 3.13, and 3.14

  • Django 4.x, 5.x, and 6.x

  • Django 4.x only on Python 3.12

For Django’s official Python compatibility, see the release notes: Django 5.2 and Django 6.1.

Installation

pip install django-secrets

If you prefer uv, use:

uv add django-secrets

Usage

After installing the package please add it to your INSTALLED_APPS settings.

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 will create a new my_secrets package in your project root with the following contents:

my_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 you are done adding all secrets, run manage.py again and you will 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 including code completion, but now they are safe! :)

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!

Metadata

Release files for django-secrets 3.0.5

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

Source distribution (sdist)

Source distribution for django-secrets 3.0.5
File Size Uploaded
django_secrets-3.0.5.tar.gz 9.7 kB Details

Built distribution (wheel)

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

Total release size: 19.7 kB

Release files / django_secrets-3.0.5.tar.gz

Download URL django_secrets-3.0.5.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1db39644f751ede8fabca00e04eeec31ea800427ae3e21afcb39c2998e2b701b
BLAKE2b-256 checksum
How to use checksums
1fc639ba0e80d3573dab7c5f0c8f07ad8a669152546d22d887935fb7cf6a4fcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.2

Release files / django_secrets-3.0.5-py3-none-any.whl

Download URL django_secrets-3.0.5-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
755e4c9241199c4045da33ca1d2fa6de6329799a81b25cb084f3f631ba4b3fe8
BLAKE2b-256 checksum
How to use checksums
ff6ad0dd423dc5bce753ac75c97613b0519786adc5469f0f32b4637706bb195c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.2

Release history Release notifications | RSS feed

This release

3.0.5 This release

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

1.0.1

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