A holder for TOML data.
Project description
Overview
A holder for TOML data.
Installation
To install tomlhold, you can use pip. Open your terminal and run:
pip install tomlhold
Example
Here’s a simple example.
import tomlhold
# Example 1: Create Holder from a TOML string
toml_data = """
[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true
"""
h = tomlhold.Holder(toml_data)
# Access a single value
print(h["database", "server"]) # Output: "192.168.1.1"
# Example 2: Access nested values using multiple indices
print(h["database", "ports", 2]) # Output: 8002
# Example 3: Update a value
h["database", "connection_max"] = 10000
print(h["database", "connection_max"]) # Output: 10000
# Example 4: Add a new section and key-value pair
h["new_section"] = dict(new_key = "New Value")
print(h["new_section", "new_key"]) # Output: "New Value"
# Example 5: TOML compatibility enforcement (invalid TOML raises an error)
try:
h["new_section", "invalid_key"] = {"invalid": object()}
except Exception as e:
print(f"Error: {e}") # Ensures only TOML-compatible data is allowed
# Example 6: Create Holder from a dictionary and convert it to TOML format
data_dict = {
"title": "Example",
"owner": {
"name": "John Doe",
"dob": "1979-05-27T07:32:00Z"
}
}
h = tomlhold.Holder.fromdict(data_dict)
print(h)
# Example 7: Iterate through Holder object like a regular dictionary
for section, values in h.items():
print(section, values)
# Output:
# 192.168.1.1
# 8002
# 10000
# New Value
# Error: type <class 'object'> is not allowed
# title = "Example"
#
# [owner]
# name = "John Doe"
# dob = "1979-05-27T07:32:00Z"
#
# title Example
# owner {'name': 'John Doe', 'dob': '1979-05-27T07:32:00Z'}
License
This project is licensed under the MIT License.
Links
Credits
Author: Johannes
Thank you for using tomlhold!
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
tomlhold-0.1.7.tar.gz
(4.1 kB
view details)
Built Distribution
File details
Details for the file tomlhold-0.1.7.tar.gz
.
File metadata
- Download URL: tomlhold-0.1.7.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce05f417a284b6260062a75ca4b61b90f97cb797100ecdbbc465b268110732f6 |
|
MD5 | e70c47a1010109809f8c20bf34f68359 |
|
BLAKE2b-256 | 2810baa25eedcdfae30ae87c078d5537b7924a35c3d74e138d6df2714e1ee82d |
File details
Details for the file tomlhold-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: tomlhold-0.1.7-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b6b66efb197b4f043952fcbef55f145a6f2c9df01c1f491f630bf22394c4366 |
|
MD5 | a63ae09a0abc8713dfd5e86d15445539 |
|
BLAKE2b-256 | 054b347f4b9d0485daec7a4d580629fa7b2d05f5f731fd06ad128d2034c8d864 |