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.1.tar.gz
.
File metadata
- Download URL: nanopub-2.0.1.tar.gz
- Upload date:
- Size: 856.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7adbec71f91dfa92d1d676842b22b32cf967784f2cfafd5cbe0c23511ddb802 |
|
MD5 | 68dee627d701586a20a529c0da9e53eb |
|
BLAKE2b-256 | a2fb29a1366f8b62a88fed76115f20e1fb761417a507a17d7a1a9558c85fceb8 |
File details
Details for the file nanopub-2.0.1-py3-none-any.whl
.
File metadata
- Download URL: nanopub-2.0.1-py3-none-any.whl
- Upload date:
- Size: 47.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75c215825e64ae655438bf1b839d8859bfe94d5bad666d189b8f2d3176b5500d |
|
MD5 | cdc2b9c160eb3c726b15d0221fa31273 |
|
BLAKE2b-256 | 9fae81d5e8b28e440ed5f83052d6ff0c0698e4740e23e354be54d58b0aed9515 |