Python client for Nanopublications
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 command in the terminal:
np setup
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 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 rdflib import Graph
from nanopub import Nanopub, NanopubConf, load_profile
# 1. Create the config
np_conf = NanopubConf(
use_test_server=True,
profile=load_profile(), # Loads the user profile that was created with `np setup`
add_prov_generated_time=True,
attribute_publication_to_profile=True,
)
# 2. Construct a desired assertion (a graph of RDF triples) using rdflib
my_assertion = Graph()
my_assertion.add((
rdflib.URIRef('www.example.org/timbernerslee'),
rdflib.RDF.type,
rdflib.FOAF.Person
))
# 2. Make a Nanopub object with this assertion
np = Nanopub(
conf=np_conf,
assertion=my_assertion
)
# 3. Publish the Nanopub object
np.publish()
print(np)
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)
Development
See the development page on the documentation website.
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 Distribution
Built Distribution
File details
Details for the file nanopub-2.0.0.tar.gz
.
File metadata
- Download URL: nanopub-2.0.0.tar.gz
- Upload date:
- Size: 854.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cef83853e85a8f349243be5c6022e23a9b9882bb295e6fb5e43047013b6f7f97 |
|
MD5 | 86f7593c31bf3b6a08eb0220cf077e0f |
|
BLAKE2b-256 | 38eaee044374ccf8d069018ef96f93583939b9fc82c918d30eb4bea70ccd679b |
File details
Details for the file nanopub-2.0.0-py3-none-any.whl
.
File metadata
- Download URL: nanopub-2.0.0-py3-none-any.whl
- Upload date:
- Size: 46.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40bc0c8f22bb3185f318689735eeaf8bfdf7fe3f38d0a4c15b91087474fa4410 |
|
MD5 | 45987339824d0e98b2868d1ad1f4f9c8 |
|
BLAKE2b-256 | 9bca62e36cf4a3ee1d5aeb8604a4a4b53b08ee4831510e33ab24dda73ac15393 |