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
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 s3ttings-0.0.7.tar.gz.
File metadata
- Download URL: s3ttings-0.0.7.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e98cfda2559152498a9446134686fa9b274fa62d7ee43d72b94fd9a5e2c17970
|
|
| MD5 |
68ab4214cce8fef332ef175605120cff
|
|
| BLAKE2b-256 |
2d4975ed9be4979ff9d10e84c82c967b1712561e79d7668e29ed1ae6e983d80e
|
File details
Details for the file s3ttings-0.0.7-py3-none-any.whl.
File metadata
- Download URL: s3ttings-0.0.7-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
100e5be9dc3f11d661ba60d6ba9b6dcb54f15bdd64263e6722546e5b32f22d21
|
|
| MD5 |
e9d19821e02248699078fe1b54690d98
|
|
| BLAKE2b-256 |
17c5086f761379f7a78b631216997a3610c0495159ecacf7572b64da3972f894
|