<!--
SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
SPDX-License-Identifier: BSD-2-Clause
-->

# Reduce a complex Python structure to basic types

\[[Home][ringlet-home] | [sourcehut][sourcehut] | [PyPI][pypi] | [ReadTheDocs][readthedocs]\]

## Overview

The `as-dict-rec` Python library mainly provides
the [as_dict_rec()][as_dict_rec.as_dict_rec] function that
takes an arbitrarily complex Python data structure (a dictionary, a dataclass,
a set of lists of complex numbers, etc) and converts it to a form that may be
serialized into an e.g. JSON, TOML, or similar representation.

## Installation

A program that uses the `as-dict-rec` library should specify it in
its list of requirements, e.g. using [PEP508][pep508] syntax:

    as-dict-rec >= 0.1.1, < 0.2

[pep508]: https://peps.python.org/pep-0508/ "PEP 508 – Dependency specification for Python Software Packages"

## Basic usage

Convert a structure to a JSON representation:

``` python
print(json.dumps(as_dict_rec.as_dict_rec(complex_data), indent=2))
```

Skip null values in lists, dictionaries, etc, since TOML cannot represent them:

``` python
print(tomli_w.dumps(as_dict_rec.as_dict_rec(complex_data, skip_null=True), indent=2))
```

## Contact

The `as-dict-rec` library was written by [Peter Pentchev][roam].
It is developed in [a sourcehut repository][sourcehut].
This documentation is hosted at [Ringlet][ringlet-home] with a copy at
[ReadTheDocs][readthedocs].

[roam]: mailto:roam@ringlet.net "Peter Pentchev"
[pypi]: https://pypi.org/project/as-dict-rec/ "The as-dict-rec Python Package Index page"
[readthedocs]: https://as-dict-rec.readthedocs.io/ "The as-dict-rec ReadTheDocs page"
[ringlet-home]: https://devel.ringlet.net/devel/as-dict-rec/ "The Ringlet as-dict-rec homepage"
[sourcehut]: https://git.sr.ht/~ppentchev/as-dict-rec "The as-dict-rec sourcehut repository"
