Skip to main content

Manage multiple TOML configurations from a single module.

Project description

mtoml

Manage multiple TOML configurations from a single thread-safe module.

pip install mtoml

codefactor circleci codecov

from sys import stderr

import mtoml

class pets(mtoml.mtomlc):
    def __init__(self):
        # set the relative path to the config directory
        # if not specified, defaults to the current directory
        # unless a directory was set prior to this class init
        mtoml.mtomlc.__init__('.\PATH_TO_CONFIGS\')

        # mtomlc does not need to be inherited and may be an instance var
        self.conf = mtoml.mtomlc('\PATH_TO_CONFIGS\')

        # mtoml methods may be accessed through any instance
        self.conf.set_dir('\PATH_TO_CONFIGS\')
        self.set_dir('.\PATH_TO_CONFIGS\')

        # or directly through the module itself
        mtoml.set_dir('.\PATH_TO_CONFIGS\')

        # all instances share the same files
        if mtoml.is_loaded('dogs') is False:
            # load a toml config named "dogs.toml"
            if mtoml.load('dogs') is False:
                # if something goes wrong mtoml won't throw exceptions
                # and instead returns either None or False
                print('Unable to load config "dogs"!', file=stderr)

    def __del__(self):
        # not a good idea to put this here in practice
        # but this is "save all changes before exit"
        mtoml.save_all()

        # where as this is would force a full write
        # to save eveything even if nothing changed
        mtoml.save_all(force_overwrite=True)

    def add_dog_breed(self, breed):
        # get the current list of dog breeds that we are
        # assuming is a list in this case
        breeds = mtoml.get('dogs', 'breeds')
        breeds.append(breed)

        # update the config with our new list
        mtoml.set('dogs', 'breeds', breeds)

        # any attempt to call get('dogs', 'breeds')
        # will return our updated list but those updates
        # haven't been saved yet, we need explicitly save
        mtoml.save('dogs')

        # now even if another app wants to access
        # our toml config about dogs it will show
        # the updated list, otherwise our new list
        # would not be saved until the class instance
        # is cleaned up through __del__()

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

mtoml-1.1.0.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

mtoml-1.1.0-py2.py3-none-any.whl (10.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file mtoml-1.1.0.tar.gz.

File metadata

  • Download URL: mtoml-1.1.0.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for mtoml-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7d7c60d77c262832866ab5c2cbc702ceb088e599c38c50a12708e79810d2eed3
MD5 e9c8e69470805141d99256900ea12f9f
BLAKE2b-256 ad200e2ec064a111a5467b08ed124143877c5660b7b612ddbce47b3bc149f7d4

See more details on using hashes here.

File details

Details for the file mtoml-1.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: mtoml-1.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for mtoml-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f0ce9b74d139e4ffd236be166deb3577b3e1311eb0c059e6880079fedd9971bc
MD5 e155af93803f0bf4756882d8d2ba3537
BLAKE2b-256 93181368e835abba7996fc3ca1412ae2daadd7aa503ba5b2eab17e843e4ca768

See more details on using hashes here.

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