Skip to main content

A simple package to securely store and manage secrets.

Project description

Secrets Saver

A lightweight, FIPS 140-2/3 compliant Python library for securely storing and managing secrets.

SecretsSaver encrypts your data using AES-GCM and derives keys using PBKDF2HMAC (with SHA-256), provided by the standard cryptography library. It guarantees that users or applications are only prompted for the encryption/decryption key exactly once per instantiation.

It supports storing your encrypted secrets in:

  • A local file (JSON based)
  • A PostgreSQL database
  • A Microsoft SQL Server (MSSQL) database

Features

  • FIPS Compliant Cryptography: Uses AES-GCM for authenticated encryption and PBKDF2 with SHA-256 for secure key derivation.
  • One-Time Prompting: Automatically prompts for the master key securely using getpass exactly once per instance via standard input (safely hiding the password).
  • Flexible Storage: Works cleanly offline with local files but seamlessly transitions to PostgreSQL or MSSQL without changing how you interact with your secrets.
  • Simple API: Easy to use dictionary-like interface masked behind set_secret and get_secret.

Installation

You will need the cryptography library. If you intend to use the database features, you will also need SQLAlchemy and the respective database drivers.

# For local file storage only
pip install cryptography

# For PostgreSQL support
pip install cryptography sqlalchemy psycopg2-binary

# For Microsoft SQL Server support
pip install cryptography sqlalchemy pyodbc

Usage

1. Local File Storage (Default)

from secrets_saver import SecretsSaver

# Prompts for the master key securely on first access.
db = SecretsSaver("secrets.ep")

# Store a secret
db.set_secret("api_token", "super_secret_value")

# Retrieve a secret
token = db.get_secret("api_token")
print(f"Retrieved token: {token}")

# List all stored keys
print(db.list_secrets())

2. PostgreSQL Storage

Pass a standard SQLAlchemy connection string via db_url.

from secrets_saver import SecretsSaver

db_url = "postgresql+psycopg2://admin:password@localhost:5432/my_database"
# Prompts for the master key; do not hardcode it in source.
db = SecretsSaver(db_url=db_url)

db.set_secret("db_password", "my_postgres_secret")
print(db.get_secret("db_password"))

3. Microsoft SQL Server (MSSQL) Storage

Pass the MSSQL connection string. Be sure the ODBC driver specified matches what is installed on your system.

from secrets_saver import SecretsSaver

db_url = "mssql+pyodbc://admin:password@localhost/my_database?driver=ODBC+Driver+17+for+SQL+Server"
# Prompts for the master key; do not hardcode it in source.
db = SecretsSaver(db_url=db_url)

db.set_secret("api_key", "my_mssql_secret")
print(db.get_secret("api_key"))

API Reference

SecretsSaver(filename="secrets.ep", db_url=None)

Initializes the class. If db_url is provided, it attempts to connect to the SQL database using SQLAlchemy, automatically creating an encrypted_secrets table if it does not exist. Otherwise, it defaults to the local file filename.

  • set_secret(key: str, value: str): Encrypts and saves a key-value pair to the database.
  • get_secret(key: str) -> str: Decrypts and retrieves the value for the given key. Returns None if the key does not exist.
  • list_secrets() -> list: Returns a list of all secret keys stored.
  • clear_database(): Deletes all secrets in the current database/file and overwrites the storage with an empty encrypted payload.

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

secrets_saver-0.1.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

secrets_saver-0.1.1-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file secrets_saver-0.1.1.tar.gz.

File metadata

  • Download URL: secrets_saver-0.1.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for secrets_saver-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2f9e33ef27da94adb304465c02446c4080343cf0ef47caf32f9f619b6aac860b
MD5 6307162bb73e31c428190f71c0d31092
BLAKE2b-256 8b9e0892426870c7816c9e2c08350cb54154bec5731ea3aa3746cdef120c80ed

See more details on using hashes here.

File details

Details for the file secrets_saver-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: secrets_saver-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for secrets_saver-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1a8b06878eac3d979b9b61483d5e23bc93caf7fb62a0a6d7f9f0c6f7f072dadb
MD5 34995510caa132024c54bf3fcf0bd3e3
BLAKE2b-256 e41b0e72a47dbe783f88cbd4c791c1b3bff5965e4b1e1634767fe2c67c157332

See more details on using hashes here.

Supported by

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