Skip to main content

A holder for TOML data.

Project description

Overview

A dict-like 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"])

# Example 2: Access nested values using multiple indices
print(h["database", "ports", 2])

# Example 3: Update a value
h["database", "connection_max"] = 10000
print(h["database", "connection_max"])

# Example 4: Add a new section and key-value pair
h["new_section", "new_key"] = "New Value"
print(h["new_section", "new_key"])

# 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.

Credits

Thank you for using tomlhold!

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

tomlhold-1.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

tomlhold-1.0.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file tomlhold-1.0.0.tar.gz.

File metadata

  • Download URL: tomlhold-1.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for tomlhold-1.0.0.tar.gz
Algorithm Hash digest
SHA256 464d5721a11328ddbf17a2505bf9717e0e37aa2f6d4fef3f086ceaf9c969e80a
MD5 33e0c33617ecb898ab2582d746fa0fda
BLAKE2b-256 bb8e091263247ac43d1e4c596c8b715424edbffbcd82ced168af6ad3016bacf1

See more details on using hashes here.

File details

Details for the file tomlhold-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tomlhold-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for tomlhold-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 62a04715be65cd7ad9cb0d11e8e4937f4e765732f436f8897ed204d63c6bdc04
MD5 e317c8bdad5d8ecf23c99f22a0d6a21c
BLAKE2b-256 bfa138f8f6d6e4ca41a53937a9e6856f693dc61f6e0bd284def56964f6ea0f6e

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