Skip to main content

Python bindings for using the RDF graph database Tentris RDF rdflib

Project description

Running Tentris Using Python

Requirements

  • Python>=3.12
  • rdflib>=7
  • glibc>=2.34 (e.g. ubuntu-22.04 or later)

Note: Connecting to local/remote Tentris instances via HTTP is supported on all plattforms. Running Tentris within python is only supported on Linux.

Install

pip install tentris

or edit your requirements.txt as follows.

# ... your other dependencies
tentris

Getting Started

The Tentris Python library is a plugin for rdflib.

Native (Linux only)

With the native TentrisStore, Tentris is embedded in Python applications.

import tentris
import rdflib

# Create an RDFLib graph using Tentris as its backend
graph = rdflib.Graph(store="Tentris")

# Load the graph using the SPARQL Update operation `LOAD`
# https://www.w3.org/TR/2013/REC-sparql11-update-20130321/#load 
graph.update("LOAD <https://files.tentris.io/mona-lisa.ttl>")

# Query the Mona Lisa knowledge graph
query_str = """
   PREFIX foaf: <http://xmlns.com/foaf/0.1/>
   PREFIX dbr: <http://dbpedia.org/resource/>
   PREFIX dbo: <http://dbpedia.org/ontology/>

   SELECT ?name WHERE {
      dbr:Mona_Lisa dbo:author ?person .
      ?person foaf:name ?name .
   }
"""

for binding in graph.query(query_str):
   print(f"{binding.name.n3()}")

The TentrisStore operates in-memory and does not persist data in the disk. To use a disk-based instance of Tentris, the HTTP-based store should be used.

HTTP (Any Operating System)

Remote or local instances of Tentris can be queries using the HTTP-based TentrisHTTPStore.

Local

Assuming a Tentris server is running on the localhost listening to the default port, it can be queried as shown in the example below.

import tentris
import rdflib

graph = rdflib.Graph(store="TentrisHTTP")

for binding in graph.query("SELECT * WHERE { ?s ?p ?o } LIMIT 10"):
    print(f"{binding.s.n3()} {binding.p.n3()} {binding.o.n3()}")

Remote

To query remote instances of Tentris, the URL needs to be explicitly stated.

from tentris import TentrisHTTPStore
import rdflib

graph = rdflib.Graph(store=TentrisHTTPStore("https://dbpedia.data.dice-research.org"))

for binding in graph.query("SELECT * WHERE { ?s ?p ?o } LIMIT 10"):
    print(f"{binding.s.n3()} {binding.p.n3()} {binding.o.n3()}")

For more information about setting up a disk-based instance of Tentris, please refer to the chapter Binary.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

tentris-0.19.12b0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

tentris-0.19.12b0-cp312-abi3-manylinux_2_34_x86_64.whl (10.4 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.34+ x86-64

File details

Details for the file tentris-0.19.12b0-py3-none-any.whl.

File metadata

  • Download URL: tentris-0.19.12b0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tentris-0.19.12b0-py3-none-any.whl
Algorithm Hash digest
SHA256 c386e64f833fb01762db56458740ed63c7cf0ec9d7fdbed3b24cb7a03a7cd7d6
MD5 4f0909c0f0e51a30ee260bb07167855f
BLAKE2b-256 34a4aeefdbf29cec00bc975b9fe857f6ea52e2d803ad6895cf8a593fcc1b7195

See more details on using hashes here.

File details

Details for the file tentris-0.19.12b0-cp312-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for tentris-0.19.12b0-cp312-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 26d03cf99bdb812723df7f5e10f7cd2eeb347360e04387875c1ad2b65e60b013
MD5 afc63ec435b651c59fc3d35b0a6666e2
BLAKE2b-256 06c4ed79fab8abc042d0342025911dd2e55ec511b6e78b9b337cfca2a21471ed

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