Skip to main content

Configuration handling

Project description

tilsit-config

tilsit-config is a lightweight Python utility for loading and managing application configuration stored in TOML format. It provides built-in support for settings modeled as dataclasses, including boolean switches and selectable option lists.

This library is designed to simplify building UIs or CLI tools that allow users to update configuration values safely.


✨ Features

  • Load config values from a TOML file
  • Automatically map TOML data into dataclass-based settings
  • Built-in setting types:
    • SettingBoolean — boolean configuration values
    • SettingOptions — selectable values from predefined choices
  • Track whether settings have changed
  • Save user-modified settings back to the file
  • Fully typed (mypy-friendly)

📦 Installation

pip install tilsit-config

🧩 Usage

Define your settings

from dataclasses import dataclass
from tilsit_config.settings import SettingBoolean, SettingOptions, SettingOption

@dataclass
class AppSettings:
    dark_mode: SettingBoolean
    language: SettingOptions

Example config.toml

[settings]
dark_mode = { label = "Dark Mode", default_value = false, current_value = true }

[settings.language]
label = "Language"
default_value = "en"
current_value = "pl"

[[settings.language.options]]
value = "en"
display_str = "English"

[[settings.language.options]]
value = "pl"
display_str = "Polish"

Loading and Saving Configuration

from tilsit_config import load_config, save_settings

config_path = "config.toml"

config_dict, settings = load_config(config_path, AppSettings)

print(settings.dark_mode)
print(settings.language.current_value)

# Modify a setting in code
settings.dark_mode.current_value = False

# Save back to file
save_settings(config_path, settings)

🔍 Detect changes

if settings.dark_mode.changed:
    print("Dark mode setting was changed.")

🗂 Structure of returned data

Variable Type Description
config_dict dict[str, Any] Raw TOML document
settings Instance of provided dataclass or None Mapped settings

💡 Use cases

  • TUI/GUI applications with persistent user preferences
  • CLI tools with configuration overrides
  • Games storing language/theme
  • Feature toggles in config-driven apps

🤝 Contributing

Contributions, suggestions and issue reports are welcome!


📝 License

MIT License — see LICENSE for details.

Project details


Download files

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

Source Distribution

tilsit_config-1.0.1.tar.gz (318.1 kB view details)

Uploaded Source

Built Distribution

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

tilsit_config-1.0.1-py3-none-any.whl (401.4 kB view details)

Uploaded Python 3

File details

Details for the file tilsit_config-1.0.1.tar.gz.

File metadata

  • Download URL: tilsit_config-1.0.1.tar.gz
  • Upload date:
  • Size: 318.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.2

File hashes

Hashes for tilsit_config-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4d0a449d6f94d5a84282bdf80d85440e755655f655ab65dd2be54a95839315f4
MD5 2710d8d8fe67b378adc91db1ee3005fd
BLAKE2b-256 a9709860d16d88eccef6c2365f868eba9d9192f0b2ab91cb2fca7051d0c51717

See more details on using hashes here.

File details

Details for the file tilsit_config-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for tilsit_config-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 460ec70f4ed3f9758a4f026c29c8e827cfdd4d9493a53515aaed7514f43ba3b8
MD5 8a52c70e25d0107e1bc9eb2e8231508b
BLAKE2b-256 43da2760470e812b239ce1183db07277c7ae446e9ba45122b4e84a6d3f9537e7

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 Pingdom Monitoring Sentry Error logging StatusPage Status page