Skip to content

Installation

Prerequisites:

  • Python 3.9+
  • Internet access

Install with pip:

pip install cript

Connect to CRIPT

Establish a connection with an API endpoint:

import cript

host = "<endpoint_hostname>"  # e.g., criptapp.org
token = "<your_api_token>"
cript.API(host, token)

Note

Your API token can be found in the UI under Account Settings.


Example Tasks

Create a node

For example, create a Project:

proj = cript.Project(name="MyProject")
proj.save()
... then a Collection:
coll = cript.Collection.create(project=proj, name="MyCollection")

Note

Notice the use of create() here, which instantiates and saves the object in one go.

Update a node

For example, update the Project node created above:

proj.name = "OurProject"
proj.save()
... then the Collection:
coll.update(name="OurCollection")

Note

Notice the use of update() here, which updates and saves a node in one go.

Delete a node

For example, delete the Collection node created above:

coll.delete()

Get an existing node

For example, get the official CRIPT Project node:

proj = cript.Project.get(name="CRIPT")
... then get the official styrene Material node via name:
styrene =  cript.Material.get(project=proj.uid, name="Styrene")
... or via UID
styrene =  cript.Material.get(uid="<material_uid>")
... or via URL
styrene =  cript.Material.get(url="<material_url>")

Run a search query

For example, search for Material nodes with a molar mass less than 10 g/mol:

res =  cript.Material.search(
    properties = [
        {
            "key": "molar_mass",
            "value__lt": 10,
            "unit": "g/mol"
        }
    ]
)

... then paginate through the results.

res.json()              # View the raw JSON for the query
res.objects()           # Generate objects for the current page
res.next_page()         # Flip to the next page
res.previous_page()     # Flip to the previous page

Upload a file

First, you'll need a Project and Data node:

proj = cript.Project.get(uid="<project_uid>")
data = cript.Data.get(uid="<data_uid>")
Next, create a File node that points to your local file:
path = "path/to/local/file"
f = cript.File(project=proj, source=path)
file.save()

Download a file

For example, download the file you uploaded above.

path = "path/to/local/file"
f.download_file(path=path)

Note

The default path for a download is your current directory.