Skip to main content

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__(directory = '.\PATH_TO_CONFIGS\')

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

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

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

        # all instances share the same files
        if mtoml.is_loaded(config = 'dogs') is False:
            # load a toml config named "dogs.toml"
            if mtoml.load(config = '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(config = 'dogs', field = 'breeds')
        breeds.append(breed)

        # if the field is part of a group, simply specify the group
        breed_info = mtoml.get(config = 'dogs', group = 'breeds', field = breed)

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

        # any attempt to call get(config = 'dogs', field = 'breeds')
        # will return our updated list but those updates
        # haven't been saved yet, we need explicitly save
        mtoml.save(config = '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__()

Metadata

Release files for mtoml 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mtoml 1.2.0
File Size Uploaded Provenance Actions
mtoml-1.2.0.tar.gz 10.7 kB Without provenance Details for mtoml-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mtoml 1.2.0
File Interpreter ABI Platform Actions
mtoml-1.2.0-py2.py3-none-any.whl Python 3, Python 2 none any Details for mtoml-1.2.0-py2.py3-none-any.whl

Total release size: 21.5 kB

Release files / mtoml-1.2.0.tar.gz

Download URL mtoml-1.2.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f301096ec75cc4dcf50e694587f27a9bf12cb6aeddfc57247a67441ba69e0ef3
BLAKE2b-256 checksum
How to use checksums
62199cc19a415f0801a6bc19ea6ad69d150107f248de2d2a4830ca89f838db40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release files / mtoml-1.2.0-py2.py3-none-any.whl

Download URL mtoml-1.2.0-py2.py3-none-any.whl
Size 10.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e4ab397769f32f60156bd7232e8601367294ba5ef33b20d9a84468bd35325d79
BLAKE2b-256 checksum
How to use checksums
e52f0e4c6b5866e12926d9498904f597347668ff572f44cceda37295e14d3bc6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Security for mtoml 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page