=========================
Provides the ability to query a data source made up of any combination
of lists and dicts.
To use from within Python:
```python
>>> from dq import query
>>> dq.query('[0].name', [{'name': 'michael'}, {'name': 'jane'}])
'michael'
>>> dq.query('..name', [{'name': 'michael'}, {'name': 'jane'}])
['michael', 'jane']
```
Installation
------------
To install dq:
```
pip install dq
```
dq does not depend on any non-standard libraries
Query Language
--------------
The query language is a much simplified version of [json path][1]. The subset
is selected to allow for simple structural querying of data - no filters or
expressions. This keeps the parser nice and simple, and since its a Python
library you have the full power of Python to perform complex filters.
The query language supports the following path syntax:
```
.key - Returns the given key from the dict
..key - Returns the given key from any descendant dictionary
[index] - Returns an item from a list at the specified index
[*] - Returns all items in a list
[start:stop:step] - Performs a python slice operation on a list
```
Query Examples
--------------
These syntax items can be combined to build complex queries.
```python
>>> from dq import query
>>> d = {}
>>> d['one'] = 1
>>> d['two'] = [1,2,3,4,5,6,7,8,9,10]
>>> d['three'] = [{'name': 'john'}, {'name': 'mary'}, {'one': 'guy'}]
>>> query('.one', d)
1
>>> query('.two', d)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> query('.two[1]', d)
2
>>> query('.two[*]', d)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> query('.two[2:-2]', d)
[3, 4, 5, 6, 7, 8]
>>> query('.two[1:6:2]', d)
[2, 4, 6]
>>> query('.three[1].name', d)
'mary'
>>> query('.three[*].name', d)
['john', 'mary']
>>> query('..name', d)
['john', 'mary']
>>> query('..one', d)
[1, 'guy']
```
Compiled Queries
----------------
When using the same query string repeatedly a CompiledQuery can be constructed
to prevent parsing the query string multiple times:
```python
>>> from dq import compiled
>>> query = compiled('[1]')
>>> query([1,2,3,4])
2
>>> query([5,6,7,8])
6
```
Thanks
-------
This library is based on the ideas and code from [python-jsonpath-rw][2].
Copyright
---------
Copyright (c) 2013 Michael Lamb. See LICENSE.txt for details.
[1]: http://goessner.net/articles/JsonPath/ "Json Path"
[2]: https://github.com/kennknowles/python-jsonpath-rw "python-jsonpath-rw"
Metadata
Release files for dq 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dq-0.1.2.tar.gz | 4.7 kB | Without provenance | Details for dq-0.1.2.tar.gz |
Release files / dq-0.1.2.tar.gz
| Download URL | dq-0.1.2.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a375f1385af15257660ef23641e9de706dfd227d5b713af1497cb2fe0c64888
|
|
BLAKE2b-256 checksum How to use checksums |
c3b8caec444f580ef5d0eaf4b78fcbb73d69b33e145ca91dc1eb3520fead9953
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for dq 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.