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.2.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.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tomly-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 887538a135c3db818be86759ad6c8d3e725c5d15f5d6e49156c73f6d8177ca08
MD5 4b4ccecc2b565d4825d215a658cfcae7
BLAKE2b-256 dcc3fc6ba08b80f2e4eb488c7c94bdb7ef3bafc149c12f5eda171557a00ad5a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for tomly-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: tomly-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.9 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b0d8d9a5035537259707ce870fada81bf5765d77ebe30eaf60f3c5c19822e84e
MD5 00853573e012e364ae4d0450b090bd6f
BLAKE2b-256 343b3ccff8718b264e921e4df53199ed86591f253d6d14283ecf826224922b72

See more details on using hashes here.

Provenance

The following attestation bundles were made for tomly-0.1.2-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