A basic library to manage collections of knobs and toggles
Installation
pip install s3ttings
Usage
Setting
1import asyncio2from settings import Setting34timeout = Setting(f"{__name__}.io.timeout", default=5)56async def main():7with asyncio.timeout(timeout.value):8await long_running_task()
Settings can be tweaked:
1from settings import Setting23timeout = Setting(f"{__name__}.io.timeout", default=5)45if __name__ == "__main__":6assert timeout.value == 578timeout.value = 39assert timeout.value = 31011with timeout(10):12assert timeout.value == 1013assert timeout.value == 31415del timeout.value16assert timeout.value == 51718timeout.default = 619assert timeout.value == 62021del timeout.default22timeout.value # raises `settings.NoDefaultValueError(timeout)`
They can transparently use other settings as their default:
1from settings import Setting23timeout = Setting(f"{__name__}.io.timeout", default=5)4load_timeout = Setting(f"{__name__}.io.load.timeout", default=timeout)5dump_timeout = Setting(f"{__name__}.io.dump.timeout", default=timeout)67if __name__ == "__main__":8assert load_timeout.value == dump_timeout.value == timeout.value == 5
Finally, Setting implements the multiton pattern:
1from settings import Setting23timeout = Setting(f"{__name__}.io.timeout", default=5)45if __name__ == "__main__":6assert Setting(f"{__name__}.io.timeout") is timeout
SettingTree
Collections of settings can be grouped in setting trees:
1from settings import Setting, SettingTree23options = SettingTree(4Setting(f"{__name__}.io.timeout", default=5),5Setting(6f"{__name__}.io.load.timeout", default=Setting(f"{__name__}.io.timeout")7),8Setting(9f"{__name__}.io.dump.timeout", default=Setting(f"{__name__}.io.timeout")10),11prefix=__name__,12)1314if __name__ == "__main__":15assert options.io.timeout.value == 5
For large projects with many settings, a common practice is to define multiple trees and merge them together in the top-level module:
1from settings import SettingTree23from .a import options as _options_a4from .b import options as _options_b56options = SettingTree(*_options_a, *_options_b, prefix=__name__)
EnvSetting
A subclass of Setting, EnvSetting can source default values from environment variables:
1import os2from settings import EnvSetting34timeout = EnvSetting("my.project.io.timeout", default=5, envparse=int)56if __name__ == "__main__":7assert timeout.value == 589os.environ["my.project.io.timeout"] = "10"10assert timeout.value == 10
Metadata
Release files for s3ttings 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| s3ttings-0.0.7.tar.gz | 5.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| s3ttings-0.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.8 kB
Release files / s3ttings-0.0.7.tar.gz
| Download URL | s3ttings-0.0.7.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e98cfda2559152498a9446134686fa9b274fa62d7ee43d72b94fd9a5e2c17970
|
|
BLAKE2b-256 checksum How to use checksums |
2d4975ed9be4979ff9d10e84c82c967b1712561e79d7668e29ed1ae6e983d80e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / s3ttings-0.0.7-py3-none-any.whl
| Download URL | s3ttings-0.0.7-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
100e5be9dc3f11d661ba60d6ba9b6dcb54f15bdd64263e6722546e5b32f22d21
|
|
BLAKE2b-256 checksum How to use checksums |
17c5086f761379f7a78b631216997a3610c0495159ecacf7572b64da3972f894
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|