Skip to main content

A wrapper around rtoml providing tomli-compatible behavior with enhanced convenience methods for intuitive value access.

Project description

tomly

PyPI version License: MIT Python Version

tomly is a lightweight wrapper around rtoml, designed to provide tomli/tomllib compatible behavior while offering enhanced convenience methods for intuitive data access.

Key Features

  • 🎯 Dot Notation: Access and modify nested dictionary keys as object attributes (e.g., config.db.port).
  • 🌍 Environment Interpolation: Automatically expand ${VAR_NAME:default} patterns within strings during loading.
  • 🌳 Nested Path Operations: Safely get, set, or delete deep values using dot-separated strings or iterables.
  • 🔒 Immutability (Freeze): Protect your configuration from accidental runtime changes.
  • 🥞 Flattening: Convert nested structures into a single-level dictionary for environment variables or logging.
  • High Performance: Built on top of rtoml (Rust-powered) for rapid parsing and serialization.

Installation

pip install tomly

Quick Start

1. Basic Loading & Attribute Access

import tomly as toml
from tomly import DataDict

toml_data = """
[server]
host = "127.0.0.1"
port = 8080
"""

# Parse and wrap into DataDict
config = DataDict(toml.loads(toml_data))

# Access via dot notation
print(config.server.host)  # "127.0.0.1"
config.server.port = 9000   # Set values like an object

2. Environment Variable Interpolation

import os
from tomly import DataDict

os.environ["APP_ENV"] = "production"

# DataDict can resolve ${VAR_NAME} or ${VAR_NAME:default}
data = {"env": "${APP_ENV:dev}", "debug": "${DEBUG:false}"}
config = DataDict(data, interpolate_env=True)

print(config.env) # "production"
print(config.debug) # "false" (using default value)

3. Deep Path Manipulation

from tomly import DataDict

config = DataDict()

# Set values at deep paths (auto-creates intermediate dicts)
config.set_nested("app.services.auth.timeout", 30)

# Safe retrieval without KeyErrors
timeout = config.get_nested("app.services.auth.timeout", default=60)

# Delete a nested structure
config.delete_nested("app.services.auth")

4. Read-only Configuration

from tomly import DataDict

config = DataDict({"api": {"version": "v1"}})
config.freeze()

# This will raise a TypeError
config.api.version = "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

tomly-0.1.3.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tomly-0.1.3-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file tomly-0.1.3.tar.gz.

File metadata

  • Download URL: tomly-0.1.3.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tomly-0.1.3.tar.gz
Algorithm Hash digest
SHA256 01845ccf54f3c44c410f7ab4e2e787a749a34b31e887923bdacb588e7dcfe730
MD5 184a643032c5107d294ffcb1c486ff55
BLAKE2b-256 8f1a1980f285b820b307f7c18d3d554fe5f76e4fd6db93883c419846d1206bf0

See more details on using hashes here.

Provenance

The following attestation bundles were made for tomly-0.1.3.tar.gz:

Publisher: python-publish.yml on hom-wang/tomly

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tomly-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: tomly-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tomly-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bb6a4b79be08e4e7e1b75a61ac83e5d7ddc677fe9e6267467357b0a2738115cf
MD5 be89f66bf26eacf85bcaafa32b8933c8
BLAKE2b-256 77f6c583de9b6e6c413c640f29fa98d10f42ae6f9a02fbd190f3ed76de681ddb

See more details on using hashes here.

Provenance

The following attestation bundles were made for tomly-0.1.3-py3-none-any.whl:

Publisher: python-publish.yml on hom-wang/tomly

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page