Skip to main content

Locke — Python

Unified credentials framework — encrypted config, OS keystore, Vaultwarden, 1Password, 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

# Store a structured Login through the official op CLI (hidden password prompt)
locke config set onepassword_account my.1password.com
locke config set onepassword_vault Operations
locke onepassword set myproject/staging/db --username admin \
  --setting host=db.example.com --setting port=5432

# 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.

1Password

The Python backend stores exact Locke paths as structured Login-item titles. Account and vault scope are mandatory, exact-title duplicates fail closed, and secret fields are passed to the official op CLI over stdin:

from locke import OnePasswordClient

client = OnePasswordClient.connect()
client.set_secret_pair(
    "myproject/prod/mail",
    "user@example.com",
    "secret",
    url="https://mail.example.com",
    settings={"imap_port": "993", "smtp_port": "465", "tls": "true"},
)

Set LOCKE_ONEPASSWORD_ACCOUNT / LOCKE_ONEPASSWORD_VAULT, or persist the same non-secret scope with locke config set onepassword_account ... and locke config set onepassword_vault ....

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_ONEPASSWORD_ACCOUNT Explicit 1Password account URL/shorthand; falls back to user settings
LOCKE_ONEPASSWORD_VAULT Explicit 1Password vault name/ID; falls back to user settings
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.11.0.tar.gz (117.1 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.11.0-py3-none-any.whl (77.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for locke-0.11.0.tar.gz
Algorithm Hash digest
SHA256 4d1a303b01f3d848eb6b83349709613963cd0785cda9ad0cc43387a65147848d
MD5 d184cdb96f3838ffa96f3a4739b2a4b0
BLAKE2b-256 22b30b19af50a58c5ecc60e5d6e6311dda53cab3b4900f7617f7b71167bd7f2c

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for locke-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0154fa293bf473489bfbba52068d973a6da2453805981536b7a0479aad3eada
MD5 ee6c57f7c780e4cf7e8a5db815cb1dfc
BLAKE2b-256 705e3c247b84efcb078e5250f8cb2b5720ba83940eb67a26a3b0122ce60dbb9c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 files

0.10.0

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