glom

25.12.0 · active · verified Mon Apr 06

glom is a declarative object transformer and formatter for Python, designed to simplify working with nested data structures. It provides path-based access, powerful data transformation using Pythonic specifications, meaningful error messages, and built-in debugging features. The library follows a CalVer versioning scheme (YY.MM.MICRO) and is actively maintained, with version 25.12.0 being a recent release that includes maintenance updates and test fixes for newer Python versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic deep access to nested data, transformation into a new dictionary structure, and using the `T` specifier for iterating and extracting specific fields from a list of dictionaries.

from glom import glom, T

data = {
    'user': {
        'profile': {
            'name': 'Alice',
            'email': 'alice@example.com'
        },
        'preferences': {
            'theme': 'dark'
        }
    },
    'messages': [
        {'id': 1, 'text': 'Hello'},
        {'id': 2, 'text': 'World'}
    ]
}

# Extract a deeply nested value
user_name = glom(data, 'user.profile.name')
print(f"User Name: {user_name}")

# Transform data to a new structure
user_summary_spec = {
    'name': 'user.profile.name',
    'contact_email': 'user.profile.email',
    'first_message': ('messages.0.text', str.upper)
}

user_summary = glom(data, user_summary_spec)
print(f"User Summary: {user_summary}")

# Using T for more complex access or method calls
message_ids = glom(data, ('messages', [T['id']]))
print(f"Message IDs: {message_ids}")

view raw JSON →