PyOxigraph

0.5.6 · active · verified Fri Apr 17

PyOxigraph provides Python bindings for Oxigraph, a high-performance SPARQL database and RDF toolkit implemented in Rust. It offers capabilities for parsing, storing, querying, and manipulating RDF data, including support for various RDF serialization formats and the SPARQL query language. The library is actively maintained with frequent releases, typically every few weeks, incorporating new features and performance improvements. Current version is 0.5.6.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to create a `Store`, add RDF `Triple`s using `NamedNode` and `Literal` terms, and then query the store using a simple SPARQL `SELECT` statement.

from pyoxigraph import Store, NamedNode, Literal, Triple

# Create an in-memory store
store = Store()

# Define some RDF terms
ex_s = NamedNode("http://example.com/subject")
ex_p = NamedNode("http://example.com/predicate")
ex_o = Literal("object value")

# Add a triple to the store
store.add(Triple(ex_s, ex_p, ex_o))

# Add another triple
store.add(Triple(NamedNode("http://example.com/another"), NamedNode("http://example.com/knows"), ex_s))

# Query the store using SPARQL
print("\n--- Query Results ---")
results = store.query("SELECT ?s ?p ?o WHERE { ?s ?p ?o }")
for s, p, o in results:
    print(f"Subject: {s}, Predicate: {p}, Object: {o}")

# Check if the store contains a specific triple
if store.contains(Triple(ex_s, ex_p, ex_o)):
    print(f"\nStore contains: {ex_s} {ex_p} {ex_o}")

view raw JSON →