Hipster-orgazmic tool to mange application settings
Project description
Pydantic Settings
Library which extends pydantic functionality in scope of application settings.
Pydantic already have settings implementation, e.g. pydantic.BaseSettings
, but from my point it's missing some useful features, listed below.
Features
- Point exact location of a failed field in the text
- Override file values by environment variables, even if a field is nested
Allow to override values for nested fields if they are represented as pydantic model, dataclass
or attrs
dataclass. Here is example:
@dataclass
class Nested:
foo: int
class Settings(SettingsModel):
nested: Nested
try:
Settings.from_env({'APP_NESTED_FOO': 'NOT AN INT'})
except ValidationError as e:
assert e.raw_errors[0].env_loc = 'APP_NESTED_FOO'
- Shows right environment variable name for failed field
try:
Settings.from_env({'APP_nested_FOO': 'NOT AN INT'})
except ValidationError as e:
assert e.raw_errors[0].env_loc = 'APP_nested_FOO'
- Extracts field documentation from Sphinx style attributes documentation by processing AST tree of class definition
class Foo(SettingsModel):
class Config:
extract_docs = True
bar: str
"""here is docs"""
#: this style is't supported, but probably will be added in future
baz: int
assert Foo.__field__['bar'].schema.description == 'here is docs'
assert Foo.__field__['baz'].schema.description == '' # :(
- Render documentation examples with commentaries taken from fields description
class Settings(SettingsModel):
host: str = 'localhost'
"""
Self domain name
"""
auth_secret: SecretStr
"""
Secret key used to encrypt user tokens with HMAC-SHA256
"""
EXAMPLE_SETTINGS = Settings(
host='host.name',
auth_secret='5O5qOWiM5qnvUwvQtP1_bUTonSIn7I7C66eqVGL2it0=',
)
assert dumper(EXAMPLE_SETTINGS, 'yaml') == """
# Self domain name
host: host.name
# Secret key used to encrypt user tokens with HMAC-SHA256
auth_secret: 5O5qOWiM5qnvUwvQtP1_bUTonSIn7I7C66eqVGL2it0
"""
Development status
- partially, only json and yaml supported for now
- doesn't supports overriding inside list, case-sensitive implementation
- done
- done (attr classes not supported for now)
- not started
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
pydantic-settings-0.1.0a1.tar.gz
(16.0 kB
view hashes)
Built Distribution
Close
Hashes for pydantic-settings-0.1.0a1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a8a87d596732d21ad591e698e60a5ba0f0b292b1e80f33964b8271514b70fd4 |
|
MD5 | 032117be71904e5283aa1acf69748a4c |
|
BLAKE2b-256 | cc600862fc0e3be14c46a1b39a1be9046ae5484ea7cdfa89897fabcb93e308f8 |
Close
Hashes for pydantic_settings-0.1.0a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 043b9c57db5d030765e914fd9eec1d80266359c88f37975d374dfd0bf4335998 |
|
MD5 | c6f34ed975b43fb111da1594237620ef |
|
BLAKE2b-256 | 24e361c2076f0868c6e46e48e3cc54127b207a2c18fcaaddacea5b017d17e3dd |