Skip to main content

A tiny library that simplifies class initialization from TOML files

Project description

TOMLini

A minimal, unintrusive library that allows you to add the ability to initialize an object from a TOML file without having to go through the dictionary dance.

Example

All you need to do is create your class with the @toml_init decorator:

# myclass.py

@toml_init
class MyClass:
    def __init__(v1, v2):
        self.v1 = v1
        self.v2 = v2

Define your TOML file (make sure the TOML key names match the __init__ parameter names!):

# file.toml

v1 = "aaa"
v2 = 1

And you're off to the races!

from myclass import MyClass

my_class = MyClass.load_from_toml("/path/to/file.toml")

print(my_class.v1, my_class.v2)

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

tomlini-1.0.0.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distribution

tomlini-1.0.0-py3-none-any.whl (3.6 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