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

# Will prompt for a key if secrets.db doesn't exist or upon first access
db = SecretsSaver("secrets.db")

# 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"
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"
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.db", 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.0.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.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: secrets_saver-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 ac694b3777881f46d14382f4ea9b8d47c09839d80f47510d178ee19b4da9bab3
MD5 8d9c9e9d9f044779eaa2b90141154ad9
BLAKE2b-256 ee9fd6af9b226f9265853bd0cd43fb9a1c8d9423b28b01a99345ce33f38bc453

See more details on using hashes here.

File details

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

File metadata

  • Download URL: secrets_saver-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8beb180a4578dfdd3fd825ff616a62998406aee0005edc968e7a8b6b613007fd
MD5 73465e6015e42d28871ddfe74837edc0
BLAKE2b-256 d8fc36901cac334edcf27249cb8e1c04e13ecf145ed6c6bf288955a79de669a5

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