Metadata-Version: 2.1
Name: datadict
Version: 1.0.0
Summary: Add dictionary-like capabilities to dataclasses
Keywords: dataclass,dict,dictionary,item,access
Author-email: Geir Arne Hjelle <geirarne@gmail.com>
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Software Development :: Code Generators
Requires-Dist: typing_extensions
Requires-Dist: black ; extra == "dev"
Requires-Dist: bumpversion ; extra == "dev"
Requires-Dist: flake8 ; extra == "dev"
Requires-Dist: flit ; extra == "dev"
Requires-Dist: interrogate ; extra == "dev"
Requires-Dist: isort ; extra == "dev"
Requires-Dist: mypy ; extra == "dev"
Requires-Dist: pre-commit ; extra == "dev"
Requires-Dist: pyright ; extra == "dev"
Requires-Dist: mkdocs ; extra == "doc"
Requires-Dist: black ; extra == "test"
Requires-Dist: flake8 ; extra == "test"
Requires-Dist: interrogate ; extra == "test"
Requires-Dist: isort ; extra == "test"
Requires-Dist: mypy ; extra == "test"
Requires-Dist: pyright ; extra == "test"
Requires-Dist: pytest ; extra == "test"
Requires-Dist: pytest-cov ; extra == "test"
Requires-Dist: tox ; extra == "test"
Project-URL: Homepage, https://github.com/gahjelle/datadict
Provides-Extra: dev
Provides-Extra: doc
Provides-Extra: test

# DataDict

_Treat dataclasses like dictionaries_

[![v1.0.0](https://img.shields.io/pypi/v/datadict.svg)](https://pypi.org/project/datadict/)
[![Python versions](https://img.shields.io/pypi/pyversions/datadict.svg)](https://pypi.org/project/datadict/)
[![Tests](https://img.shields.io/github/workflow/status/gahjelle/datadict/tests?label=tests)](https://github.com/realpython/codetiming/actions)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Interrogate](https://raw.githubusercontent.com/gahjelle/datadict/master/interrogate_badge.svg)](https://interrogate.readthedocs.io/)


## Installing DataDict

DataDict is available at [PyPI](https://pypi.org/project/datadict/). You can install it using Pip:

    $ python -m pip install datadict


## Using DataDict

You can use a DataDict `dataclass` as a drop-in replacement for `dataclasses.dataclass` in the standard library:

```python
from datadict import dataclass

@dataclass(order=True)
class Point:
    x: int
    y: int
```

For instances of the new data class, you can access attributes using square brackets, similar to dictionary access:

```python
>>> point = Point(1, 2)
>>> point
Point(x=1, y=2)

>>> point.x
1
>>> point["x"]
1

>>> point["y"] = 3
>>> point
Point(x=1, y=3)
```

You can also convert the dataclass instance to a proper dictionary:

```python
>>> point.asdict()
{'x': 1, 'y': 3}
```


## Installing From Source

You can always download the [latest version of DataDict from GitHub](https://github.com/gahjelle/datadict). DataDict uses [Flit](https://flit.pypa.io/) as a build tool.

To install DataDict from the downloaded source, run Flit through `pip`:

    $ python -m pip install .

If you want to change and play with the DataDict source code, you should install it in editable mode:

    $ python -m pip install -w .[dev,test]

