nanopub.client

This module includes a client for the nanopub server.

class nanopub.client.NanopubClient(use_test_server=False)

Provides utility functions for searching, creating and publishing RDF graphs as assertions in a nanopublication.

Parameters

use_test_server (bool) – Toggle using the test nanopub server.

claim(statement_text: str)

Quickly claim a statement.

Constructs statement triples around the provided text following the Hypotheses and Claims Ontology (http://purl.org/petapico/o/hycl).

Parameters

statement_text (str) – the text of the statement, example: ‘All cats are grey’

Returns

Publication info with: ‘nanopub_uri’: the URI of the published nanopublication, ‘concept_uri’: the URI of the introduced concept (if applicable)

Return type

dict of str

fetch(uri: str)

Fetch nanopublication

Download the nanopublication at the specified URI.

Parameters

uri (str) – The URI of the nanopublication to fetch.

Returns

a Publication object representing the nanopublication.

Return type

Publication

find_nanopubs_with_pattern(subj: Optional[str] = None, pred: Optional[str] = None, obj: Optional[str] = None, filter_retracted: bool = True, pubkey: Optional[str] = None)

Pattern search.

Search the nanopub servers for any nanopubs matching the given RDF pattern. You can leave parts of the triple to match anything by not specifying subj, pred, or obj arguments.

Parameters
  • subj (str) – URI of the subject that you want to match triples on.

  • pred (str) – URI of the predicate that you want to match triples on.

  • obj (str) – URI of the object that you want to match triples on.

  • pubkey (str) – Public key that the matching nanopubs should be signed with

  • filter_retracted (bool) – Toggle filtering for publications that are retracted. Default is True, returning only publications that are not retracted.

Yields

dicts depicting matching nanopublications. Each dict holds: ‘np’: the nanopublication uri, ‘date’: date of creation of the nanopublication, ‘description’: A description of the nanopublication (if found in RDF).

find_nanopubs_with_text(text: str, pubkey: Optional[str] = None, filter_retracted: bool = True)

Text search.

Search the nanopub servers for any nanopubs matching the given search text.

Parameters
  • text (str) – The text to search on

  • pubkey (str) – Public key that the matching nanopubs should be signed with

  • filter_retracted (bool) – Toggle filtering for publications that are retracted. Default is True, returning only publications that are not retracted.

Yields

dicts depicting matching nanopublications. Each dict holds: ‘np’: the nanopublication uri, ‘date’: date of creation of the nanopublication, ‘description’: A description of the nanopublication (if found in RDF).

find_retractions_of(source: Union[str, nanopub.publication.Publication], valid_only=True) List[str]

Find retractions of given URI

Find all nanopublications that retract a certain nanopublication.

Parameters
  • source (str or nanopub.Publication) – URI or Publication object to find retractions for

  • valid_only (bool) – Toggle returning only valid retractions, i.e. retractions that are signed with the same public key as the publication they retract. Default is True.

Returns

List of uris that retract the given URI

find_things(type: str, searchterm: str = ' ', pubkey: Optional[str] = None, filter_retracted: bool = True)

Search things (experimental).

Search for any nanopublications that introduce a concept of the given type, that contain text with the given search term.

Parameters
  • type (str) – A URI denoting the type of the introduced concept

  • searchterm (str) – The term that you want to search on

  • pubkey (str) – Public key that the matching nanopubs should be signed with

  • filter_retracted (bool) – Toggle filtering for publications that are retracted. Default is True, returning only publications that are not retracted.

Yields

dicts depicting matching nanopublications. Each dict holds: ‘np’: the nanopublication uri, ‘date’: date of creation of the nanopublication, ‘description’: A description of the nanopublication (if found in RDF).

publish(publication: nanopub.publication.Publication)

Publish a Publication object.

Publish Publication object to the nanopub server. It uses nanopub_java commandline tool to sign the nanopublication RDF with the RSA key in the profile and then publish.

Parameters

publication (Publication) – Publication object to publish.

Returns

Publication info with: ‘nanopub_uri’: the URI of the published nanopublication, ‘concept_uri’: the URI of the introduced concept (if applicable)

Return type

dict of str

retract(uri: str, force=False)

Retract a nanopublication.

Publish a retraction nanpublication that declares retraction of the nanopublication that corresponds to the ‘uri’ argument.

Parameters
  • uri (str) – The uri pointing to the to-be-retracted nanopublication

  • force (bool) – Toggle using force to retract, this will even retract the nanopublication if it is signed with a different public key than the one in the user profile.

Returns

Publication info with: ‘nanopub_uri’: the URI of the published nanopublication, ‘concept_uri’: the URI of the introduced concept (if applicable)

Return type

dict of str