Knowledge Graph

Table of Contents:

Schemas

Using schemas is a way to ensure your data to follow a set of rules.

nexussdk.schemas.create(org_label, project_label, schema_obj, schema_id=None)

Create a new schema

Parameters
  • org_label – Label of the organization in which to create the schema

  • project_label – label of the project in which to create a schema

  • schema_obj – Schema, can be a dictionary or a JSON string

  • schema_id – OPTIONAL The view will be created with this specific internal id, if provided. Otherwise, an id will be generated by Nexus.

Returns

payload of the schema as a Python dictionary. This payload is partial and contains only Nexus metadata. To get the full schema payload, use the fetch() method.

nexussdk.schemas.deprecate(schema, rev=None)

Flag a schema as deprecated. Schema cannot be deleted in Nexus, once one is deprecated, it is no longer possible to update it.

Parameters
  • schema – payload of a previously fetched resource

  • rev – OPTIONAL The previous revision you want to update from. If not provided, the rev from the schema argument will be used.

Returns

A payload containing only the Nexus metadata for this deprecated schema.

nexussdk.schemas.fetch(org_label, project_label, schema_id, rev=None, tag=None)

Fetches a distant schema and returns the payload as a dictionary. In case of error, an exception is thrown.

Parameters
  • org_label – The label of the organization that the resource belongs to

  • project_label – The label of the project that the resource belongs to

  • schema_id – id of the schema

  • rev – OPTIONAL fetches a specific revision of a schema (default: None, fetches the last)

  • tag – OPTIONAL fetches the schema version that has a specific tag (default: None)

Returns

Payload of the whole schema as a dictionary

nexussdk.schemas.list(org_label, project_label, pagination_from=0, pagination_size=20, deprecated=None, full_text_search_query=None)

List all the schemas available.

Parameters
  • org_label – Label of the organization to which listing the schema

  • project_label – Label of the project to which listing the schema

  • pagination_from – OPTIONAL The pagination index to start from (default: 0)

  • pagination_size – OPTIONAL The maximum number of elements to returns at once (default: 20)

  • deprecated – OPTIONAL Get only deprecated resource if True and get only non-deprecated results if False. If not specified (default), return both deprecated and not deprecated resource.

  • full_text_search_query – A string to look for as a full text query

Returns

The raw payload as a dictionary

Returns

List of schema and some Nexus metadata

nexussdk.schemas.tag(schema, tag_value, rev_to_tag=None, rev=None)

Add a tag to a a specific revision of the schema. Note that a new revision (untagged) will be created

Parameters
  • schema – payload of a previously fetched schema

  • tag_value – The value (or name) of a tag

  • rev_to_tag – OPTIONAL Number of the revision to tag. If not provided, this will take the revision number from the provided schema payload.

  • rev – OPTIONAL The previous revision you want to update from. If not provided, the rev from the schema argument will be used.

Returns

A payload containing only the Nexus metadata for this schema.

nexussdk.schemas.update(schema, rev=None)

Update a schema. The schema object is most likely the returned value of a nexus.schema.fetch(), where some fields where modified, added or removed. Note that the returned payload only contains the Nexus metadata and not the complete resource.

Parameters
  • schema – payload of a previously fetched resource, with the modification to be updated

  • rev – OPTIONAL The previous revision you want to update from. If not provided, the rev from the schema argument will be used.

Returns

A payload containing only the Nexus metadata for this updated schema.

Resolvers

This module provides a Python interface for operations on Resolvers. It is part of the Knowledge Graph API of Blue Brain Nexus v1. https://bluebrainnexus.io/docs/api/kg/kg-resolvers-api.html

nexussdk.resolvers.create(org_label: str, project_label: str, projects: List[str], identities: List[Dict], priority: int, id: str = None, resource_types: List[str] = None) → Dict

Create a cross-project resolver.

Parameters
  • org_label – Label of the organization the resolver belongs to.

  • project_label – Label of the project the resolver belongs to.

  • projects – List of target projects, given with format organization/project.

  • identities – List of identities the creator of the resolver has and which have the permission resources/read on the target projects.

  • priority – Resolution priority.

  • id – (optional) User-defined ID of the resolver, given as an IRI which is not URL encoded.

  • resource_types – (optional) List of types of the resources to resolve, given as IRIs.

Returns

The Nexus metadata of the created resolver.

nexussdk.resolvers.create_(path: str, payload: Dict, id: str = None) → Dict

Create a resolver (path version).

Parameters
  • path – Full path of the project the resolver belongs to, URL encoded.

  • payload – Payload of the resolver.

  • id – (optional) User-defined ID of the resolver, given as an IRI which is not URL encoded.

Returns

The Nexus metadata of the created resolver.

nexussdk.resolvers.fetch(org_label: str, project_label: str, id: str, tag: str = None, rev: int = None) → Dict

Fetch a resolver.

Raise an Exception if rev and tag are used together.

Parameters
  • org_label – Label of the organization the resolver belongs to.

  • project_label – Label of the project the resolver belongs to.

  • id – ID of the resolver, given as an IRI which is not URL encoded.

  • tag – (optional) Tag of the resolver.

  • rev – (optional) Revision number of the resolver.

Returns

The Nexus payload of the fetched resolver.

nexussdk.resolvers.fetch_(path: str, tag: str = None, rev: int = None) → Dict

Fetch a resolver (full path version).

Raise an Exception if rev and tag are used together.

Parameters
  • path – Full path of the resolver (i.e. includes its ID), URL encoded.

  • tag – (optional) Tag of the resolver.

  • rev – (optional) Revision number of the resolver.

Returns

The Nexus payload of the fetched resolver.

nexussdk.resolvers.list(org_label: str, project_label: str, pagination_from: int = None, pagination_size: int = None, deprecated: bool = None, type: str = None, created_by: str = None, updated_by: str = None, rev: int = None) → Dict

List resolvers corresponding to some criteria.

Parameters
  • org_label – Label of the organization the resolver belongs to.

  • project_label – Label of the project the resolver belongs to.

  • pagination_from – (optional) Pagination index to start from. Default: 0.

  • pagination_size – (optional) Number of results to return per page. Default: 20.

  • deprecated – (optional) Deprecation status of the resolvers to keep.

  • type – (optional) Type of the resolvers to keep, given as an IRI.

  • created_by – (optional) Identity ID of the creator of the resolvers to keep, given as an IRI.

  • updated_by – (optional) Identity ID of the last identity which has updated the resolvers to keep, given as en IRI.

  • rev – (optional) Revision number of the resolvers to keep.

Returns

A Nexus results list with the Nexus metadata of the matching resolvers.

nexussdk.resolvers.list_(path: str, pagination_from: int = None, pagination_size: int = None, deprecated: bool = None, type: str = None, created_by: str = None, updated_by: str = None, rev: int = None) → Dict

List resolvers corresponding to some criteria (path version).

Parameters
  • path – Full path of the project the resolver belongs to, URL encoded.

  • pagination_from – (optional) Pagination index to start from. Default: 0.

  • pagination_size – (optional) Number of results to return per page. Default: 20.

  • deprecated – (optional) Deprecation status of the resolvers to keep.

  • type – (optional) Type of the resolvers to keep, given as an IRI.

  • created_by – (optional) Identity ID of the creator of the resolvers to keep, given as an IRI.

  • updated_by – (optional) Identity ID of the last identity which has updated the resolvers to keep, given as en IRI.

  • rev – (optional) Revision number of the resolvers to keep.

Returns

A Nexus results list with the Nexus metadata of the matching resolvers.

nexussdk.resolvers.update(org_label: str, project_label: str, id: str, projects: List[str], identities: List[Dict], priority: int, rev: int, resource_types: List[str] = None) → Dict

Update a resolver.

Parameters
  • org_label – Label of the organization the resolver belongs to.

  • project_label – Label of the project the resolver belongs to.

  • id – ID of the resolver, given as an IRI which is not URL encoded.

  • projects – List of target projects, given with format organization/project.

  • identities – List of identities the creator of the resolver has and which have the permission resources/read on the target projects.

  • priority – Resolution priority.

  • rev – Last revision of the resolver.

  • resource_types – (optional) List of types of the resources to resolve, given as IRIs.

Returns

The Nexus metadata of the updated resolver.

nexussdk.resolvers.update_(path: str, payload: Dict, rev: int) → Dict

Update a resolver (full path version).

Parameters
  • path – Full path of the resolver (i.e. includes its ID), URL encoded.

  • payload – Payload of the resolver.

  • rev – Last revision of the resolver.

Returns

The Nexus metadata of the updated resolver.

nexussdk.resolvers.tag(org_label: str, project_label: str, id: str, tag: str, rev_to_tag: str, rev: int) → Dict

Tag a revision of a resolver.

Parameters
  • org_label – Label of the organization the resolver belongs to.

  • project_label – Label of the project the resolver belongs to.

  • id – ID of the resolver, given as an IRI which is not URL encoded.

  • tag – Tag to set.

  • rev_to_tag – Revision number to tag.

  • rev – Last revision of the resolver.

Returns

The Nexus metadata of the tagged resolver.

nexussdk.resolvers.tag_(path: str, payload: Dict, rev: int) → Dict

Tag a revision of a resolver (full path version).

Parameters
  • path – Full path of the resolver (i.e. includes its ID), URL encoded.

  • payload – Payload of the tag.

  • rev – Last revision of the resolver.

Returns

The Nexus metadata of the tagged resolver.

nexussdk.resolvers.deprecate(org_label: str, project_label: str, id: str, rev: int) → Dict

Deprecate a resolver.

Parameters
  • org_label – Label of the organization the resolver belongs to.

  • project_label – Label of the project the resolver belongs to.

  • id – ID of the resolver, given as an IRI which is not URL encoded.

  • rev – Last revision of the resolver.

Returns

The Nexus metadata of the deprecated resolver.

nexussdk.resolvers.deprecate_(path: str, rev: int) → Dict

Deprecate a resolver (full path version).

Parameters
  • path – Full path of the resolver (i.e. includes its ID), URL encoded.

  • rev – Last revision of the resolver.

Returns

The Nexus metadata of the deprecated resolver.

Views

A view is a way to access Nexus data and to perform queries. A view belongs to a specific project. By default, an ElasticSearch view and a SparQL view are provided. More ElasticSearch views can be created manually, hence providing a custom indexing and custom research capabilities.

nexussdk.views.aggregate_es(org_label, project_label, esviews, id)

Creates an aggregated view for ElasticSearch.

Parameters
  • org_label – Label of the organization the view wil belong to

  • project_label – label of the project the view will belong too

  • esviews – list of ElasticSearch view payloads, most likely got with .fetch()

  • id – id to give to this aggregation id ElasticSearch views

Returns

A payload containing only the Nexus metadata for this aggregated view.

nexussdk.views.create_es(org_label, project_label, view_data, view_id=None)

Creates an ElasticSearch view

Parameters
  • org_label – Label of the organization the view wil belong to

  • project_label – label of the project the view will belong too

  • view_data – Mapping data required for ElasticSearch indexing

  • view_id – OPTIONAL if provided, the view will be created with the given id. Otherwise, an autogenerated one will be given by Nexus

Returns

The payload representing the view. This payload only contains the Nexus metadata

nexussdk.views.deprecate_es(esview, rev=None)

Update a ElasticSearch view. The esview object is most likely the returned value of a nexus.views.fetch(), where some fields where modified, added or removed. Note that the returned payload only contains the Nexus metadata and not the complete view.

Parameters
  • esview – payload of a previously fetched view, with the modification to be updated

  • rev – OPTIONAL The previous revision you want to update from. If not provided, the rev from the view argument will be used.

Returns

A payload containing only the Nexus metadata for this updated view.

nexussdk.views.fetch(org_label, project_label, view_id, rev=None, tag=None)

Fetches a distant view and returns the payload as a dictionary. In case of error, an exception is thrown.

Parameters
  • org_label – The label of the organization that the view belongs to

  • project_label – The label of the project that the view belongs to

  • view_id – id of the view

  • rev – OPTIONAL fetches a specific revision of a view (default: None, fetches the last)

  • tag – OPTIONAL fetches the view version that has a specific tag (default: None)

Returns

Payload of the whole view as a dictionary

nexussdk.views.list(org_label, project_label, pagination_from=0, pagination_size=20, deprecated=None, type=None, rev=None, schema=None, created_by=None, updated_by=None, view_id=None)

List the views available for a given organization and project. All views, of all kinds.

Parameters
  • org_label – The label of the organization that the view belongs to

  • project_label – The label of the project that the view belongs to

  • pagination_from – OPTIONAL The pagination index to start from (default: 0)

  • pagination_size – OPTIONAL The maximum number of elements to returns at once (default: 20)

  • deprecated – OPTIONAL Get only deprecated view if True and get only non-deprecated results if False. If not specified (default), return both deprecated and not deprecated view.

  • type – OPTIONAL The view type

  • rev – OPTIONAL Revision to list

  • schema – OPTIONAL list only the views with a certain schema

  • created_by – OPTIONAL List only the views created by a certain user

  • updated_by – OPTIONAL List only the views that were updated by a certain user

  • view_id – OPTIONAL List only the view with this id. Relevant only when combined with other args

Returns

The raw payload as a dictionary

nexussdk.views.list_keep_only_es(viewlist)

Helper function to keep only the ElasticSearch views metadata from the result of a .list() call.

Parameters

viewlist – the payload returned by .list()

Returns

the list of ElasticSearch view metadata (beware: not complete payloads like if it was the result of .fetch() calls)

nexussdk.views.list_keep_only_sparql(viewlist)

Helper function to keep only the SparQL views metadata from the result of a .list() call.

Parameters

viewlist – the payload returned by .list()

Returns

the list of SparQL view metadata (beware: not complete payloads like if it was the result of .fetch() calls)

nexussdk.views.query_es(org_label, project_label, query, view_id='documents')

Perform a ElasticSearch query.

Parameters
  • org_label – Label of the organization to perform the query on

  • project_label – Label of the project to perform the query on

  • view_id – id of an ElasticSearch view

  • query – ElasticSearch query as a JSON string or a dictionary

Returns

the result of the query as a dictionary

nexussdk.views.query_sparql(org_label, project_label, query)

Perform a SparQL query.

Parameters
  • org_label – Label of the organization to perform the query on

  • project_label – Label of the project to perform the query on

  • query – Query as a string

Returns

result of the query as a dictionary

nexussdk.views.tag_es(esview, tag_value, rev_to_tag=None, rev=None)

Add a tag to a a specific revision of an ElasticSearch view. Note that a new revision (untagged) will be created.

Parameters
  • esview – payload of a previously fetched view (ElasticSearch)

  • tag_value – The value (or name) of a tag

  • rev_to_tag – OPTIONAL Number of the revision to tag. If not provided, this will take the revision number from the provided resource payload.

  • rev – OPTIONAL The previous revision you want to update from. If not provided, the rev from the resource argument will be used.

Returns

A payload containing only the Nexus metadata for this view.

nexussdk.views.update_es(esview, rev=None)

Update a ElasticSearch view. The esview object is most likely the returned value of a nexus.views.fetch(), where some fields where modified, added or removed. Note that the returned payload only contains the Nexus metadata and not the complete view.

Parameters
  • esview – payload of a previously fetched view, with the modification to be updated

  • rev – OPTIONAL The previous revision you want to update from. If not provided, the rev from the view argument will be used.

Returns

A payload containing only the Nexus metadata for this updated view.

Files

Files are a particular kind of resource that contain binary data. In addition, like any other resource, they are bound to a project (and thus, an organization) and can be described with their metadata.

nexussdk.files.create(org_label, project_label, filepath, file_id=None)

This is the POST method, when the user does not provide a file ID.

Parameters
  • org_label – The label of the organization that the file belongs to

  • project_label – The label of the project that the file belongs to

  • filepath – path of the file to upload

  • file_id – OPTIONAL Will use this id to identify the file if provided. If not provided, an ID will be generated

Returns

A payload containing only the Nexus metadata for this updated file.

nexussdk.files.deprecate(file, rev=None)

Flag a file as deprecated. files cannot be deleted in Nexus, once one is deprecated, it is no longer possible to update it.

Parameters
  • file – payload of a previously fetched file

  • rev – OPTIONAL The previous revision you want to update from. If not provided, the rev from the file argument will be used.

Returns

A payload containing only the Nexus metadata for this deprecated file.

nexussdk.files.fetch(org_label, project_label, file_id, rev=None, tag=None, out_filepath=None)

Fetches a distant file and returns the metadata of this file. In addition, if the argument out_filepath can be of three forms: - out_filepath=None (default): the binary is not fetched - out_filepath=”./some/folder/” the binary is fetched and written in this dir with it’s original filename - out_filepath=”./somefile.jpg” the binary is fetched and written under this exact filename

In case of error, an exception is thrown.

Parameters
  • org_label – The label of the organization that the file belongs to

  • project_label – The label of the project that the file belongs to

  • file_id – id of the file

  • rev – OPTIONAL fetches a specific revision of a file (default: None, fetches the last)

  • tag – OPTIONAL fetches the file version that has a specific tag (default: None)

  • out_filepath – OPTIONAL the filename to write (default: None)

Returns

Payload of the whole file as a dictionary

nexussdk.files.list(org_label, project_label, pagination_from=0, pagination_size=20, deprecated=None, type=None, rev=None, schema=None, created_by=None, updated_by=None, file_id=None)

List the files available for a given organization and project.

Parameters
  • org_label – The label of the organization that the file belongs to

  • project_label – The label of the project that the file belongs to

  • pagination_from – OPTIONAL The pagination index to start from (default: 0)

  • pagination_size – OPTIONAL The maximum number of elements to returns at once (default: 20)

  • deprecated – OPTIONAL Get only deprecated file if True and get only non-deprecated results if False. If not specified (default), return both deprecated and not deprecated file.

  • type – OPTIONAL Lists only the file for a given type (default: None)

  • rev – OPTIONAL List only the resource with this particular revision

  • schema – OPTIONAL list only the views with a certain schema

  • created_by – OPTIONAL List only the file created by a certain user

  • updated_by – OPTIONAL List only the file that were updated by a certain user

  • file_id – OPTIONAL List only the file with this id. Relevant only when combined with other args

Returns

The raw list payload as a dictionary

nexussdk.files.tag(file, tag_value, rev_to_tag=None, rev=None)

Add a tag to a a specific revision of the file. Note that a new revision (untagged) will be created

Parameters
  • file – payload of a previously fetched file

  • tag_value – The value (or name) of a tag

  • rev_to_tag – OPTIONAL Number of the revision to tag. If not provided, this will take the revision number from the provided file payload.

  • rev – OPTIONAL The previous revision you want to update from. If not provided, the rev from the file argument will be used.

Returns

A payload containing only the Nexus metadata for this file.

nexussdk.files.tags(file)

List all the tags added to this file, along with their version numbers

Parameters

file – payload of a previously fetched file

Returns

payload containing the list of tags and versions

nexussdk.files.update(file, filepath, rev=None)

Update a file. The file object is most likely the returned value of a nexus.file.fetch(), where some fields where modified, added or removed. Note that the returned payload only contains the Nexus metadata and not the complete file.

Parameters
  • file – payload of a previously fetched file, with the modification to be updated

  • rev – OPTIONAL The previous revision you want to update from. If not provided, the rev from the file argument will be used.

Returns

A payload containing only the Nexus metadata for this updated file.

Resources

A resource represents a set of organized data represented with JSON. Hence, a resource can handle data such as numbers, strings, arrays, boolean and complex objects made of those primitive types. In addition, Nexus adds some metadata. Resources belong to projects and their access rights are defined at the project level.

nexussdk.resources.create(org_label, project_label, data, schema_id='_', resource_id=None)

Create a resource. If resource_id is provided, this given ID will be used. If resource_id not provided, an ID will be automatically generated for this new resource.

Parameters
  • org_label – The label of the organization that the resource belongs to

  • project_label – The label of the project that the resource belongs to

  • schema_id – OPTIONAL The schema to constrain the data. Can be None for non constrained data (default: “resource)

  • data – dictionary containing the data to store in this new resource

  • resource_id – OPTIONAL force the use of a specific id when creating the new resource

Returns

A payload containing only the Nexus metadata for this updated resource.

If the data does not have a “@context” value, a default one is automatically added.

nexussdk.resources.deprecate(resource, rev=None)

Flag a resource as deprecated. Resources cannot be deleted in Nexus, once one is deprecated, it is no longer possible to update it.

Parameters
  • resource – payload of a previously fetched resource

  • rev – OPTIONAL The previous revision you want to update from. If not provided, the rev from the resource argument will be used.

Returns

A payload containing only the Nexus metadata for this deprecated resource.

nexussdk.resources.fetch(org_label, project_label, resource_id, schema_id='_', rev=None, tag=None)

Fetches a distant resource and returns the payload as a dictionary. In case of error, an exception is thrown.

Parameters
  • org_label – The label of the organization that the resource belongs to

  • project_label – The label of the project that the resource belongs to

  • resource_id – id of the resource

  • schema_id – OPTIONAL id of the schema (default: “_” means whatever)

  • rev – OPTIONAL fetches a specific revision of a resource (default: None, fetches the last)

  • tag – OPTIONAL fetches the resource version that has a specific tag (default: None)

Returns

Payload of the whole resource as a dictionary

nexussdk.resources.list(org_label, project_label, pagination_from=0, pagination_size=20, deprecated=None, type=None, rev=None, schema=None, created_by=None, updated_by=None, resource_id=None)

List the resources available for a given organization and project.

Parameters
  • org_label – The label of the organization that the resource belongs to

  • project_label – The label of the project that the resource belongs to

  • schema – OPTIONAL Lists only the resource for a given schema (default: None)

  • pagination_from – OPTIONAL The pagination index to start from (default: 0)

  • pagination_size – OPTIONAL The maximum number of elements to returns at once (default: 20)

  • deprecated – OPTIONAL Get only deprecated resource if True and get only non-deprecated results if False. If not specified (default), return both deprecated and not deprecated resource.

  • type – OPTIONAL Lists only the resource for a given type (default: None)

  • rev – OPTIONAL List only the resource with this particular revision

  • created_by – OPTIONAL List only the resources created by a certain user

  • updated_by – OPTIONAL List only the resources that were updated by a certain user

  • resource_id – OPTIONAL List only the resources with this id. Relevant only when combined with other args

Returns

The raw payload as a dictionary

nexussdk.resources.tag(resource, tag_value, rev_to_tag=None, rev=None)

Add a tag to a a specific revision of the resource. Note that a new revision (untagged) will be created

Parameters
  • resource – payload of a previously fetched resource

  • tag_value – The value (or name) of a tag

  • rev_to_tag – OPTIONAL Number of the revision to tag. If not provided, this will take the revision number from the provided resource payload.

  • rev – OPTIONAL The previous revision you want to update from. If not provided, the rev from the resource argument will be used.

Returns

A payload containing only the Nexus metadata for this resource.

nexussdk.resources.tags(resource)

List all the tags added to this resource, along with their version numbers

Parameters

resource – payload of a previously fetched resource

Returns

payload containing the list of tags and versions

nexussdk.resources.update(resource, rev=None)

Update a resource. The resource object is most likely the returned value of a nexus.resource.fetch(), where some fields where modified, added or removed. Note that the returned payload only contains the Nexus metadata and not the complete resource.

Parameters
  • resource – payload of a previously fetched resource, with the modification to be updated

  • rev – OPTIONAL The previous revision you want to update from. If not provided, the rev from the resource argument will be used.

Returns

A payload containing only the Nexus metadata for this updated resource.