Objectstore#

These functions are used by OpenGHG to store and retrieve data from the object store. OpenGHG will call either local object store functions (that create an object store on disk) or cloud object store functions depending on its environment. Within the __init__.py of openghg.objectstore a check is made to see if the environment is the OpenGHG hub or a serverless function.

Local#

These functions handle data storage on disk.

openghg.objectstore.delete_object(bucket, key)[source]#

Remove object at key in bucket

Parameters:
  • bucket (str) – Bucket path

  • key (str) – Key to data in bucket

Return type:

None

Returns:

None

openghg.objectstore.exists(bucket, key)[source]#

Checks if there is an object in the object store with the given key

Parameters:
  • bucket (str) – Bucket containing data

  • key (str) – Prefix for key in object store

Returns:

True if key exists in store

Return type:

bool

openghg.objectstore.get_all_object_names(bucket, prefix=None, without_prefix=False)[source]#

Returns the names of all objects in the passed bucket

Parameters:
  • bucket (str) – Bucket path

  • prefix (Optional[str]) – Prefix for keys

  • without_prefix (bool) – If True don’t use prefix

Returns:

List of object names

Return type:

list

openghg.objectstore.get_bucket(empty=False)[source]#

Find and return a new bucket in the object store called ‘bucket_name’. If ‘create_if_needed’ is True then the bucket will be created if it doesn’t exist. Otherwise, if the bucket does not exist then an exception will be raised.

Return type:

str

openghg.objectstore.get_object(bucket, key)[source]#

Gets the object at key in the passed bucket

Parameters:
  • bucket (str) – Bucket containing data

  • key (str) – Key for data in bucket

Returns:

Binary data from the store

Return type:

bytes

openghg.objectstore.get_object_from_json(bucket, key)[source]#

Return an object constructed from JSON stored at key.

Parameters:
  • bucket (str) – Bucket containing data

  • key (str) – Key for data in bucket

Returns:

Dictionary

Return type:

dict

openghg.objectstore.get_object_names(bucket, prefix=None)[source]#

List all the keys in the object store

Parameters:

bucket (str) – Bucket containing data

Returns:

List of keys in object store

Return type:

list

openghg.objectstore.get_local_objectstore_path()[source]#

Read

Returns:

Path of object store

Return type:

pathlib.Path

openghg.objectstore.get_tutorial_store_path()[source]#

Get the path to the local tutorial store

Returns:

Path of tutorial store

Return type:

pathlib.Path

openghg.objectstore.query_store()[source]#

Create a dictionary that can be used to visualise the object store

Returns:

Dictionary for data to be shown in force graph

Return type:

dict

openghg.objectstore.set_object(bucket, key, data)[source]#

Store data in bucket at key

Parameters:
  • bucket (str) – Bucket path

  • key (str) – Key to store data in bucket

  • data (bytes) – Data in string form

Return type:

None

Returns:

None

openghg.objectstore.set_object_from_file(bucket, key, filename)[source]#

Set the contents of file at filename to key in bucket

Parameters:
  • bucket (str) – Bucket path

  • key (str) – Key to for data

  • filename (str, pathlib.Path) – Filename/path

Return type:

None

Returns:

None

openghg.objectstore.set_object_from_json(bucket, key, data)[source]#

Set JSON data in the object store

Parameters:
  • bucket (str) – Bucket for data storage

  • key (str) – Key for data in bucket

  • data (Union[str, Dict]) – JSON serialised data string

Return type:

None

Returns:

None

openghg.objectstore.visualise_store()[source]#

View the object store using a pyvis force graph.

This function should only be called from within a notebook

Return type:

Network

Returns:

pyvis.network.Network