Library Reference¶
driver¶
- class glitter_sdk.GlitterClient(*nodes, headers=None, transport_class=<class 'glitter_sdk.transport.Transport'>, timeout=10)[source]¶
Bases:
objectA :class: ~driver.GlitterClient is a python client for Glitter. We can use this client to connect, create schema and put & search documents in Glitter.
- __init__(*nodes, headers=None, transport_class=<class 'glitter_sdk.transport.Transport'>, timeout=10)[source]¶
Initializes a
GlitterClientdriver instance.- Parameters
*nodes (list of (str or dict)) – Glitter nodes to connect to.
headers (dict) – Optional headers that will be passed with each request.
transport_class – Optional transport class to use.
timeout (int) – Optional timeout in seconds that will be passed to each request.
- property nodes¶
tupleofstr: URLs of connected nodes.
- property transport¶
Object responsible for forwarding requests to a
Connectioninstance (node).- Type
Transport
- class glitter_sdk.driver.DataBase(driver)[source]¶
Bases:
glitter_sdk.driver.NamespacedDriverDB to get access of the data in Glitter.
- create_schema(schema_name, fields)[source]¶
- Parameters
schema_name (-) – name of the schema.
fields (-) – list of schema fields in JSON format. It’s required to specify the type field under the index field. O.w., get_doc functions are not able to be used. For more details, please follow instructions at https://docs.glitterprotocol.io.
- Returns
request result.
- Return type
dic
- get_schema(schema_name)[source]¶
- Parameters
schema_name (-) – name of the schema.
- Returns
detailed information of the schema.
- Return type
dic
- app_status()[source]¶
- Returns
- a list of data schemas in Glitter along with the
record counts.
- Return type
dic
- put_doc(schema_name, doc_data)[source]¶
Put document to Glitter.
- Parameters
schema_name (-) – name of the schema.
doc_data (-) – doc content.
- Returns
put doc transaction result with code, msg, tx.
- Return type
dic
- get_doc(schema_name, primary_key)[source]¶
Get documents from Glitter by the primary key.
- Parameters
schema_name (str) – name of the schema.
primary_key – a unique key of the document.
- Returns
result with the document struct.
- Return type
dic
- get_docs(schema_name, primary_key)[source]¶
Get documents from glitter by doc ids.
- Parameters
schema_name (str) – name of the schema.
primary_key (list) – keys of the documents and each of them must be unique.
- Returns
detailed documents in Glitter.
- Return type
dic
- search(schema_name, query_word, query_field=[], filters=[], aggs_field=[], order_by='', limit=10, page=1)[source]¶
Search from Glitter specified by the conditions and filters.
- Parameters
schema_name (str) – name of the schema.
query_word (str) – word to search in the query_field.
( (aggs_field) – obj: list of str): a list of the fields to search. If it’s empty, will search all the fields.
filters (
listofdic) – filter conditions.( – obj: list of str): aggregated field which is defined in the schema. Aggregation a multi-bucket value source based aggregation, where buckets are dynamically built - one per unique value.
order_by (str) – adds a sort order.
limit (int) – sets an upper limit on the response body size that we accept.
page (int) – page index to start the search from.
- Returns
a list of documents which have matched query word in their fields.
- Return type
dic
- class glitter_sdk.driver.Chain(driver)[source]¶
Bases:
glitter_sdk.driver.NamespacedDriver- status()[source]¶
- Get Tendermint status including node info, pubkey, latest block
hash, app hash, block height, current max peer height and time.
- Returns
Details of the HTTP API provided by the Tendermint server.
- Return type
json
- tx_search(query, page=1, per_page=30, order_by='desc', prove=True)[source]¶
Search for transactions.
- Parameters
query (str) – query words. (e.g:
tx.height=1000, tx.hash='xxx', update_doc.token='test_token')page (int) – page index to start the search from. Defaults to
1.per_page (int) – number of entries per page (max:
100,defaults to30) .order_by (str) – Sort the returned transactions (
ascordesc) by height & index . If it’s empty, desc is used as default.prove (bool) – Include proofs of the transactions in the block. Defaults to
True. (This is an option to the tendermint concept, indicating whether the return value is included in the block’s transaction proof.)
- Returns
obj”json: transaction info.
- block_search(query, page=1, per_page=30, order_by='desc')[source]¶
- Search for blocks by BeginBlock and EndBlock events (BeginBlock and
- EndBlock is the concept of tendermint.
https://docs.tendermint.com/master/spec/abci/apps.html#beginblock)
- Parameters
query (str) – query condition. (e.g:
block.height > 1000 AND valset.changed > 0)page (int) – page index to start the search from.
per_page (int) – number of entries per page (max: 100)
order_by (str) – sort the returned blocks (“asc” or “desc”) by height. If it’s empty, desc is used as default.
- Returns
block info.
- Return type
json
- class glitter_sdk.driver.Admin(driver)[source]¶
Bases:
glitter_sdk.driver.NamespacedDriver'/admin'endpoint whi is used to manage the nodes.- update_validator(pub_key, power=0, headers=None)[source]¶
Update validator set. A validator is a peer who can vote.
- Parameters
pub_key (str) – public key
power (int) – power
headers (dict) – http header
- Returns
validator information.
- Return type
dic
- validators(height=None, page=1, per_page=100)[source]¶
Get validator set at a specific height.
- Parameters
height (str) – Fetch validators with the specific height. If height is not set, return the lastest validator.
page (int) – page index to start the search from. (1-based)
per_page (int) – Number of entries per page (max: 100)
- Returns
- A list of Validators which are sorted first by voting
power (descending), then by address (ascending).
- Return type
json