Typed Settings
PoC for library for managing (typed) settings – for server processes as well as commandline programms.
Requirements
-
Default settings are defined by app and can be overridden by config files, environment variables and click options.
-
You define settings as attrs class with types, converters and validators.
-
Attributes are basic data types (bool, int, float, str), lists of basic types, or nested settings classes.
-
Settings can be loaded from multiple config files.
-
Config files are allowed to contain settings for multiple apps (like
pyproject.toml) -
Paths to config files have to be explicitly named. Most defaults are not useful in many cases and have to be changed anyways.
-
Additional paths for config files can be specified via an environment variable. As in
PATH, multiple paths are separated by a:. The last file in the list has the highest priority. -
Environment variables with a defined prefix override settings from config files. This can optionally be disabled.
-
Click options for some or all settings can be generated. They are passed to the cli function as a single object (instead of individually).
-
Settings must be explicitly loaded, either via
typed_settings.load_settings()or viatyped_settings.click_options(). -
Both functions allow you to customize config file paths, prefixes et cetera.
Example
import click
import typed_settings as ts
@ts.settings
class Host:
name: str
port: int = ts.option(converter=int)
@ts.settings(kw_only=True)
class Settings:
url: str
default: int = 3
host: Host = ts.option(converter=lambda d: Host(**d))
settings = ts.load_settings(
settings_cls=Settings, appname='example', config_files=['settings.toml']
)
print(settings)
@click.command()
@ts.click_options(Settings, 'example', ['settings.toml'])
def main(settings):
print(settings)
if __name__ == '__main__':
main()
Metadata
Release files for typed-settings 0.5
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 |
|---|---|---|---|---|
| typed-settings-0.5.tar.gz | 16.8 kB | Without provenance | Details for typed-settings-0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| typed_settings-0.5-py3-none-any.whl | Python 3 | none | any | Details for typed_settings-0.5-py3-none-any.whl |
Total release size: 27.2 kB
Release files / typed-settings-0.5.tar.gz
| Download URL | typed-settings-0.5.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
07c1273eab46ec4df9ed479eaecbbed8f6b561e97f15df97104a4b8fb13fe6f8
|
|
BLAKE2b-256 checksum How to use checksums |
16368c1733967888933148a7df6a62e825894d4350388e64da44c19a1fc13d14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.6
|
Release files / typed_settings-0.5-py3-none-any.whl
| Download URL | typed_settings-0.5-py3-none-any.whl |
|---|---|
| Size | 10.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b9396d4a495ed5d65b54768b815f714324d9d54700420b1b445f235edd2afe1e
|
|
BLAKE2b-256 checksum How to use checksums |
269a5c715a26cf4250e2e587abb2591f3e079b84c54402d8154afaf268079dcd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.8.6
|
Security for typed-settings 0.5
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.