Skip to main content

A tiny op-first secret resolver with environment fallback.

Project description

secretpath

secretpath resolves application secrets from a short, explicit provider path:

  1. 1Password CLI references through op read
  2. Environment variables

It is designed for CLIs and local automation that should prefer 1Password when available, fall back to environment variables when appropriate, and report where the secret came from without logging the secret itself.

secretpath never writes resolved secret values to disk. Its cache is process-local memory only.

Install

pip install secretpath

For local development:

uv sync
uv run pytest
uv run ruff check src tests

Quick Start

from secretpath import resolve_secret

result = resolve_secret(
    "Canvas API key",
    provider="auto",
    op_reference="op://Vault/Canvas/credential",
    env_var="CANVAS_API_KEY",
)

api_key = result.value
print(f"Using API key from {result.source}")

Use environment variables to avoid putting op://... references in project files:

result = resolve_secret(
    "ANTHROPIC_API_KEY",
    provider_env="MYAPP_SECRET_PROVIDER",
    op_reference_env="MYAPP_ANTHROPIC_API_KEY_OP_REFERENCE",
)

For prefix-based project conventions:

from secretpath import resolve_env_secret

result = resolve_env_secret("ANTHROPIC_API_KEY", prefix="PIPYER")

That reads:

  • PIPYER_SECRET_PROVIDER
  • PIPYER_ANTHROPIC_API_KEY_OP_REFERENCE
  • ANTHROPIC_API_KEY

For application doctor commands, reuse the same sanitized setup diagnostics as the CLI:

from secretpath import doctor_report

payload = doctor_report(check_resolution=True)

The payload reports provider availability, config files, permissions, configured secret names, optional resolution status, and issues without resolved secret values or direct op://... references.

Named Config

Local .secretpath.toml and global ~/.config/secretpath/config.toml files can store secret lookup metadata. They should contain references and environment variable names, not resolved secret values.

[defaults]
provider = "auto"

[secrets.canvas]
env_var = "CANVAS_API_KEY"
op_reference = "op://Vault/Canvas/credential"

[secrets.anthropic]
env_var = "ANTHROPIC_API_KEY"
op_reference_env = "MYAPP_ANTHROPIC_API_KEY_OP_REFERENCE"

Then:

from secretpath import resolve_named_secret

result = resolve_named_secret("canvas")

See docs/config.md for precedence and file discovery.

CLI

The CLI checks whether a secret resolves without printing the secret:

secretpath check canvas
sp check canvas
secretpath check canvas --json
secretpath list
secretpath config path
secretpath config init
secretpath config show
secretpath doctor
secretpath doctor --check
sp direnv init openai anthropic
secretpath check ANTHROPIC_API_KEY --prefix PIPYER
secretpath check API_KEY --no-config --env-var API_KEY
python -m secretpath check canvas

sp is a short alias for the secretpath command.

See docs/cli.md.

Behavior

  • provider="auto" tries 1password first, then env.
  • provider="1password" only tries op read.
  • provider="env" only reads the environment variable.
  • env_var defaults to name.
  • environment-sourced results report env:<env_var>, such as env:CANVAS_API_KEY.
  • required=False returns a SecretMiss with non-secret attempt metadata.
  • resolved values are cached in process memory by default.
  • clear_cache() clears the process-local cache.
  • clear_cache(name) clears entries for one logical secret name.

Error messages name providers tried, but intentionally avoid including op://... references, environment variable names, raw op stderr, or secret values.

Documentation

Why No Durable Secret Cache?

secretpath treats 1Password or the environment as the durable authority. A disk cache would create another secret store with weaker rotation and audit semantics. The built-in cache is intentionally limited to the current Python process.

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

secretpath-0.3.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

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

secretpath-0.3.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file secretpath-0.3.0.tar.gz.

File metadata

  • Download URL: secretpath-0.3.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.20 {"installer":{"name":"uv","version":"0.11.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for secretpath-0.3.0.tar.gz
Algorithm Hash digest
SHA256 38b83ab5828f05f256387989701e9aa6ceaf2332ac7f5b35682d5ff9ec42136c
MD5 2b5deffa8e169cfa4e8d8edc3848d23b
BLAKE2b-256 62e39fd2f53420474e774d9ca03b5c0d77e67b5f0f6cf459313fb0d615510030

See more details on using hashes here.

File details

Details for the file secretpath-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: secretpath-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.20 {"installer":{"name":"uv","version":"0.11.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for secretpath-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c67540df688081c4938d391f9f694582c5c499fb32c39f3362cce5596773f001
MD5 943f55165f51e1c99cc1a07396fdf12b
BLAKE2b-256 bf14966c5623a48ddb5408a57ab6178081bbfb021da5c30c23e38467063fad53

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