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

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.2.0.tar.gz (11.4 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.2.0-py3-none-any.whl (13.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: secretpath-0.2.0.tar.gz
  • Upload date:
  • Size: 11.4 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.2.0.tar.gz
Algorithm Hash digest
SHA256 e1f66933ac3849668b303913224831daac9cffe913525a197bb26dde1d61fc3e
MD5 5b1cfb30712e505c8d3382191e28cf1e
BLAKE2b-256 1ba9b9fe863f4ad62f27de5525fa0176fc5c45bc91d465cc943b9ebb66b90196

See more details on using hashes here.

File details

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

File metadata

  • Download URL: secretpath-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.9 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8c3c06777363dd4625d5c2974abba1bed8d2b1b043d32b93271a191f5acd579
MD5 6fca04dd027c9f00eae889f8d6edb4a1
BLAKE2b-256 95db62d777a73deb04a4ad52399fe7d2f18e7fbb86372df7033e71bdc9ca03ff

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