Skip to content

Repository files navigation

BlobStash Python Client

builds.sr.ht statusPyPIPyPILicenseCode style: black

Client for BlobStash.

Examples

Document Store

>>>fromblobstash.docstoreimportDocStoreClient, Q>>>client=DocStoreClient(api_key='123')
>>>col=client.my_collection>>>col<blobstash.docstore.Collectionname='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>>>fordocincol.query(Q['key'] ==10):
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID_id='14d854f6e9ee37a9cd8c1ffc'>}
>>>fordocincol.query(Q['key'] >10):
... print(doc)
>>>fordocincol.query():
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID_id='14d854f6e9ee37a9cd8c1ffc'>}
>>>fordocincol.query(Q['l'].contains(1)):
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID_id='14d854f6e9ee37a9cd8c1ffc'>}
>>>fordocincol.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>>>fordocincol.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>>>fromblobstash.docstore.queryimportLuaScript>>>script=LuaScript("""... return function(doc)... if doc.key == 10 then... return true... end... return false... end... """)
>>>fordocincol.query(script):
... print(doc)
{'k1': True, 'k2': None, 'key': 10, 'l': [1, 2, 'c'], '_id': <blobstash.docstore.ID_id='14d854f6e9ee37a9cd8c1ffc'>}

LICENSE

MIT

About

Python client for BlobStash. Mirror of https://git.sr.ht/~tsileo/blobstash-python

Topics

Resources

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages