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.
pip install glomVerified import paths — ran on the pinned version, not inferred.
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.
If you experience issues, you can temporarily revert the behavior by setting `glom.core.PATH_STAR = False`. The recommended fix is to explicitly use the `Path` specifier, e.g., `Path('a', '*')` instead of `'a.*'`.Replace `Call` with `Invoke` in your specs. For calling methods on the target, consider using the `T` object instead.
Rely only on documented `glom` functions, classes, and specifiers. If you find undocumented functionality that seems useful, consider filing an issue or pull request.
Use the `Coalesce` specifier or the `default` and `skip_exc` kwargs in the `glom()` function to gracefully handle missing data or potential errors. `Coalesce` catches exceptions internally and proceeds to the next spec.
Ensure your project runs on Python 3.7 or newer to use glom versions 23.3.0 and above.
Install the glom library using pip: `pip install glom`
Check your target data to ensure the path in your glom spec matches the actual structure. You can use `glom.Coalesce` or the `default` argument in `glom()` to provide fallback values or handle missing paths gracefully. For example: `glom(target, 'a.b.c', default=None)` or `glom(target, Coalesce('a.b.c', 'a.b.fallback_c', default='default_value'))`.Ensure at least one subspec in `Coalesce` is expected to match your data, or provide a `default` argument to `Coalesce` to define a value to return if all subspecs fail. Example: `glom(target, Coalesce('key1', 'key2', default='fallback_value'))`.Verify that the path and index you are trying to assign to are valid and within the bounds of mutable collections. If you need to create missing intermediate data structures during assignment, use the `missing` argument in `assign()` or `Assign`. Example: `assign(target, 'a.b.c', value, missing=dict)` will create dictionaries for 'a' and 'b' if they don't exist.