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.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| secrefs-0.3.0.tar.gz | 25.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| secrefs-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 57.1 kB
Release files / secrefs-0.3.0.tar.gz
| Download URL | secrefs-0.3.0.tar.gz |
|---|---|
| Size | 25.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20b3b76da9ec50e03a22b308d58d3ae8fcd25f8f4b0fa5155750a57ec2cbf5cd
|
|
BLAKE2b-256 checksum How to use checksums |
13f575f395650674a545a0f233f8a691efba4bb102f953d804304c5dbaf55b08
|
| 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 11, 2026.
Transparency logRelease files / secrefs-0.3.0-py3-none-any.whl
| Download URL | secrefs-0.3.0-py3-none-any.whl |
|---|---|
| Size | 31.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8d0e6a32fbbef33cc472880e805e05dc57928fa7cb6bdf9495f45fc9bca48df3
|
|
BLAKE2b-256 checksum How to use checksums |
eb5aa55365cdd63727853d61ea6edf991670058457d2118ca65b2aa099cf4bd1
|
| 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 11, 2026.
Transparency log