This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Python Simple Data Query

Project Description - Python DataQuery
Provides the ability to query a data source made up of any combination
of lists and dicts.

To use from within Python:
>>> from dq import query
>>> dq.query('[0].name', [{'name': 'michael'}, {'name': 'jane'}])

>>> dq.query('', [{'name': 'michael'}, {'name': 'jane'}])
['michael', 'jane']
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.
>>> 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)

>>> query('.two', d)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

>>> query('.two[1]', d)

>>> 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)

>>> query('.three[*].name', d)
['john', 'mary']

>>> query('', d)
['john', 'mary']

>>> query('', 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:
>>> from dq import compiled
>>> query = compiled('[1]')
>>> query([1,2,3,4])
>>> query([5,6,7,8])

This library is based on the ideas and code from [python-jsonpath-rw][2].

Copyright (c) 2013 Michael Lamb. See LICENSE.txt for details.

[1]: "Json Path"
[2]: "python-jsonpath-rw"
Release History

Release History

This version
History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
dq-0.1.2.tar.gz (4.7 kB) Copy SHA256 Checksum SHA256 Source Apr 21, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting