Query JSON in memory as though it were a Mongo database.
Project description
j q u e
Query JSON in memory as though it were a Mongo database
Installation
pip3 install jque
Usage
import jque
jque
accepts a variety of inputs to the constructor.
Pass a list of dicts:
data = jque.jque([
{ "name": "john" },
{ "name": "paul" },
{ "name": "george" },
{ "name": "ringo" }
])
Pass a JSON filename:
DATAFILE = "~/my/big/data.json"
data = jque.jque(DATAFILE)
Now you can query this dataset using Mongo-like syntax:
>>> data.query({ "name": {"$neq": "paul"} })
[
{ "name": "john" },
{ "name": "george" },
{ "name": "ringo" }
]
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. |
Another example!
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 }
})
Which returns:
[{
"_id": "DE2",
"name": "Penny Lane",
"age": 19,
"current_planet": "earth"
}]
Use Python lambdas as a filter:
>>> libraries = jque.jque([
... {"name": "jque", "language": "Python"},
... {"name": "react", "language": "node"}
... ])
>>> list(libraries.query({
... 'language': lambda x: x[:2] == "Py"
... }))
[{"name": "jque", "language": "Python"}]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jque-0.1.3.tar.gz
(4.6 kB
view details)
Built Distribution
File details
Details for the file jque-0.1.3.tar.gz
.
File metadata
- Download URL: jque-0.1.3.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b228a4fd2d3a983418e372a2c20ef369b3140c7206ba892f94c7c5dcea38349 |
|
MD5 | b67505a9d3811807cb0b68b2c90d409e |
|
BLAKE2b-256 | 3dc74d37639c2b34efdd077dc1f9f2886d370a1bfb51888b7955ce61e7e27852 |
File details
Details for the file jque-0.1.3-py2.py3-none-any.whl
.
File metadata
- Download URL: jque-0.1.3-py2.py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0497c51c9a0174ee742493301dc604ce2147cb7c9f705bcbaefc0dd6ca2b0ec0 |
|
MD5 | 5585db32963597f29bdc6a7a5358bc41 |
|
BLAKE2b-256 | 4eaf9d7c1e438a3e3cee3b2fc5c5e54e02ecc24f3acf77889030aee303ef5ede |