Skip to main content

Python client for Nanopublications

Project description

nanopub Tests and update docs Publish to PyPI 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:

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


Download files

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

Source Distribution

nanopub-2.0.0.tar.gz (854.1 kB view details)

Uploaded Source

Built Distribution

nanopub-2.0.0-py3-none-any.whl (46.8 kB view details)

Uploaded Python 3

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

Hashes for nanopub-2.0.0.tar.gz
Algorithm Hash digest
SHA256 cef83853e85a8f349243be5c6022e23a9b9882bb295e6fb5e43047013b6f7f97
MD5 86f7593c31bf3b6a08eb0220cf077e0f
BLAKE2b-256 38eaee044374ccf8d069018ef96f93583939b9fc82c918d30eb4bea70ccd679b

See more details on using hashes here.

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

Hashes for nanopub-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40bc0c8f22bb3185f318689735eeaf8bfdf7fe3f38d0a4c15b91087474fa4410
MD5 45987339824d0e98b2868d1ad1f4f9c8
BLAKE2b-256 9bca62e36cf4a3ee1d5aeb8604a4a4b53b08ee4831510e33ab24dda73ac15393

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