vaultdantic
vaultdantic extends pydantic-settings with a vault-backed fallback source.
If you're already in the pydantic ecosystem, pydantic-settings makes it easy to specify your environment configuration as env files and load them at runtime. When you're working on a remote production app, you probably only need these global environment keys. But when you're working locally on side projects, it's way more convenient to store your environment parameters in a vault like 1Password. This lets you delete the contents of your machine and restore your secrets with a simple vault pull.
BaseSettings inputs continue to win in normal priority order (init args, env vars, .env, file
secrets), and the vault provider is only queried when required fields are still missing.
Usage
from pydantic import SecretStr
from pydantic_settings import BaseSettings, SettingsConfigDict
from vaultdantic import OnePasswordConfigDict, VaultMixin
class ExampleSettings(BaseSettings, VaultMixin):
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
env_prefix="EXAMPLE_",
extra="ignore",
)
model_vault_config = OnePasswordConfigDict(
vault="Engineering",
entry="example-service",
)
api_token: SecretStr
workspace_id: str
When ExampleSettings() is created, values are resolved in this order:
pydantic-settingsloads normal sources first (__init__kwargs, environment,.env, and file secrets).- If required fields are still missing,
OnePasswordConfigDict.get_vars()is called and only missing keys are filled from the vault entry. - Any key already provided by earlier sources keeps precedence over vault values, then the final model is validated.
Vault field labels should use env-style keys (for example EXAMPLE_API_TOKEN, not api_token).
For nested fields, follow pydantic-settings rules: use env_nested_delimiter (for example
PARENT_CHILD__TOKEN when env_nested_delimiter="__").
Vault Providers
| Provider | Config Class |
|---|---|
| 1Password | OnePasswordConfigDict |
CLI
We also provide convenience methods to sync your vaults into an .env file, to make it easier to sync to a remote host or use in Docker. Sync all discovered vault values into .env:
uv run sync-vault-to-env
This will write your credentials in a special managed-by-vaultdantic section. We will overwrite this section on any subsequent syncs so we recommend leaving it alone.
# start managed by vaultdantic
...
# end managed by vaultdantic
Development
make sync
make lint
make test
make build
Metadata
Release files for vaultdantic 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vaultdantic-0.1.2.tar.gz | 11.4 kB | Without provenance | Details for vaultdantic-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vaultdantic-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for vaultdantic-0.1.2-py3-none-any.whl |
Total release size: 25.0 kB
Release files / vaultdantic-0.1.2.tar.gz
| Download URL | vaultdantic-0.1.2.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a929b5f0a7d2cc872658b3254ede6d236da27228446685c67d9b3c5001a1e2b3
|
|
BLAKE2b-256 checksum How to use checksums |
c90a9fa4e5531ba9542aed68d53958ff39922be2e005826ed1cdeeaad28c0bbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.13
|
Release files / vaultdantic-0.1.2-py3-none-any.whl
| Download URL | vaultdantic-0.1.2-py3-none-any.whl |
|---|---|
| Size | 13.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23b9989539d8ecc99ab7232ba38e397fb7a292e6b5b9a8e046eb31b746dfd51f
|
|
BLAKE2b-256 checksum How to use checksums |
d0ee885de0122655a29b103d4f28501787bba66dcd197c34417cfb05ae4e3400
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.13
|
Security for vaultdantic 0.1.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.