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 Coverage PyPI version python

with-keepass

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 without hardcoding them into scripts, leaving them in plaintext in your shell history or exposing them in the parent shell.

Why use with-keepass?

Managing secrets is hard:

  • .env files leak — credentials often end up in repos, backups, or logs.

  • Shell pollution — exporting secrets into your parent shell keeps them around after you’re done.

  • Copy/paste risk — copying values from KeePass into terminals or scripts risks accidental exposure.

with-keepass solves this by:

  • Loading secrets directly from your KeePass database.

  • Injecting them as environment variables only into the child process (never your shell).

  • Ensuring secrets are ephemeral — they disappear when the process exits.

  • Working with any CLI tool or script (AWS CLI, kubectl, Python apps, etc.).

KeePass stays your single source of truth, while secrets stay safer.

Installation

pip install with-keepass

KeePass mapping model

Secrets can be loaded from either a KeePass group or a single entry:

  • Group path

    • Each entry inside the group becomes an environment variable.

    • Entry Title is the variable name

    • Custom string field value is the variable value

    Group path example

    Group: EnvVars
    Entry: API_KEY
      Title: API_KEY
      Custom String Field "value": abcd1234
    Entry: DB_PASS
      Title: DB_PASS
      Custom String Field "value": supersecret
    

    Produces:

    API_KEY=abcd1234
    DB_PASS=supersecret
    
  • Entry path

    • A single entry can hold multiple fields.

    • Each custom string field becomes an environment variable.

    Entry path example

    Entry: MyApp
    Title: MyApp
    Custom String Field "API_KEY": abcd1234
    Custom String Field "DB_PASS": supersecret
    Custom String Field "REGION": us-west-2
    

    Produces:

    API_KEY=abcd1234
    DB_PASS=supersecret
    REGION=us-west-2
    

Usage & Options

usage: with-keypass [-h] [--db-path 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-path DB_PATH  path to KeePass .kdbx database file
                                              (default: $HOME/.keypass/.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)

Notes

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

  • Separate with-keepass options from the target command with --.

  • The --path may refer to either a group or an entry.

  • Able to set --db-path and --path via the following environment variables respectively KEEPASS_DB_PATH and KEEPASS_PATH

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-path "$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)

Security considerations

  • Secrets are injected only into the executed process, never your shell.

  • Secrets live in process memory while running; downstream apps may still log them.

  • Master password is entered at runtime — do not hard-code it.

  • Ensure your KeePass DB file is stored securely.

  • Not a replacement for full secret-management services — use appropriately.

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 coverage report -m
coverage-badge -o badges/coverage.svg -f

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.1.2.tar.gz (12.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.1.2-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: with_keepass-1.1.2.tar.gz
  • Upload date:
  • Size: 12.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.1.2.tar.gz
Algorithm Hash digest
SHA256 e0691a19769f01315d89cf7d8677f7e6cbdcf16dcc62c05739c229df598eaac3
MD5 2ebb1111d630f1b2c2435e500cb8112f
BLAKE2b-256 829fba269dab788cc99a581079b3965e5b956f352275174cf18150f8f06260aa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: with_keepass-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.9 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.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1bc01c812e5d5a3c79aad542d3db42e8420eaa6cc0a7fa8f7797eacfb38e053f
MD5 266c81c3f51e9b7a268b51a09a58f658
BLAKE2b-256 bb2a88e7a096760377bd22959e50dce2d5cc3597d9b853e8cabfe935c367b54f

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