# django-simple-secrets
A Django integration for AWS Secrets Manager with caching and lazy loading support.
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![Django 4-5](https://img.shields.io/badge/django-4.x|5.x-green.svg)](https://www.djangoproject.com/)
## 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
```bash
pip install django-simple-secrets
```
Note: This package requires `boto3`, which must be installed separately:
```bash
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
```python
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
```python
from django_secrets import get_secret_lazy
# Secret won't be fetched until actually accessed
database_config = get_secret_lazy('prod/database')
```
### Cache Management
```python
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:
```python
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](LICENSE) file for details.
Raw data
{
"_id": null,
"home_page": "https://github.com/efficient-solutions/django-simple-secrets",
"name": "django-simple-secrets",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "Django, AWS Secrets Manager",
"author": "Efficient Solutions LLC",
"author_email": "contact@efficient.solutions",
"download_url": "https://files.pythonhosted.org/packages/31/49/76f74eb9cefe1455956052be54ccbc6b19b8be7e74d5b09fc52ce7fe1d99/django-simple-secrets-0.1.0.tar.gz",
"platform": null,
"description": "# django-simple-secrets\n\nA Django integration for AWS Secrets Manager with caching and lazy loading support.\n\n[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)\n[![Django 4-5](https://img.shields.io/badge/django-4.x|5.x-green.svg)](https://www.djangoproject.com/)\n\n## Overview\n\n`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`.\n\n\u26a0\ufe0f **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`.\n\n### Key Features\n\n- Simple, intuitive API for accessing AWS Secrets Manager\n- Built-in caching mechanism to minimize API calls\n- Lazy loading support for improved performance\n- Configured retry logic and timeouts\n- Type hints for better IDE support\n- Compatible with Python 3.10+ and Django 4.x/5.x\n\n## Installation\n\n```bash\npip install django-simple-secrets\n```\n\nNote: This package requires `boto3`, which must be installed separately:\n\n```bash\npip install boto3\n```\n\n## Configuration\n\nEnsure your AWS credentials are properly configured either through:\n- Environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`)\n- AWS credentials file\n- IAM role (when running on AWS infrastructure)\n\n## Usage\n\n### Basic Usage\n\n```python\nfrom django_secrets import get_secret\n\n# Get an entire secret\ndatabase_config = get_secret('prod/database')\n\n# Get a specific key from a secret\ndatabase_password = get_secret('prod/database', key='password')\n```\n\n### Lazy Loading\n\n```python\nfrom django_secrets import get_secret_lazy\n\n# Secret won't be fetched until actually accessed\ndatabase_config = get_secret_lazy('prod/database')\n```\n\n### Cache Management\n\n```python\nfrom django_secrets import clear_cache\n\n# Clear a specific secret from cache\nclear_cache('prod/database')\n\n# Clear entire cache\nclear_cache()\n\n# Bypass cache for a single request\nfresh_secret = get_secret('prod/database', use_cache=False)\n```\n\n## Error Handling\n\nThe module raises standard boto3 exceptions:\n\n```python\ntry:\n secret = get_secret('prod/database')\nexcept ClientError as e:\n # Handle AWS-specific errors\n pass\nexcept KeyError as e:\n # Handle missing key errors\n pass\n```\n\n## Performance Considerations\n\n- The module maintains a single boto3 client instance\n- Caching is enabled by default to minimize API calls\n- Timeout settings: 2 seconds for both connect and read\n- Maximum retry attempts: 3\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Django integration for AWS Secrets Manager with caching and lazy loading support",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/efficient-solutions/django-simple-secrets"
},
"split_keywords": [
"django",
" aws secrets manager"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b8a521cc5d6ba1eb3cd7337ff6e7a2d7b12f803811e575f4adce6d19e054aae0",
"md5": "830d951abfbbc1a6cebf4f2f7cb8b22e",
"sha256": "55f9ab17b630bb9f141e4b73d52312b70c46c733a42db10dbd400ddf8f17a716"
},
"downloads": -1,
"filename": "django_simple_secrets-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "830d951abfbbc1a6cebf4f2f7cb8b22e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 5596,
"upload_time": "2024-10-27T01:59:26",
"upload_time_iso_8601": "2024-10-27T01:59:26.609132Z",
"url": "https://files.pythonhosted.org/packages/b8/a5/21cc5d6ba1eb3cd7337ff6e7a2d7b12f803811e575f4adce6d19e054aae0/django_simple_secrets-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "314976f74eb9cefe1455956052be54ccbc6b19b8be7e74d5b09fc52ce7fe1d99",
"md5": "3a7adb24e791e6100eecaef40ee5a912",
"sha256": "261448e9c8784e5d14e3abdf9a80b9a73cc2ad7f53d6d1a90835f03b470c7f92"
},
"downloads": -1,
"filename": "django-simple-secrets-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "3a7adb24e791e6100eecaef40ee5a912",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 5320,
"upload_time": "2024-10-27T01:59:28",
"upload_time_iso_8601": "2024-10-27T01:59:28.765381Z",
"url": "https://files.pythonhosted.org/packages/31/49/76f74eb9cefe1455956052be54ccbc6b19b8be7e74d5b09fc52ce7fe1d99/django-simple-secrets-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-27 01:59:28",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "efficient-solutions",
"github_project": "django-simple-secrets",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "Django",
"specs": [
[
"<",
"6"
],
[
">=",
"4"
]
]
},
{
"name": "boto3",
"specs": [
[
">=",
"1.35"
],
[
"<",
"2"
]
]
},
{
"name": "twine",
"specs": [
[
">=",
"5.1"
],
[
"<",
"5.2"
]
]
}
],
"lcname": "django-simple-secrets"
}