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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

s3ttings-0.0.7.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

s3ttings-0.0.7-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

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

Hashes for s3ttings-0.0.7.tar.gz
Algorithm Hash digest
SHA256 e98cfda2559152498a9446134686fa9b274fa62d7ee43d72b94fd9a5e2c17970
MD5 68ab4214cce8fef332ef175605120cff
BLAKE2b-256 2d4975ed9be4979ff9d10e84c82c967b1712561e79d7668e29ed1ae6e983d80e

See more details on using hashes here.

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

Hashes for s3ttings-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 100e5be9dc3f11d661ba60d6ba9b6dcb54f15bdd64263e6722546e5b32f22d21
MD5 e9d19821e02248699078fe1b54690d98
BLAKE2b-256 17c5086f761379f7a78b631216997a3610c0495159ecacf7572b64da3972f894

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page