Skip to main content

A simple python library to safely store your passwords using encription

Project description

Secure Password Vault

A lightweight, thread-safe, file-backed password vault that encrypts entries using a master password. It provides a simple API to add, retrieve, and list secrets, while ensuring data integrity through HMAC and protecting against concurrent access with file locks.


Table of Contents


Features

  • AES‑GCM encryption of each entry via cryptography.Fernet.
  • Argon2id key derivation for strong password-based key stretching.
  • Integrity checking with HMAC-SHA256 over the entire vault.
  • Inter-process file locking (filelock) to prevent concurrent writes.
  • Threaded queue to serialize file operations in a dedicated worker.
  • Configurable password caching with auto-lock after inactivity.
  • Custom subclass NumericValue for automatically sorting numeric keys.

Requirements

This project uses Poetry for dependency management. Ensure you have Poetry installed.

Required Python version:

  • Python 3.12+

Dependencies are specified in pyproject.toml and will be installed automatically by Poetry.

Installation

Install the library via Poetry from PyPI:

poetry add password-vault

Or to install for development:

git clone https://github.com/matteogabburo/password-vault.git
cd password-vault
poetry install

Then import and use the Vault class in your project:

from vault import Vault
```python
from vault import Vault

Usage

Initializing or Opening a Vault

# Creates a new vault if file doesn't exist, or opens existing.
vault = Vault(filepath="./mysecret.vault", master_password=None, keep_unlocked=10)
  • If mysecret.vault does not exist, you will be prompted for a new master password (unless provided).
  • If it exists, you will be prompted to verify your password (unless provided).
  • keep_unlocked is seconds to cache the password before re-prompting.

Adding Secrets

# Add a new secret with key "api_token" and value "s3cr3t"
vault.add(key="api_token", secret="s3cr3t")

Raises WalletError on lock timeout or I/O issues.

Retrieving Secrets

token = vault.get(key="api_token")
print(token)  # "s3cr3t"
  • Returns a NumericValue for numeric-style secrets (e.g. "value1").
  • Raises KeyNotFoundError if the key is absent.

Listing Keys

keys = vault.list_keys()
print(keys)  # ["api_token", ...]

Closing the Vault

vault.close()

Stops the internal worker thread and releases resources. Automatically invoked on program exit.

API Reference

Class: Vault

Method Description
__init__(filepath, master_password=None, keep_unlocked=10) Initialize or open a vault file. Prompt if needed.
add(key, secret, master_password=None) Encrypt and store a secret.
get(key, master_password=None) -> str Decrypt and return a secret.
list_keys(master_password=None) -> list Return list of stored keys.
close() Gracefully stop worker thread.

Class Attributes

  • KDF_ITERATIONS: Number of iterations for Argon2id KDF.
  • FILE_MODE: File permissions (default 0o600).
  • LOCK_TIMEOUT: Seconds to wait for the file lock (default 5).

Exceptions

  • WalletError: Base exception for vault errors.
  • WalletNotFoundError: File does not exist.
  • InvalidPasswordError: Wrong master password.
  • KeyNotFoundError: Secret key not found.
  • MalformedWalletError: Vault JSON is invalid or missing fields.

Security Considerations

  • Do not share your master password.
  • Vault file is created with owner-only permissions.
  • Entries are individually encrypted and integrity-protected.
  • Argon2id settings: 64 MiB memory, parallelism 4, 3 iterations.
  • HMAC key derived from the same Argon2id output, ensuring tamper-detection.

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

password_vault-1.0.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

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

password_vault-1.0.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file password_vault-1.0.0.tar.gz.

File metadata

  • Download URL: password_vault-1.0.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-62-generic

File hashes

Hashes for password_vault-1.0.0.tar.gz
Algorithm Hash digest
SHA256 80b1ab47c1cdc175d5c5d4fae50b38ea25c82d7e810a35cc7bc10ef60f9f1518
MD5 446e3fe6d5e7c72abb9ea3e5e98b27f4
BLAKE2b-256 530359a0e88f15df6ab04bbb9cdae8ee92d12df7b16db46a59403fb954539d1b

See more details on using hashes here.

File details

Details for the file password_vault-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: password_vault-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.3 Linux/6.8.0-62-generic

File hashes

Hashes for password_vault-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ac4a2488ae236584b06ed6bed27e471dafea96d4615216d3c52bf0ada38b3e7b
MD5 2d04872d6aac059d849a70b34afd5e6f
BLAKE2b-256 d9de598c251cc036f868f76c69129e3b3a9ad95f89c780a42d4d7427f1dec29a

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