Skip to main content

Python client for Nanopub

Project description

Build Status Documentation Status Coverage Status PyPI version CII Best Practices fair-software.eu DOI

nanopub

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

Nanopublications are a formalized and machine-readable way of communicating the smallest possible units of publishable information. See the documentation for more information.

Documentation

Checkout the user documentation

Setup

Install using pip:

pip install nanopub

To publish to the nanopub server you need to setup your profile. This allows the nanopub server to identify you. Run the following command in the terminal:

setup_nanopub_profile

This will ask you a few questions, then it will use that information to add and store RSA keys to sign your nanopublications with, (optionally) publish a nanopublication with your name and ORCID iD to declare that you are using using these RSA keys, and store your ORCID iD to automatically add as author to the provenance of any nanopublication you will publish using this library.

Quick Start

Publishing nanopublications

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

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

# Either quickly publish a statement to the server
client.claim('All cats are gray')

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

# 2. Make a Publication object with this assertion
publication = Publication.from_assertion(assertion_rdf=my_assertion)

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

Searching for nanopublications

from nanopub import NanopubClient

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

Fetching nanopublications and inspecting them

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

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

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

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 Distribution

nanopub-1.2.8.tar.gz (9.6 MB view details)

Uploaded Source

Built Distribution

nanopub-1.2.8-py3-none-any.whl (9.6 MB view details)

Uploaded Python 3

File details

Details for the file nanopub-1.2.8.tar.gz.

File metadata

  • Download URL: nanopub-1.2.8.tar.gz
  • Upload date:
  • Size: 9.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for nanopub-1.2.8.tar.gz
Algorithm Hash digest
SHA256 d264584c8b943fe96e7dcfc1442521b674ffe40291a8cd42363a932ba06b0801
MD5 281bf8e2de13d2fdb8964d9b58ce1dfe
BLAKE2b-256 86c18e90d89ddfd3aa15320f81f07d7607a6e8ca9a80c5a66c5bcb9e70bd616b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nanopub-1.2.8-py3-none-any.whl
  • Upload date:
  • Size: 9.6 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for nanopub-1.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 bfe4472e10b880c6e8a0189ef6d2310a6f296036ca2e2b930c4748d79503b812
MD5 c050c508fe44d17630e33818f2e49bf2
BLAKE2b-256 88eefe70f9ffe8afb8fb4b3a63d9690451cbd57c6484a9aac57b5e9e4d47c18b

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