Skip to main content

A Django integration for AWS Secrets Manager with caching and lazy loading support

Project description

django-simple-secrets

A Django integration for AWS Secrets Manager with caching and lazy loading support.

Python 3.10+ Django 4-5

Overview

django-simple-secrets provides a clean and efficient way to access AWS Secrets Manager from a Django applications. It features built-in caching to reduce API calls and supports lazy loading of secrets through Django's SimpleLazyObject.

⚠️ Important Note: This module is not thread-safe. The caching mechanism uses a simple dictionary that is not protected against concurrent access. If you need thread-safety, consider implementing your own synchronization mechanism or disabling caching with use_cache=False.

Key Features

  • Simple, intuitive API for accessing AWS Secrets Manager
  • Built-in caching mechanism to minimize API calls
  • Lazy loading support for improved performance
  • Configured retry logic and timeouts
  • Type hints for better IDE support
  • Compatible with Python 3.10+ and Django 4.x/5.x

Installation

pip install django-simple-secrets

Note: This package requires boto3, which must be installed separately:

pip install boto3

Configuration

Ensure your AWS credentials are properly configured either through:

  • Environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
  • AWS credentials file
  • IAM role (when running on AWS infrastructure)

Usage

Basic Usage

from django_secrets import get_secret

# Get an entire secret
database_config = get_secret('prod/database')

# Get a specific key from a secret
database_password = get_secret('prod/database', key='password')

Lazy Loading

from django_secrets import get_secret_lazy

# Secret won't be fetched until actually accessed
database_config = get_secret_lazy('prod/database')

Cache Management

from django_secrets import clear_cache

# Clear a specific secret from cache
clear_cache('prod/database')

# Clear entire cache
clear_cache()

# Bypass cache for a single request
fresh_secret = get_secret('prod/database', use_cache=False)

Error Handling

The module raises standard boto3 exceptions:

try:
    secret = get_secret('prod/database')
except ClientError as e:
    # Handle AWS-specific errors
    pass
except KeyError as e:
    # Handle missing key errors
    pass

Performance Considerations

  • The module maintains a single boto3 client instance
  • Caching is enabled by default to minimize API calls
  • Timeout settings: 2 seconds for both connect and read
  • Maximum retry attempts: 3

License

This project is licensed under the MIT License. See the LICENSE file for details.

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-simple-secrets-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

django_simple_secrets-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file django-simple-secrets-0.1.0.tar.gz.

File metadata

  • Download URL: django-simple-secrets-0.1.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.1

File hashes

Hashes for django-simple-secrets-0.1.0.tar.gz
Algorithm Hash digest
SHA256 261448e9c8784e5d14e3abdf9a80b9a73cc2ad7f53d6d1a90835f03b470c7f92
MD5 3a7adb24e791e6100eecaef40ee5a912
BLAKE2b-256 314976f74eb9cefe1455956052be54ccbc6b19b8be7e74d5b09fc52ce7fe1d99

See more details on using hashes here.

File details

Details for the file django_simple_secrets-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_simple_secrets-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55f9ab17b630bb9f141e4b73d52312b70c46c733a42db10dbd400ddf8f17a716
MD5 830d951abfbbc1a6cebf4f2f7cb8b22e
BLAKE2b-256 b8a521cc5d6ba1eb3cd7337ff6e7a2d7b12f803811e575f4adce6d19e054aae0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page