Skip to main content

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.

Metadata

Release files for nanopub 2.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nanopub 2.3.0
File Size Uploaded Provenance Actions
nanopub-2.3.0.tar.gz 1.0 MB Without provenance Details for nanopub-2.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nanopub 2.3.0
File Interpreter ABI Platform Actions
nanopub-2.3.0-py3-none-any.whl Python 3 none any Details for nanopub-2.3.0-py3-none-any.whl

Total release size: 1.1 MB

Release files / nanopub-2.3.0.tar.gz

Download URL nanopub-2.3.0.tar.gz
Size 1.0 MB
Tags Source
SHA-256 checksum
How to use checksums
97a3c3a0b6ab4997e5d0886288c5430a0b6aeba197767186c437da0eef422dcd
BLAKE2b-256 checksum
How to use checksums
c783353937f32c7c86186ffce9a05d50d2d0eab0c1f90ff2356477ac4bd236bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / nanopub-2.3.0-py3-none-any.whl

Download URL nanopub-2.3.0-py3-none-any.whl
Size 71.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61830bae0fc24eff1242cef323b8f5c7ad6be14a30fb2823e0ec498dfea37c15
BLAKE2b-256 checksum
How to use checksums
ca5013dc7f4bec0f06409898f08e4d48196bc068a3773d9697a13e91fa91ff42
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for nanopub 2.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.3.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page