Skip to main content

secrefs (Python)

Python SDK/CLI parity with @secrefs/node. See the repo root README for the full sec:// reference spec and provider list.

Install

pip install secrefs
# Bitwarden Secrets Manager support is an extra - see "Providers" below:
pip install 'secrefs[bitwarden]'
# or, in this monorepo:
poetry install

Library usage

import asyncio
import os
from secrefs import sec_refs

async def main():
    await sec_refs.init()  # expands sec:// values in os.environ, in place
    print(os.environ["DB_PASSWORD"])

asyncio.run(main())

Two ways to expand, and when each is wrong

A sec:// reference is a stable name for a value that changes. Which of these you use decides whether that actually holds:

At use (recommended). Expand where the secret is consumed. Every call re-fetches, so rotating the value at the source reaches this consumer with no redeploy:

async def call_vendor_api():
    key = await sec_refs.expand_string("sec://aws/hackerone#api_key")
    ...

At load (secrefs-py run). Expands once at startup and bakes plain strings into the child's environment. Convenient, and the right choice for short-lived processes like a CI job — but an environment variable is a static string, so a long-running process keeps the pre-rotation value until it restarts.

Network-backed providers re-fetch on every expansion by default. Concurrent expansions of the same reference still share one request, and cache_ttl_ms trades a bounded window of staleness for fewer round trips if you need it:

AWSSecretsManagerProvider(cache_ttl_ms=30_000)  # rotation lands within 30s

LocalProvider re-reads its JSON file per fetch for the same reason, so editing .secrefs.local.json mid-session takes effect; cache_file=True restores the old behavior.

Providers

Alias Backend Ambient auth
aws AWS Secrets Manager boto3's default credential chain
vault HashiCorp Vault (KV v1/v2) VAULT_ADDR / VAULT_TOKEN
bitwarden Bitwarden Secrets Manager BWS_ACCESS_TOKEN / BWS_ORGANIZATION_ID
local gitignored JSON file n/a - development only

bitwarden needs the secrefs[bitwarden] extra: Bitwarden secrets are end-to-end encrypted, so only Bitwarden's own SDK can decrypt them, and it ships as prebuilt native wheels for a fixed set of platforms. It's an extra rather than a hard dependency so a platform it doesn't build for can still install SecRefs.

Control-plane-sourced credentials

AWSSecretsManagerProvider and BitwardenProvider can source credentials per request from a running control plane instead of the ambient environment (see docs/control-plane-design.md), so each fetch is authenticated, RBAC-checked and audited on the control plane's side:

from secrefs import AWSSecretsManagerProvider, ControlPlaneCredentialSource

AWSSecretsManagerProvider(
    control_plane=ControlPlaneCredentialSource(
        base_url=os.environ["SECREFS_CONTROL_PLANE_URL"],
        token=os.environ["SECREFS_CONTROL_PLANE_TOKEN"],
        alias="aws-prod",
    )
)

CLI usage

secrefs-py run -- python app.py
secrefs-py check

Metadata

Release files for secrefs 0.2.0

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

Source distribution (sdist)

Source distribution for secrefs 0.2.0
File Size Uploaded
secrefs-0.2.0.tar.gz 21.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for secrefs 0.2.0
File Interpreter ABI Platform
secrefs-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 50.0 kB

Release files / secrefs-0.2.0.tar.gz

Download URL secrefs-0.2.0.tar.gz
Size 21.9 kB
Tags Source
SHA-256 checksum
How to use checksums
da631092bf9bfcc01c6dfabba1b2b1e1d01584c1fcfffe53abeaecb03b746504
BLAKE2b-256 checksum
How to use checksums
68ca7525a0471091006a34867f3775ff0defa76ce6950c01cb466806c7662037
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Release files / secrefs-0.2.0-py3-none-any.whl

Download URL secrefs-0.2.0-py3-none-any.whl
Size 28.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4291064e6739485d04d0f7fd015f2b35b52e5313610f20afde928681a8a2af8a
BLAKE2b-256 checksum
How to use checksums
5bc0f5d7fd95aca0b12b6adfbedff4e3d3172b52a7d4ed3265a4de4c632d9d75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 9, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.0

2 release files

This release

0.2.0 This release

2 release 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