Metadata-Version: 2.4
Name: jque
Version: 0.1.2
Summary: Query JSON in memory as though it were a Mongo database.
Home-page: https://github.com/j6k4m8/jque
Author: Jordan Matelsky
Author-email: open-source@matelsky.com
License: MIT
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Requires-Python: >=3.6.0
Description-Content-Type: text/markdown
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pylint; extra == "dev"
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: provides-extra
Dynamic: requires-python
Dynamic: summary


<h2 align=center>j q u e</h2>
<p align=center>Query JSON in memory as though it were a Mongo database</p>
<p align=center><a href="https://circleci.com/gh/j6k4m8/jque">CircleCI: <img src="https://circleci.com/gh/j6k4m8/jque.svg?style=svg" /></a></p>

## Installation

```shell
pip3 install jque
```

## Usage

```python
import jque
```

`jque` accepts a variety of inputs to the constructor.

Pass a list of dicts:
```python
data = jque.jque([{ "name": "jque" }])
```

Pass a JSON filename:
```python
DATAFILE = "~/my/big/data.json"
data = jque.jque(DATAFILE)
```

Now you can query this dataset using Mongo-like syntax:
```python
data.query({ "name": {"$neq": "numpy"} })
```

### Arguments to `query`:

| Arg | Description |
|-----|-------------|
| `wrap` (`boolean` : `True`) | Whether to wrap the resultant dataset in a new `jque` object. This allows chaining, like `jque.query(...).query(...)`, if you're the sort of person to do that. Pass `False` to get back a `list` instead. |

### 


```python
data = jque.jque([{
    "_id": "ABC",
    "name": "Arthur Dent",
    "age": 42,
    "current_planet": "earth"
}, {
    "_id": "DE2",
    "name": "Penny Lane",
    "age": 19,
    "current_planet": "earth"
}, {
    "_id": "123",
    "name": "Ford Prefect",
    "age": 240,
    "current_planet": "Brontitall"
}])

teenage_earthlings = data.query({
    "current_planet": {"$eq": "earth"},
    "age": { "$lte": 20, "$gte": 10 }
})
```


Use Python lambdas as a filter:

```python
libraries = jque.jque([{"name": "jque", "language": "Python"}, {"name": "react", "language": "node"}])
list(libraries.query({ 'language': lambda x: x[:2] == "Py" }))
```

