Skip to main content

Python client for Nanopublications

Project description

nanopub Tests Coverage Status PyPI version CII Best Practices fair-software.eu DOI semantic-release: angular

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 nanopublication network you need to set up your profile. This allows the nanopublication services 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'
client = NanopubClient()
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.

Tests

To run tests:

Install dependencies (if not already installed):

uv sync

Run tests:

uv run pytest

Test coverage

Run the tests with coverage tracking:

uv run pytest --cov

View a terminal summary:

uv run coverage report

Or generate a detailed HTML report

uv run coverage html

License

nanopub is free software under the Apache License. See LICENSE.

Copyright

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.2.1.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nanopub-2.2.1-py3-none-any.whl (59.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nanopub-2.2.1.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for nanopub-2.2.1.tar.gz
Algorithm Hash digest
SHA256 4ac012978f06588b18c668a9516ff4a2ccbf1ab853da9a94653f1404fcb382eb
MD5 ad75dcaf666b6e55299163df28d43604
BLAKE2b-256 a92f400b3b64a0f67045d8dfaa6dbe14f6082be2eebbfff8db5f3afab52cc7a5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nanopub-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 59.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for nanopub-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e26f280b319c424bcec8c219d67a97b9e06977ddec12e0f1c095ccf7967cd9e
MD5 63ffa530864ac8ecf979aaeedf42ff59
BLAKE2b-256 bf75e352df801e162547313d832d7288523ce72de594dd39e4f98d34fa9de049

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page