A Python library to save your settings in a TOML file.
Project description
Simple TOML Settings
A Python library to save your settings in a TOML file.
Development software
Note that this library is still in the early stages of development and may contain bugs and/or change in the future. Please report any bugs you find on the issue tracker and feel free to make suggestions for improvements.
Installation
You should install this package into a virtual environment. You can use Poetry to do this:
$ poetry add simple-toml-settings
If you don't want to use Poetry, you can use pip:
$ 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.
For full documentation, see the documentation site.
Usage is simple:
Setup
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
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:
[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:
settings = MySettings("test_app")
settings.favourite_colour = "red"
settings.save()
Note that the current library access methods are not set in stone and may change in the future. We will try to keep the changes to a minimum and will provide a migration path (and backwards compatibility) if we do change them.
Development setup
Install the dependencies using Poetry:
$ poetry install
Then, activate the virtual environment:
$ poetry shell
Now, you can start to develop the app.
Task Runner
The task-runner Poe the Poet is installed
as a development dependency which allows us to run simple tasks (similar to npm
scripts
).
These are run (from within the virtual environment) using the poe
command and
then the script name, for example:
$ poe pre
You can define your own, but there are 7 specific ones provided with the script.
-
pre
: Runpre-commit run --all-files
-
pylint
: Run Pylint on all Python files in the project. -
mypy
= Run MyPy type-checker on all Python files in the project. -
flake8
= Run Flake8 linter on all Python files in the project. -
black
= Run Black code formatter on all Python files in the project. -
try
= Run Tryceratops linter on all Python files in the project. -
lint
= Runs pylint, mypy, flake8 and black in sequence
These are defined in the pyproject.toml
file in the [tool.poe.tasks]
section. Take a look at this file if you want to add or remove tasks.
Linting
This project includes flake8 (with several plugins) for linting and Black for formatting. Mypy is installed for type checking. isort,Pylint and tyrceratops are also installed as standard.
Pre-commit
There is a pre-commit configuration provided to run some checks on the code before it is committed. This is a great tool to help keep your code clean.
To install pre-commit, run the following command from inside your venv:
$ pre-commit install
pre-commit installed at .git/hooks/pre-commit
License
This project is released under the terms of the MIT license.
Credits
The original Python boilerplate for this package was created using Pymaker by Grant Ramsay (seapagan)
Project details
Release history Release notifications | RSS feed
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
Hashes for simple_toml_settings-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96949865acba1296b5dee3014077c1c654cbf4b694b9eb65fae8e07b4e95d800 |
|
MD5 | db2869eee69306c4eb5e2c69146e3afe |
|
BLAKE2b-256 | af2ec5415f41c9bd79dec0daf17c6eb05416952b97d1c8a57c0f83c9c87604b1 |
Hashes for simple_toml_settings-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3bf63ea68dec40b570c48274fa61d175f4aa799fbc63616266b02ab6ff1e9551 |
|
MD5 | 1274ede8e479a3fb7cc6a201457c4974 |
|
BLAKE2b-256 | 96f42380288e9a95dfc22ae2e1c547423805b80d4ed331c299c4311f1e4745c6 |