Skip to main content

Python client for Nanopub

Project description

Build Status Coverage Status PyPI version fair-software.eu

nanopub

The nanopub library provides a high-level, user-friendly python interface for searching, publishing and retracting nanopublications.

Setup

Install using pip:

pip install nanopub

To publish to the nanopub server you need to setup RSA keys. This allows the nanopub server to identify you.

make_nanopub_keys

Quick Start

Publishing an assertion as a nanopub

from nanopub import Nanopub, NanopubClient
from rdflib import Graph, URIRef, RDF, FOAF

# Create the client, that allows searching, fetching and publishing nanopubs
client = NanopubClient()

# Construct your desired assertion (a graph of RDF triples)
my_assertion = Graph()
my_assertion.add( (URIRef('www.example.org/timbernerslee'), RDF.type, FOAF.Person) )

# Make a Nanopub object with this assertion
nanopub = Nanopub.from_assertion(assertion_rdf=my_assertion)

# Publish the Nanopub object. The URI at which it is published is returned.
publication_info = client.publish(nanopub)
print(publication_info)

Searching for nanopublications

from nanopub import NanopubClient

# Search for all nanopublications containing the text 'fair'
results = client.search_text('fair')
print(results)

# Search for nanopublications whose assertions contain triples that are ```rdf:Statement```s.
# Return only the first three results.
results = client.search_pattern(
                pred='http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
                obj='http://www.w3.org/1999/02/22-rdf-syntax-ns#Statement',
                max_num_results=3)
print(results)

# Search for nanopublications that introduce a concept that is a ```p-plan:Step```.
# Return only one result.
results = client.search_things('http://purl.org/net/p-plan#Step', max_num_results=1)
print(results)

Fetching nanopublications and inspecting them

# Fetch the nanopublication at the specified URI
np = client.fetch('http://purl.org/np/RApJG4fwj0szOMBMiYGmYvd5MCtRle6VbwkMJUb1SxxDM')

# Print the RDF contents of the nanopublication
print(np)

# Iterate through all triples in the assertion graph
for s, p, o in np.assertion:
    print(s, p, o)

# Iterate through the publication info
for s, p, o in np.pubinfo:
    print(s, p, o)

# Iterate through the provenance graph
for s, p, o in np.provenance:
    print(s,p,o)

# See the concept that is introduced by this nanopublication (if any)
print(np.introduces_concept)

Specifying more information

You can optionally specify that the Nanopub introduces a particular concept, or is derived from another nanopublication:

nanopub = Nanopub.from_assertion(assertion_rdf=my_assertion,
                                 introduces_concept=(URIRef('www.example.org/timbernerslee'),
                                 derived_from=URIRef('www.example.org/another-nanopublication') )

Dependencies

The nanopub library currently uses the nanopub-java tool for signing and publishing new nanopublications. This is automatically installed by the library.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

nanopub-0.2.5-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file nanopub-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: nanopub-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for nanopub-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 bf471b0902cad0e6a5f1b44c434ed6ed88ed298beb7f8a3f94b0f36a95b7e881
MD5 b6596767f251d423e7f1d864c715cb7a
BLAKE2b-256 9fbc5b76b9b3074179df4328f126656660748e920cf6de582d9b65f4f400078d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page