An open API service indexing awesome lists of open source software.

https://github.com/croqaz/prop

Python library for getting a property from a nested object using a dot path
https://github.com/croqaz/prop

library python

Last synced: 12 months ago
JSON representation

Python library for getting a property from a nested object using a dot path

Awesome Lists containing this project

README

          

# prop · py

[![Pypi Version][pypi-image]][pypi-url]
[![Build Status][build-image]][build-url]
[![Code coverage][cover-image]][cover-url]
[![Python ver][python-image]][python-url]

A Python 🐍 library for getting a property from a nested object using a dot path.

## Usage

```py
import prop

data = {
'k1': 'v1',
'nested': {'x': 'y', 'int': 0, 'null': None},
'list': [[None, True, 9]]
}

prop.get(data, 'k1')
# v1

prop.get(data, 'nested.x')
# x

prop.get(data, 'list.0.1')
# True

prop.get(data, 'list.0.-1')
# 9
```

Limitations: For navigating dicts, only string keys are supported.

## Installation

```sh
$ pip install prop
```

## Similar libraries

* https://github.com/chrisinajar/py-dot-prop - (Python) Get a property from a dict or list
* https://github.com/sindresorhus/dot-prop - (Node.js) Get, set, or delete a property from a nested object using a dot path
* https://github.com/jonschlinkert/get-value - (Node.js) Use property paths (`a.b.c`) to get a nested value from an object

## License

[MIT](LICENSE) © Cristi Constantin.

[pypi-image]: https://img.shields.io/pypi/v/prop.svg
[pypi-url]: https://pypi.org/project/prop/
[build-image]: https://github.com/croqaz/prop/workflows/Python/badge.svg
[build-url]: https://github.com/croqaz/prop/actions
[cover-image]: https://codecov.io/gh/croqaz/prop/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/croqaz/prop
[python-image]: https://img.shields.io/badge/Python-3.6-blue.svg
[python-url]: https://python.org