Skip to main content

A simple Python SQLite3-based key-value storage vault

Project description

Fernet Key Vault

A simple Python SQLite3-based key-value storage vault for securely storing and retrieving data. Note: Despite the repository name, the current implementation does not include Fernet encryption.

Features

  • Store key-value pairs in an SQLite database
  • Retrieve values using their associated keys
  • Delete entries from the vault
  • Automatic database initialization
  • Error handling and input validation

Installation

From Source

You can install the package directly from the source code:

# Clone the repository
git clone https://github.com/kvcrajan/FernetKeyVault.git
cd FernetKeyVault

# Install the package
pip install .

For development, you can install the package in editable mode:

pip install -e .

Dependencies

No special dependencies are required beyond Python's standard library. The implementation uses the built-in sqlite3 module.

Usage

Basic Usage

from database_vault import DatabaseVault  # Import the DatabaseVault class

# Initialize the vault (creates vault.db by default)
vault = DatabaseVault()

# Add entries
vault.add_entry("username", "admin")
vault.add_entry("api_key", "sk_test_abcdefghijklmnopqrstuvwxyz")

# Retrieve entries
username = vault.retrieve_entry("username")
print(f"Username: {username}")  # Output: Username: admin

# Delete entries
vault.delete_entry("username")

Custom Database Path

You can specify a custom path for the database file:

from database_vault import DatabaseVault

vault = DatabaseVault(db_path="/path/to/custom/vault.db")

Error Handling

The methods return appropriate values to indicate success or failure:

  • add_entry(): Returns True if successful, False otherwise
  • retrieve_entry(): Returns the value if found, None otherwise
  • delete_entry(): Returns True if an entry was deleted, False otherwise

API Reference

DatabaseVault(db_path="vault.db")

Initialize a new DatabaseVault instance.

Parameters:

  • db_path (str, optional): Path to the SQLite database file. Defaults to "vault.db".

add_entry(key, value)

Add a key-value pair to the vault. If the key already exists, its value will be updated.

Parameters:

  • key (str): The key for the entry
  • value (str): The value to store

Returns:

  • bool: True if successful, False otherwise

Raises:

  • TypeError: If key or value is not a string

retrieve_entry(key)

Retrieve a value from the vault using its key.

Parameters:

  • key (str): The key to look up

Returns:

  • str or None: The value associated with the key, or None if the key doesn't exist

Raises:

  • TypeError: If key is not a string

delete_entry(key)

Delete an entry from the vault using its key.

Parameters:

  • key (str): The key of the entry to delete

Returns:

  • bool: True if an entry was deleted, False otherwise

Raises:

  • TypeError: If key is not a string

Testing

Run the included test script to verify the functionality:

python test_database_vault.py

The test script creates a temporary database, tests all functionality, and then removes the test database.

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

fernetkeyvault-1.0.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

fernetkeyvault-1.0.0-py3-none-any.whl (2.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fernetkeyvault-1.0.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for fernetkeyvault-1.0.0.tar.gz
Algorithm Hash digest
SHA256 06adb1d6cf69cd03f27e2cdb393f2b667c88af5f0c1fad0e05635f95b213efac
MD5 750a73586c6de68a234d96013cc074c8
BLAKE2b-256 aba853ad480554e47b22a4bd73097a46052bea5ecaa1a70cbda9589adff1f4f8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fernetkeyvault-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 2.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for fernetkeyvault-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8cf8aa88cb85b94665f4f7435a2b025b2913e2972a65e257c08b598a284cdcab
MD5 ec873af22a3ea4d823ec318aec8538f3
BLAKE2b-256 83c86649aad1f6f9b66e8700308b34f8b48f757c352e34353ac8e72a649f4ecb

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