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.4.tar.gz (25.3 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.4-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tomly-0.1.4.tar.gz
  • Upload date:
  • Size: 25.3 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.4.tar.gz
Algorithm Hash digest
SHA256 ac6b58cb61c826dda295f64c253d3f1b2b79aefbe8fc79d462b8304f017c9dcc
MD5 688eb6cc23154711ac46caaabcd88db8
BLAKE2b-256 aa2f9528468635cd46f794e86e292a29ceca218303feba82b524187ff75948cb

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: tomly-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3a94227961360ede41ed65432b176c12157e81eb32658b056a541d4bf2162b6b
MD5 821787c6d63c26ddfd5ef6e775b72df0
BLAKE2b-256 b2a29e85636f6d98e18be4c1e3f2ee1d7854859e85511a1f8509444a538d47a1

See more details on using hashes here.

Provenance

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