https://github.com/seapagan/simple-toml-settings
A Python library to save your settings in a TOML file.
https://github.com/seapagan/simple-toml-settings
python python-configuration settings toml toml-config
Last synced: 9 days ago
JSON representation
A Python library to save your settings in a TOML file.
- Host: GitHub
- URL: https://github.com/seapagan/simple-toml-settings
- Owner: seapagan
- License: mit
- Created: 2023-10-06T17:40:38.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-21T17:15:46.000Z (over 1 year ago)
- Last Synced: 2024-10-21T19:25:12.441Z (over 1 year ago)
- Topics: python, python-configuration, settings, toml, toml-config
- Language: Python
- Homepage: http://toml-settings.grantramsay.dev/
- Size: 2.05 MB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Simple TOML Settings
[](https://badge.fury.io/py/simple-toml-settings)
[](https://github.com/seapagan/simple-toml-settings/actions/workflows/testing.yml)
[](https://app.codacy.com/gh/seapagan/simple-toml-settings/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage)
[](https://app.codacy.com/gh/seapagan/simple-toml-settings/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[](https://github.com/seapagan/simple-toml-settings/actions/workflows/codeql.yml)
A Python library to save your settings in a TOML file.
- [Development Status](#development-status)
- [Installation](#installation)
- [Usage](#usage)
- [Setup](#setup)
- [Using the settings](#using-the-settings)
- [Development setup](#development-setup)
- [License](#license)
- [Credits](#credits)
## Development Status
Note that there is still additional functionality planned to be added to this
package, but the methodology is to keep the package simple to use and
understand. Any additional functionality will be added in a way that is backward
compatible and optional.
The package is considered stable and is being used in production in several
non-trivial applications.
Please report any bugs you find on the
[issue tracker](https://github.com/seapagan/simple-toml-settings/issues) and
feel free to make suggestions for improvements.
## Installation
You should install this package into a virtual environment. You can use
[uv](https://docs.astral.sh/uv/) (recommended), or
[Poetry](https://python-poetry.org/) to do this:
```console
$ uv add simple-toml-settings
```
or
```console
$ poetry add simple-toml-settings
```
If you don't want to use Poetry, you can use pip from inside your virtual
environment:
```console
$ pip install simple-toml-settings
```
## Usage
This is a library to save your settings in a TOML file. It is designed to be
simple to use and to be able to save and load settings from a TOML file with a
minimal of configuration.
The below is a minimal example, for full documentation and information on
available options, see the [documentation
site](https://seapagan.github.io/simple-toml-settings/). There are several flags
you can set to change the location of the settings file, the name of the file,
allowing to run without a settings file, and more.
Usage is simple:
### Setup
```python
from simple_toml_settings import TOMLSettings
class MySettings(TOMLSettings):
"""My settings class."""
# Define the settings you want to save
name: str = "My Name"
age: int = 42
favourite_colour: str = "blue"
favourite_number: int = 42
favourite_foods: list = ["pizza", "chocolate", "ice cream"]
settings = MySettings("test_app")
```
The above will automatically create a TOML file in the user's **home** directory
called `config.toml`, in the subdirectory `.test_app/`, and save the settings to
it. If the file already exists, the settings will be loaded from it.
The file contents for the above example would be:
```toml
[test_app]
age = 42
favourite_colour = "blue"
favourite_number = 42
name = "My Name"
schema_version = "none"
favourite_foods = ["pizza", "chocolate", "ice cream"]
```
### Using the settings
Once you have created your settings class, you can use it like any other class:
```python
settings = MySettings("test_app")
settings.favourite_colour = "red"
settings.save()
```
## Development setup
See the [Contributing Guidelines](CONTRIBUTING.md) for details of how to
contribute to this project and set it up for development.
## License
This project is released under the terms of the MIT license.
## Credits
The original Python boilerplate for this package was created using
[Pymaker](https://github.com/seapagan/py-maker) by [Grant
Ramsay (seapagan)](https://github.com/seapagan) (Me!! 😄).