Skip to main content

A basic library to manage collections of knobs and toggles

Installation

pip install s3ttings

Usage

Setting

1  import asyncio
2  from settings import Setting
3 
4  timeout = Setting(f"{__name__}.io.timeout", default=5)
5 
6  async def main():
7      with asyncio.timeout(timeout.value):
8          await long_running_task()

Settings can be tweaked:

 1  from settings import Setting
 2 
 3  timeout = Setting(f"{__name__}.io.timeout", default=5)
 4 
 5  if __name__ == "__main__":
 6      assert timeout.value == 5
 7 
 8      timeout.value = 3
 9      assert timeout.value = 3
10 
11      with timeout(10):
12          assert timeout.value == 10
13      assert timeout.value == 3
14 
15      del timeout.value
16      assert timeout.value == 5
17 
18      timeout.default = 6
19      assert timeout.value == 6
20 
21      del timeout.default
22      timeout.value  # raises `settings.NoDefaultValueError(timeout)`

They can transparently use other settings as their default:

1  from settings import Setting
2 
3  timeout = Setting(f"{__name__}.io.timeout", default=5)
4  load_timeout = Setting(f"{__name__}.io.load.timeout", default=timeout)
5  dump_timeout = Setting(f"{__name__}.io.dump.timeout", default=timeout)
6 
7  if __name__ == "__main__":
8      assert load_timeout.value == dump_timeout.value == timeout.value == 5

Finally, Setting implements the multiton pattern:

1  from settings import Setting
2 
3  timeout = Setting(f"{__name__}.io.timeout", default=5)
4 
5  if __name__ == "__main__":
6      assert Setting(f"{__name__}.io.timeout") is timeout

SettingTree

Collections of settings can be grouped in setting trees:

 1  from settings import Setting, SettingTree
 2 
 3  options = SettingTree(
 4      Setting(f"{__name__}.io.timeout", default=5),
 5      Setting(
 6          f"{__name__}.io.load.timeout", default=Setting(f"{__name__}.io.timeout")
 7      ),
 8      Setting(
 9          f"{__name__}.io.dump.timeout", default=Setting(f"{__name__}.io.timeout")
10      ),
11      prefix=__name__,
12  )
13 
14  if __name__ == "__main__":
15      assert 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:

1  from settings import SettingTree
2 
3  from .a import options as _options_a
4  from .b import options as _options_b
5 
6  options = SettingTree(*_options_a, *_options_b, prefix=__name__)

EnvSetting

A subclass of Setting, EnvSetting can source default values from environment variables:

 1  import os
 2  from settings import EnvSetting
 3 
 4  timeout = EnvSetting("my.project.io.timeout", default=5, envparse=int)
 5 
 6  if __name__ == "__main__":
 7      assert timeout.value == 5
 8 
 9      os.environ["my.project.io.timeout"] = "10"
10      assert 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)

Source distribution for s3ttings 0.0.7
File Size Uploaded
s3ttings-0.0.7.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for s3ttings 0.0.7
File Interpreter ABI Platform
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}

Release history Release notifications | RSS feed

This release

0.0.7 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page