Tutorial

This tutorial is intended as an introduction to working with glitter and glitter-sdk-py. For an introduction on using these utilities, see the Examples.

Getting Started

We begin by creating an object of class GlitterClient:

from glitter-sdk import GlitterClient
glitter_client = GlitterClient()

Or use your glitter root url

from glitter-sdk import GlitterClient
url = 'http://127.0.0.1:26659'  # Or Use YOUR Glitter Root URL here
glitter_client = GlitterClient(url)

Create Schema

First, create a schema for documents.

schema_name="demo"
fields = [
    {
        "name": "doi",
        "type": "string",
        "primary": "true",
        "index": {
            "type": "keyword"
        }
    },
    {
        "name": "title",
        "type": "string",
        "index": {
            "type": "text"
        }
    },
    {
        "name": "ipfs_cid",
        "type": "string",
        "index": {
            "index": "false"
        }
    }
]
res = glitter_client.db.create_schema(schema_name, fields)
# result like this
{
    "code": 0,
    "message": "ok",
    "tx": "B88CEA8172F0B8BD7EAC3021C1B347786F74EDCD9110A7525C61237CD91FCE73",
    "data": ""
}

Put Document to Glitter

Then, put a document glitter by glitter-sdk. For example:

demo_doc = {
    "doi": "10.1002/(sci)1099-1697(199803/04)7:2<65::aid-jsc357>3.0.c",
    "title": "British Steel Corporation: probably the biggest turnaround story in UK industrial history",
    "ipfs_cid": "https://ipfs.io/ipfs/bafybeicoccgasbfx3puk5fxfol6gnbsaj7ssqs5gmhggotpx52p4pb6oze/6dbc6bb3e4993915f5ca07ca854ac31c.pdf"
}
res = self.glitter_client.db.put_doc(self.schema_name, demo_doc)
# return like this, the tx is transaction id.
{
  "code": 0,
  "message": "ok",
  "tx": "49429CDC575C0ED6D021FE9BEE1D44578AC7EDAD61A25EBBF0DE72746E0064F8",
  "data": ""
}