An Infisical secrets source for pydantic-settings.
Project description
pydantic-settings-infisical
An Infisical secrets source for pydantic-settings.
Declare your configuration as a typed BaseSettings class and load values from an
Infisical project — alongside (and with the usual precedence over) environment
variables and dotenv files.
Install
pip install pydantic-settings-infisical
Usage
from pydantic_settings import BaseSettings, SettingsConfigDict
from pydantic_settings_infisical import InfisicalSettingsSource
class Settings(BaseSettings):
model_config = SettingsConfigDict(
infisical_project_id="a0ccf8d8-8978-429d-91f5-59baefa1601c",
infisical_environment="prod", # default: "prod"
# infisical_host="https://app.infisical.com", # or self-hosted
# infisical_secret_path="/",
)
DB_HOST: str
DB_PASSWORD: str
@classmethod
def settings_customise_sources(cls, settings_cls, init_settings, env_settings, dotenv_settings, file_secret_settings):
return (
init_settings,
InfisicalSettingsSource(settings_cls), # Infisical wins over env/dotenv here
env_settings,
dotenv_settings,
file_secret_settings,
)
settings = Settings()
Authentication
Set one of the following (via env var, model_config, or a source kwarg):
- Service token:
INFISICAL_TOKEN - Machine identity (Universal Auth):
INFISICAL_CLIENT_ID+INFISICAL_CLIENT_SECRET
Configuration
Every connection parameter resolves in this order: explicit source kwarg → model_config key → environment variable.
| Parameter | model_config key |
Environment variable | Default |
|---|---|---|---|
| host | infisical_host |
INFISICAL_HOST |
https://app.infisical.com |
| project id | infisical_project_id |
INFISICAL_PROJECT_ID |
(required) |
| environment | infisical_environment |
INFISICAL_ENVIRONMENT |
prod |
| secret path | infisical_secret_path |
INFISICAL_SECRET_PATH |
/ |
Mapping fields to secret names
Each field is looked up by its Infisical secret name, resolved from the field's
validation_alias (the first string of an AliasChoices), else its alias, else the
field name. This lets you map Python-friendly field names to Infisical's naming:
from pydantic import Field, AliasChoices
class Settings(BaseSettings):
# reads the Infisical secret "POSTGRE-SCC--HOST", falls back to the DB_HOST env var
db_host: str = Field(validation_alias=AliasChoices("POSTGRE-SCC--HOST", "DB_HOST"))
Error handling
By default a missing secret or any Infisical error is non-fatal — the value simply
falls through to the remaining settings sources (env, dotenv, …). Pass
InfisicalSettingsSource(settings_cls, raise_on_error=True) to fail loudly instead.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pydantic_settings_infisical-0.1.0.tar.gz.
File metadata
- Download URL: pydantic_settings_infisical-0.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.12 {"installer":{"name":"uv","version":"0.9.12"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b88c2da8419a408b078de96d5582c77c6cdb1db6410ef02fb462aec49a454a2a
|
|
| MD5 |
2ebc0d6e648955d060c05176945c9e0a
|
|
| BLAKE2b-256 |
141105584da81792e70ac4ed3b09b5da7cc3edebc3eb4a4749ddf73f0887fe7a
|
File details
Details for the file pydantic_settings_infisical-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydantic_settings_infisical-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.12 {"installer":{"name":"uv","version":"0.9.12"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9482393debcf96084dc2d8b89cf4a4077c0071e47f565cd10a4894c375e9549
|
|
| MD5 |
09dbee9ca1855d8f6eef755d4c473fa6
|
|
| BLAKE2b-256 |
9c618940572ab8921535d05970bcd26194b784f05275471d891a30dde43c4aee
|