Skip to main content

A Python library to save your settings in a TOML file.

Project description

Simple TOML Settings

PyPI version Tests codecov Codacy Badge CodeQL

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 Settings

class MySettings(Settings):
    """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 : Run pre-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


Download files

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

Source Distribution

simple_toml_settings-0.2.0.tar.gz (6.6 kB view hashes)

Uploaded Source

Built Distribution

simple_toml_settings-0.2.0-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page