Skip to main content

Locke — Python

Unified credentials framework — encrypted config, OS keystore, Vaultwarden and OpenBao integration.

Install

For local development from this repository:

cd python
pip install -e ".[dev]"

From the repository root on macOS, install the public Locke CLI/package locally:

python3 -m pip install -e ./python
locke --version

The locke executable is installed into the active Python environment's bin directory, so make sure that directory is on your PATH.

Usage

Library

import locke

# Load and decrypt config → flat env vars
env = locke.load_config(".locke/config.encrypted.json")
# env["MONGO_URI"], env["SENTRY_DSN"], etc.

# Resolve a single credential
cred = locke.resolve_credential("LOCKE_ENCRYPTION_KEY")

# Get or set a vault secret
secret = locke.get_vault_secret("myproject/staging/api_key")
locke.set_vault_secret("myproject/staging/api_key", "new-value")

# Check Locke-owned setup placeholders ("FILL_ME")
if locke.is_placeholder(secret):
    raise RuntimeError("vault secret still needs a real value")

CLI

# Decrypt + flatten → shell exports
eval $(locke env)

# Decrypt to stdout
locke decrypt

# Encrypt plaintext config
locke encrypt

# Manage OS keystore
locke keystore set LOCKE_ENCRYPTION_KEY --prompt
locke keystore get LOCKE_ENCRYPTION_KEY

# Get vault secret
locke vault get myproject/staging/api_key

# Create missing vault entries from locke.json, then fill them interactively
locke vault setup
locke vault setup --interactive

# Get/set an OpenBao KV secret
locke openbao get myproject/staging/api_key
locke openbao set myproject/staging/api_key --password "new-value"

# Initialize project
locke init --project myproject --tenant staging

# Encrypt every config.{environment}.json[c] using project-root .env settings
locke genkeys

# Convert JSONC to strict JSON
locke strip-jsonc input.jsonc output.json

Project tools on PATH

Installing Locke provides locke-genkeys and locke-strip-jsonc as standalone commands, as well as locke genkeys and locke strip-jsonc subcommands.

From any directory below a project root, locke genkeys finds the nearest ancestor containing .env and reads:

LOCKE_INPUT_DIR=../shared-configs/myproject
LOCKE_OUTPUT_DIR=.locke
LOCKE_KEY_NAME=MYPROJECT_CONFIG_ENCRYPTION_KEY

Relative paths are resolved from the discovered project root. CLI options take precedence over process environment variables, which take precedence over the project .env. LOCKE_OUTPUT_DIR defaults to .locke. Use --project-root to select a root explicitly.

OpenBao KV

Locke can also read/write secrets from an OpenBao KV v1/v2 mount, using the same shape as the Vaultwarden client (get_secret/set_secret, get_secret_pair/set_secret_pair):

secret = locke.get_openbao_secret("myproject/staging/api_key")
locke.set_openbao_secret("myproject/staging/api_key", "new-value")

Connects via LOCKE_OPENBAO_ADDR/OPENBAO_ADDR/VAULT_ADDR and LOCKE_OPENBAO_TOKEN/OPENBAO_TOKEN/VAULT_TOKEN. See locke/openbao.py for the full env var list (mount, KV version).

Vault placeholders

Locke uses locke.PLACEHOLDER_VALUE ("FILL_ME") for vault entries that are known but not filled yet. Use locke.is_placeholder(value) instead of hard-coding the sentinel. VaultClient.get_secret() warns when it returns a placeholder; VaultClient.set_secret(path, None) or an empty value writes a placeholder and warns.

Vault connection settings from .env

LOCKE_VAULT_URL and LOCKE_VAULT_USERNAME are read from the process environment first. In development and staging, Locke falls back to a .env file in the current working directory. Production ignores .env and requires real environment variables. The vault password is not read by this fallback: LOCKE_VAULT_PASSWORD continues through the keystore-first credential pipeline.

Environment Variables

Variable Purpose
LOCKE_ENV Override environment detection
LOCKE_ENCRYPTION_KEY Encryption key (if not in keystore)
LOCKE_USE_BIOMETRIC Set false to disable biometric gating
LOCKE_VAULT_URL Vaultwarden server URL; current-directory .env fallback outside production
LOCKE_VAULT_USERNAME Vaultwarden username; current-directory .env fallback outside production
LOCKE_INPUT_DIR genkeys plaintext config directory, absolute or project-root relative
LOCKE_OUTPUT_DIR genkeys output directory (default .locke)
LOCKE_KEY_NAME Credential name used by genkeys
LOCKE_OPENBAO_ADDR OpenBao server URL (falls back to OPENBAO_ADDR/VAULT_ADDR)
LOCKE_OPENBAO_TOKEN OpenBao token (falls back to OPENBAO_TOKEN/VAULT_TOKEN)

Testing

cd python
pip install -e ".[dev]"
pytest

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

locke-0.10.0.tar.gz (100.2 kB view details)

Uploaded Source

Built Distribution

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

locke-0.10.0-py3-none-any.whl (67.0 kB view details)

Uploaded Python 3

File details

Details for the file locke-0.10.0.tar.gz.

File metadata

  • Download URL: locke-0.10.0.tar.gz
  • Upload date:
  • Size: 100.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for locke-0.10.0.tar.gz
Algorithm Hash digest
SHA256 e1b3ae1b5a3c1fdb7c5bd0f524475eb8350b7c206d653e7af4937972ffd21554
MD5 734e45ba3f13bee823cf01e46051d53c
BLAKE2b-256 78568749444b18eef75b38feda549557a468de3b47505637208cadf0e791c96a

See more details on using hashes here.

File details

Details for the file locke-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: locke-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 67.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for locke-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a308fe59c9e9c250867167912dc6968754646fda78d955345f490e561339789
MD5 506bc171bd9547b7740cf8bee063bbc9
BLAKE2b-256 82163bc80ac3ab3d9ca4f005130494d09a34741d8fff734c11f2b2db20ca954e

See more details on using hashes here.

Release history Release notifications | RSS feed

0.11.0

2 files

This release

0.10.0 This release

2 files

0.9.1

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.1

2 files

0.5.2

2 files

0.5.1

2 files

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