Encrypted Credentials for Django and FastAPI

Secure Credentials Kit keeps environment-specific application credentials in encrypted YAML files instead of plaintext settings files.

Supported features

  • Encrypted, environment-specific YAML credentials with signed files.
  • A CLI for generating keys and editing credentials, with separate master and read-only runtime keys.
  • Django management commands and a credentials loader.
  • FastAPI helpers for loading credentials into application state and dependencies.

Install

Install the Django extra; for FastAPI, replace django with fastapi:

pip install "secure-credentials-kit[django]"

Usage example

Generate a key pair with secure-credentials-kit generate-key <environment>. For production, run secure-credentials-kit edit production, add a DATABASE_URL entry in the encrypted YAML, then load it in Django:

from secure_credentials_kit.secrets_loader import decrypt_credentials

credentials = decrypt_credentials("production")
database_url = credentials.get("DATABASE_URL")

Django and FastAPI integration

Django: Add secure_credentials_kit to INSTALLED_APPS. Its credentials_generate_key and credentials_edit management commands provide the same workflow; decrypt_credentials("production") loads values in the app.

FastAPI: Call setup_secure_credentials_kit(app, "production") and use credentials_dependency() to access credentials in route dependencies.

Store keys securely

Keep secrets/*.key out of Git. Store the master key in an access-controlled secret store and provide the application runtime with only its read-only key.

GitHub repository PyPI package