Skip to main content

A command-line utility that allows you to run any command with environment variables automatically injected from a KeePass database.

Project description

GitHub Workflow Status PyPI version python

with-keepass

with-keepass is a command-line utility that allows you to run any command with environment variables automatically injected from a KeePass database.

This is especially useful for securely managing sensitive credentials (like API keys, AWS tokens, or database passwords) without hardcoding them into scripts, leaving them in plaintext in your shell history or exposing them in the parent shell.

Why use with-keepass?

  • Ephemeral secrets: Environment variables exist only for the lifetime of the executed process. They are not stored in your shell, not written to history, and vanish as soon as the command finishes.

  • Reduced risk: Since the parent shell is never modified, secrets are isolated to the command being run and its child processes.

  • KeePass integration: This lets you use an existing, trusted password manager as the single source of truth for sensitive data.

  • Practical workflow: Instead of hardcoding secrets or exporting them manually, you inject them only when needed — making secret use explicit and controlled.

Installation

pip install with-keepass

Loading secrets from a KeePass group or KeePass entry

with-keypass is able to load environment variables from either a KeePass Group or KeePass Entry.

A KeePass Group contains multiple entries, where each entry:

Title → becomes the environment variable name.

The custom string field named value → becomes the environment variable value.

A KeePass Entry contains multiple custom string fields, where each field is treated as key value pair.

Usage

with-keypass will prompt for the master password of the KeePass database.

usage: with-keypass [-h] [--db DB_PATH] [--path PATH] [--dry-run] ...

Execute a command with environment variables loaded from KeePass.

positional arguments:
  command       Command to execute; must be preceded by -- (not required with --dry-run)

options:
  -h, --help    show this help message and exit
  --db DB_PATH  Path to KeePass .kdbx database file (default: $HOME/.kp.kdbx)
  --path PATH   path to KeePass entry or KeePass group containing the secrets to load (default: EnvVars)
  --dry-run     Print NAME=value pairs and exit; do not exec a command (default: False)

Examples

Run AWS CLI with injected credentials:

with-keypass --path AwsSecrets --field-name value -- \
    aws s3 ls

Preview environment variables:

with-keypass --dry-run
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

Run kubectl with secrets from a custom DB:

with-keepass --db "$HOME/.keepass/work.kdbx" --path 'Root/Secrets/K8s' -- \
    kubectl get pods --namespace=default

Exit Codes

Code Description
0 Success
1 Runtime error (failed to open DB, etc.)
2 Usage error (bad arguments, group not found, no secrets)
130 User aborted (Ctrl-C or password prompt canceled)

Development

Create and source virtual environment:

python -m venv venv && source venv/Scripts/activate

Install project in editable mode:

python -m pip install -e .[dev]

Lint the source code:

python -m flake8 -v with_keepass/ --max-line-length 100 --ignore=E302,E305

Run unit tests:

python -m unittest discover tests/ -v

Compute coverage report:

python -m coverage run -m unittest discover tests/
python -m coverate report -m

Run cyclomatic complexity:

python -m radon cc -s with_keepass/

Run bandit scan:

python -m bandit -r with_keepass/ --skip B606

Build the package:

python -m build

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

with_keepass-1.0.3.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

with_keepass-1.0.3-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file with_keepass-1.0.3.tar.gz.

File metadata

  • Download URL: with_keepass-1.0.3.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for with_keepass-1.0.3.tar.gz
Algorithm Hash digest
SHA256 def6e80ef10d4890132ca1d5e206b02c8a6e9d2b130bc03948f6f79109cf086f
MD5 e5ebf42631408bd9bc496e01a352fd54
BLAKE2b-256 2362a377bca3f20fa2d103a6516a14e07a3b771a931ba8d889e904fa349fe90d

See more details on using hashes here.

File details

Details for the file with_keepass-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: with_keepass-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for with_keepass-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e9ab9ae8749166123ea150670b60db6f503ea85256063a361a8f7ed669508761
MD5 95e875ca6253ec9b0196559118587add
BLAKE2b-256 b7b0bda2df76934ce28e46580b1bf070deb58211ef4c4b05039647c2cca9b69a

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