Gen3 Metadata Class

class gen3.metadata.Gen3Metadata(endpoint=None, auth_provider=None, service_location='mds', admin_endpoint_suffix='-admin')[source]

Bases: object

A class for interacting with the Gen3 Metadata services.

Examples

This generates the Gen3Metadata class pointed at the sandbox commons while using the credentials.json downloaded from the commons profile page.

>>> auth = Gen3Auth(refresh_file="credentials.json")
... metadata = Gen3Metadata(auth)
endpoint

public endpoint for reading/querying metadata - only necessary if auth_provider not provided

Type

str

auth_provider

auth manager

Type

Gen3Auth

async_create(guid, metadata, overwrite=False, _ssl=None, **kwargs)[source]

Asynchronous function to create metadata

Parameters
  • guid (str) – guid to use

  • metadata (Dict) – dictionary representing what will end up a JSON blob attached to the provided GUID as metadata

  • overwrite (bool, optional) – whether or not to overwrite existing data

  • _ssl (None, optional) – whether or not to use ssl

async_get(guid, _ssl=None, **kwargs)[source]

Asynchronous function to get metadata

Parameters
  • guid (str) – guid to use

  • _ssl (None, optional) – whether or not to use ssl

Returns

metadata for given guid

Return type

Dict

async_update(guid, metadata, _ssl=None, **kwargs)[source]

Asynchronous function to update metadata

Parameters
  • guid (str) – guid to use

  • metadata (Dict) – dictionary representing what will end up a JSON blob attached to the provided GUID as metadata

  • _ssl (None, optional) – whether or not to use ssl

batch_create(metadata_list, overwrite=True, **kwargs)[source]

Create the list of metadata associated with the list of guids

Parameters
  • (List[Dict{"guid" (metadata_list) – “”, “data”: {}}]): list of metadata objects in a specific format. Expects a dict with “guid” and “data” fields where “data” is another JSON blob to add to the mds

  • overwrite (bool, optional) – whether or not to overwrite existing data

create(guid, metadata, overwrite=False, **kwargs)[source]

Create the metadata associated with the guid

Parameters
  • guid (str) – guid to use

  • metadata (Dict) – dictionary representing what will end up a JSON blob attached to the provided GUID as metadata

  • overwrite (bool, optional) – whether or not to overwrite existing data

create_index_key_path(path)[source]

Create a metadata key path indexed in the database.

Parameters

path (str) – metadata key path

delete(guid, **kwargs)[source]

Delete the metadata associated with the guid

Parameters

guid (str) – guid to use

delete_index_key_path(path)[source]

List all the metadata key paths indexed in the database.

Parameters

path (str) – metadata key path

get(guid, **kwargs)[source]

Get the metadata associated with the guid

Parameters

guid (str) – guid to use

Returns

metadata for given guid

Return type

Dict

get_index_key_paths()[source]

List all the metadata key paths indexed in the database.

Returns

list of metadata key paths

Return type

List

get_version()[source]

Return the version

Returns

the version

Return type

str

is_healthy()[source]

Return if is healthy or not

Returns

True if healthy

Return type

bool

query(query, return_full_metadata=False, limit=10, offset=0, **kwargs)[source]

Query the metadata given a query.

Query format is based off the logic used in the service:

‘’’ Without filters, this will return all data. Add filters as query strings like this:

GET /metadata?a=1&b=2

This will match all records that have metadata containing all of:

{“a”: 1, “b”: 2} The values are always treated as strings for filtering. Nesting is supported:

GET /metadata?a.b.c=3

Matching records containing:

{“a”: {“b”: {“c”: 3}}} Providing the same key with more than one value filters records whose value of the given key matches any of the given values. But values of different keys must all match. For example:

GET /metadata?a.b.c=3&a.b.c=33&a.b.d=4

Matches these:

{“a”: {“b”: {“c”: 3, “d”: 4}}} {“a”: {“b”: {“c”: 33, “d”: 4}}} {“a”: {“b”: {“c”: “3”, “d”: 4, “e”: 5}}} But won’t match these:

{“a”: {“b”: {“c”: 3}}} {“a”: {“b”: {“c”: 3, “d”: 5}}} {“a”: {“b”: {“d”: 5}}} {“a”: {“b”: {“c”: “333”, “d”: 4}}} ‘’’

Parameters
  • query (str) – mds query as defined by the metadata api

  • return_full_metadata (bool, optional) – if False will just return a list of guids

  • limit (int, optional) – max num records to return

  • offset (int, optional) – offset for output

Returns

list of guids matching query

OR if return_full_metadata=True

Dict{guid: {metadata}}: Dictionary with GUIDs as keys and associated

metadata JSON blobs as values

Return type

List

update(guid, metadata, **kwargs)[source]

Update the metadata associated with the guid

Parameters
  • guid (str) – guid to use

  • metadata (Dict) – dictionary representing what will end up a JSON blob attached to the provided GUID as metadata