BlobStash DocStore client
Project description
# BlobStash Python DocStore
[](https://travis-ci.org/tsileo/blobstash-python-docstore)
[](https://pypi.python.org/pypi/blobstash-docstore)
[](https://pypi.python.org/pypi/blobstash-docstore)
[](https://blobstash-python-docstore.a4.io/)
[](https://raw.githubusercontent.com/tsileo/blobstash-python-docstore/master/LICENSE)
Client for [BlobStash](https://github.com/tsileo/blobstash) JSON document store.
See the [documentation](https://blobstash-python-docstore.a4.io/) for more details.
## Examples
```python
>>> from blobstash.docstore import DocStoreClient, Path, Q
>>> client = DocStoreClient(api_key='123')
>>> col = client.my_collection
>>> col
<blobstash.docstore.Collection name='my_collection'>
>>> # Insert data
>>> k = col.insert({'key': 10, 'k1': True, 'k2': None, 'l': [1, 2, 'c']})
>>> k
<blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>
>>> # Get a single document
>>> col.get_by_id(k)
{'_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>,
'k1': True,
'k2': None,
'key': 10,
'l': [1, 2, 'c']}
>>> col.get_by_id('14d854f6e9ee37a9cd8c1ffc')
{'_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>,
'k1': True,
'k2': None,
'key': 10,
'l': [1, 2, 'c']}
# Native Python query using Q
>>> for doc in col.query(Q['key'] == 10):
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>}
>>> for doc in col.query(Q['key'] > 10):
... print(doc)
>>> for doc in col.query():
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>}
>>> for doc in col.query(Q['l'].contains(1)):
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>}
>>> for doc in col.query(Q['l'][0] == 1):
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>}
>>> # Raw Lua query
>>> # 1. in shortcut mode
>>> for doc in col.query("doc.k1 == true and doc.key ~= nil"):
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>}
>>> # 2. full Lua script
>>> from blobstash.docstore.query import LuaScript
>>> script = LuaScript("""
... return function(doc)
... if doc.key == 10 then
... return true
... end
... return false
... end
... """)
>>> for doc in col.query(script):
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>}
```
## LICENSE
MIT
[](https://travis-ci.org/tsileo/blobstash-python-docstore)
[](https://pypi.python.org/pypi/blobstash-docstore)
[](https://pypi.python.org/pypi/blobstash-docstore)
[](https://blobstash-python-docstore.a4.io/)
[](https://raw.githubusercontent.com/tsileo/blobstash-python-docstore/master/LICENSE)
Client for [BlobStash](https://github.com/tsileo/blobstash) JSON document store.
See the [documentation](https://blobstash-python-docstore.a4.io/) for more details.
## Examples
```python
>>> from blobstash.docstore import DocStoreClient, Path, Q
>>> client = DocStoreClient(api_key='123')
>>> col = client.my_collection
>>> col
<blobstash.docstore.Collection name='my_collection'>
>>> # Insert data
>>> k = col.insert({'key': 10, 'k1': True, 'k2': None, 'l': [1, 2, 'c']})
>>> k
<blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>
>>> # Get a single document
>>> col.get_by_id(k)
{'_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>,
'k1': True,
'k2': None,
'key': 10,
'l': [1, 2, 'c']}
>>> col.get_by_id('14d854f6e9ee37a9cd8c1ffc')
{'_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>,
'k1': True,
'k2': None,
'key': 10,
'l': [1, 2, 'c']}
# Native Python query using Q
>>> for doc in col.query(Q['key'] == 10):
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>}
>>> for doc in col.query(Q['key'] > 10):
... print(doc)
>>> for doc in col.query():
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>}
>>> for doc in col.query(Q['l'].contains(1)):
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>}
>>> for doc in col.query(Q['l'][0] == 1):
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>}
>>> # Raw Lua query
>>> # 1. in shortcut mode
>>> for doc in col.query("doc.k1 == true and doc.key ~= nil"):
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>}
>>> # 2. full Lua script
>>> from blobstash.docstore.query import LuaScript
>>> script = LuaScript("""
... return function(doc)
... if doc.key == 10 then
... return true
... end
... return false
... end
... """)
>>> for doc in col.query(script):
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID _id='14d854f6e9ee37a9cd8c1ffc'>}
```
## LICENSE
MIT
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
File details
Details for the file blobstash-docstore-0.1.0.tar.gz
.
File metadata
- Download URL: blobstash-docstore-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
b7a570b82150eca914bccc43c1a906832a420cc277fe52da0f8fd9ad71e4785d
|
|
MD5 |
e7b76b2fc8fcfb5e6a9927477661dc74
|
|
BLAKE2b-256 |
1d48350b915735382eef14aa7b26d6d5e403cfd311a07f4e873361f0efdf13fd
|