A tiny library for initializing objects 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.
Install
Available on PyPI
pip install tomlini
Example
All you need to do is create your class with the
@toml_initdecorator:
# myclass.py
@toml_init
class MyClass:
def __init__(v1, v2):
self.v1 = v1
self.v2 = v2
@toml_init
class MyClass2:
def __init__(v3, v4: MyClass):
self.v3 = v3
self.v4 = v4
Define your TOML file (make sure the TOML key names match the
__init__parameter names!):
# file1.toml
v1 = "aaa"
v2 = 1
# file2.toml
v3 = [1, 2, 3]
[v4]
v1 = "aaa"
v2 = 1
And you're off to the races!
from myclass import MyClass, MyClass2
my_class = MyClass.load_from_toml("/path/to/file1.toml")
my_class_2 = MyClass2.load_from_toml("/path/to/file2.toml")
print(my_class.v1, my_class.v2)
# Outputs: 'aaa', 1
print(my_class_2.v4.v1)
# Outputs: 'aaa'
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tomlini-1.0.1.tar.gz.
File metadata
- Download URL: tomlini-1.0.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59cefd43d1c01b892b31b12482b90d5c348c8a007e0ec6a04f1885e866d7b5ec
|
|
| MD5 |
c7d538fc117b29c04affcd61d436233c
|
|
| BLAKE2b-256 |
867c61e721e656479e38ff0c19c9355f34836c4ad0ee43c78b19e6ceb8d8015d
|
File details
Details for the file tomlini-1.0.1-py3-none-any.whl.
File metadata
- Download URL: tomlini-1.0.1-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0rc1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7b507d062c709627a5c84088a4369d2b97faac9a1812f14c8b17ef255e6724aa
|
|
| MD5 |
6f4e0ea74529e0d433d4f124dc8b7ced
|
|
| BLAKE2b-256 |
2184ca7ae2d93cbc99da4b251ef3a08942c811b454571f7b6adce9b6ba9a352d
|