Skip to main content

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' \
-- 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

make dev

Metadata

Release files for with-keepass 1.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for with-keepass 1.1.4
File Size Uploaded Provenance
with_keepass-1.1.4.tar.gz 12.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for with-keepass 1.1.4
File Interpreter ABI Platform
with_keepass-1.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 21.8 kB

Release files / with_keepass-1.1.4.tar.gz

Download URL with_keepass-1.1.4.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1d7e058b9bd75947dd9f4c87a74efde59682104ad0e7bbd10cbb90a374c1df3e
BLAKE2b-256 checksum
How to use checksums
98fb64bfee1cc59da957a6aa2dd341644f2d9173dd4f7d72f26ab11bc060080f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Release files / with_keepass-1.1.4-py3-none-any.whl

Download URL with_keepass-1.1.4-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
942591a630046d296a3b0ab151a7c45f91d8078cf7b09c48e1adfa80144712d4
BLAKE2b-256 checksum
How to use checksums
6667a5a7b3fb36b9dedb4739c0d27a712a1e198d0e880fcd8fbcdc4d44077e5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.11

Security for with-keepass 1.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page