Skip to main content

Django SecretsManager is custom secret managers for Django

Project description

Django SecretsManager

Django SecretsManager is a package that helps you manage the secret values used by Django through variable services.


  • Python >= 3.6
  • Django

Required settings for the settings module

    • Secret name of SecretsManager to use
    • The key that separates JSON objects by colons.
      ex) In the example below, the "production" item is represented as "sample-project:production".
    • Region of the SecretsManager service to use
      ex) ap-northeast-2

Secret value setting of AWS SecretsManager

SecretsManager's Secret value uses JSON format in Plaintext.
Here is an example Secret value to use for configuration, and the Secret (Corresponds to AWS_SECRETS_MANAGER_SECRET_NAME in the settings module) is named sample-project-secret

  "sample-project(Recommend the name of django project)": {
    "base(If the settings module is a package, submodule names are recommended)": {
      "SECRET_KEY": "DjangoSecretKey"
    "dev": {
      "AWS_S3_BUCKET_NAME": "sample-s3-dev"
    "production": {
      "AWS_S3_BUCKET_NAME": "sample-s3-production"

Setting up AWS Credentials for Django to use

Django uses two methods to access the SecretsManager on AWS. The first uses a profile of ~/.aws/credentials in your home folder, and the second uses an environment variable.

1. Using the AWS Credentials Profile

Recommended for use in development environments

Set Profile of IAM User with SecretsManagerReadWrite Permission to ~/.aws/credentials. The following example uses the profile name sample-project-secretsmanager

aws_access_key_id = AKI*************
aws_secret_access_key = Mlp********************

Then enter the profile name in AWS_SECRETS_MANAGER_PROFILE (or AWS_PROFILE) of the settings module.

AWS_SECRETS_MANAGER_PROFILE = 'sample-project-secrets-manager'

2. Use environment variables

It is recommended to use in distribution or CI / CD environment.

If you set the following values in the environment variable, the contents are used to use the SecretsManager service.


Using Secrets in Django's Settings Module

  1. First, import the SECRETS instance of the library.
  2. Enter the settings for Django AWS SecretsManager
  3. Use SECRETS as a dictionary to get the secrets you want

Follow the form of the example below

By separating the settings module into packages, it is assumed that there are base and dev submodules.

## settings/

# 1. Import the SECRETS instance of the library
from django_secrets import SECRETS

# 2. Enter the settings for Django AWS SecretsManager
AWS_SECRETS_MANAGER_SECRET_NAME = 'sample-project-secret'
AWS_SECRETS_MANAGER_PROFILE = 'sample-project-secretsmanager'

# 3. Use SECRETS as a dictionary to get the secrets you want
## settings/

# The SECRETS instance is already imported from the base module.
from .base import *

# Use a different secrets section

# Use SECRETS as a dictionary to get the secrets you want


As an open source project, we welcome contributions.
The code lives on GitHub

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

django-secrets-manager-0.1.13.tar.gz (5.1 kB view hashes)

Uploaded source

Built Distribution

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