|
1 | 1 | # attmap |
2 | 2 |
|
3 | | -[](https://travis-ci.org/pepkit/attmap) |
4 | | -[](https://coveralls.io/github/pepkit/attmap?branch=master) |
| 3 | +[](https://github.com/pepkit/attmap/actions/workflows/run-pytest.yml) |
5 | 4 |
|
6 | | -Key-value Mapping supporting nesting and attribute-style access |
| 5 | +Key-value Mapping supporting nesting and attribute-style access. |
7 | 6 |
|
8 | | -Originally motivated by and designed for the [pepkit family projects](https://pepkit.github.io/). |
| 7 | +**Note:** This package is no longer actively developed. Consider using plain dicts or dataclasses for new projects. |
| 8 | + |
| 9 | +Originally designed for the [pepkit family projects](https://pepkit.github.io/). |
| 10 | + |
| 11 | +## Install |
| 12 | + |
| 13 | +``` |
| 14 | +pip install attmap |
| 15 | +``` |
| 16 | + |
| 17 | +## Class hierarchy |
| 18 | + |
| 19 | +- `AttMapLike` (abstract base) |
| 20 | + - `AttMap` — dict-backed mapping with dot notation access |
| 21 | + - `OrdAttMap` — insertion-ordered (extends `OrderedDict`) |
| 22 | + - `PathExAttMap` — expands environment variables in path-like string values |
| 23 | + - `EchoAttMap` — returns the key itself when a value is not set |
| 24 | + |
| 25 | +## Customizing subclasses |
| 26 | + |
| 27 | +### Excluding keys from text representation |
| 28 | + |
| 29 | +Override `_excl_from_repr` in a subclass: |
| 30 | + |
| 31 | +```python |
| 32 | +def _excl_from_repr(self, k, cls): |
| 33 | + protected = ["reserved_metadata", "REZKEY"] |
| 34 | + return k in protected |
| 35 | +``` |
| 36 | + |
| 37 | +### Excluding class name from repr |
| 38 | + |
| 39 | +Override `__repr__` using the `exclude_class_list` argument to `_render`: |
| 40 | + |
| 41 | +```python |
| 42 | +def __repr__(self): |
| 43 | + return self._render( |
| 44 | + self._simplify_keyvalue(self._data_for_repr(), self._new_empty_basic_map), |
| 45 | + exclude_class_list="YacAttMap", |
| 46 | + ) |
| 47 | +``` |
| 48 | + |
| 49 | +### Excluding classes from `to_dict` conversion |
| 50 | + |
| 51 | +Override `_excl_classes_from_todict`: |
| 52 | + |
| 53 | +```python |
| 54 | +def _excl_classes_from_todict(self): |
| 55 | + return (pandas.DataFrame, ClassToExclude) |
| 56 | +``` |
0 commit comments