Python client for Nanopub
Project description
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 interactive command:
setup_nanopub_profile
It will add and store RSA keys to sign your nanopublications, 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file nanopub-1.2.3-py3-none-any.whl
.
File metadata
- Download URL: nanopub-1.2.3-py3-none-any.whl
- Upload date:
- Size: 9.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 561d6da97814c9580965964ad605d6ed22294157fe16dbe094d5ef3504c68887 |
|
MD5 | 7a386c3974678b190d32ab0437b3587a |
|
BLAKE2b-256 | c199ea580c1eb44c05424984411c314fdbd49348db32ffaef98f417426a58812 |