Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
b56194f
feat: add RDF4JClient, RepositoryManager, and initial Repository impl…
edmondchuc Oct 28, 2025
42708bd
test: add test for repo listing format error and repo not healthy error
edmondchuc Oct 30, 2025
562bd1d
chore: add testcontainers comment
edmondchuc Oct 31, 2025
4c37989
Merge branch '7.x' into v7/feat/rdf4j
edmondchuc Oct 31, 2025
00164e1
docs: add google style docstring for mkdocs
edmondchuc Oct 31, 2025
6c0520e
test: add rdf4j client test
edmondchuc Oct 31, 2025
b3242f1
chore: add todo to only run rdf4j tests on python 3.9 or greater
edmondchuc Oct 31, 2025
bae5560
chore: add todo to only run rdf4j tests on python 3.9 or greater
edmondchuc Oct 31, 2025
a5b71b2
refactor: organise rdf4j package into rdflib.contrib
edmondchuc Oct 31, 2025
8cf0178
feat: add http_client property
edmondchuc Oct 31, 2025
e81322a
feat: bootstrap a minimal graphdb client
edmondchuc Oct 31, 2025
6d744ce
chore: remove unused rdf4j testcontainer
edmondchuc Oct 31, 2025
f52473e
chore: add testcontainer pytest marker, refactor rdf4j test structure…
edmondchuc Nov 2, 2025
b550323
test: rearrange unit tests
edmondchuc Nov 3, 2025
cc1840c
feat: Repository get method
edmondchuc Nov 3, 2025
ced7451
feat: Repository delete method
edmondchuc Nov 3, 2025
ce4af99
feat: Repository size method
edmondchuc Nov 3, 2025
d925815
test: add e2e tests for the new Repository methods
edmondchuc Nov 3, 2025
a7ec08f
feat: add Repository upload and graphs method
edmondchuc Nov 4, 2025
39f1adc
test: fix up and improve existing tests
edmondchuc Nov 4, 2025
d5182ac
test: add tests for Repository.graphs
edmondchuc Nov 4, 2025
3282124
chore: add docstring to overwrite and upload methods
edmondchuc Nov 4, 2025
c44058e
feat: defer repository manager creation until accessed, and also amen…
edmondchuc Nov 4, 2025
73ed890
feat: add RDF4J NamespaceManager
edmondchuc Nov 4, 2025
fca2b99
chore: fix mypy issues
edmondchuc Nov 4, 2025
0c89e59
test: add e2e tests for RDF4J Repository NamespaceManager
edmondchuc Nov 4, 2025
b51f4f3
chore: doc improvements
edmondchuc Nov 4, 2025
c7a05c8
feat: the repository's namespace prefixes are now bound to the return…
edmondchuc Nov 4, 2025
b9596c2
feat: add Repository GraphStoreManager
edmondchuc Nov 5, 2025
39b83d8
test: add e2e test for Repository GraphStoreManager
edmondchuc Nov 5, 2025
b84c498
chore: remove redundant re-raise of httpx exceptions
edmondchuc Nov 5, 2025
fb464e4
docs: add docstring to protocol method
edmondchuc Nov 5, 2025
28bf65f
style: formatting
edmondchuc Nov 5, 2025
8efe9d0
feat: add Repository.query method
edmondchuc Nov 6, 2025
aadee52
feat: add Repository.update method
edmondchuc Nov 6, 2025
4c39a79
feat: add Repository Transaction with ping and commit
edmondchuc Nov 6, 2025
323f303
refactor: prep Repository.size method to be used by transactions as well
edmondchuc Nov 6, 2025
4920a3e
test: refactor e2e test file names to avoid clash
edmondchuc Nov 6, 2025
e1de8e4
test: fix test
edmondchuc Nov 6, 2025
96375cc
Revert "refactor: prep Repository.size method to be used by transacti…
edmondchuc Nov 6, 2025
f472b30
test: fix test
edmondchuc Nov 6, 2025
578f0cf
feat: Add Transaction.size method
edmondchuc Nov 6, 2025
af504f9
feat: Add Transaction rollback, add, and query methods
edmondchuc Nov 6, 2025
c7d6600
feat: Add Transaction delete, and also Transaction upload test
edmondchuc Nov 6, 2025
2e45622
feat: Add Transaction update
edmondchuc Nov 6, 2025
0a680fb
feat: Add Transaction get
edmondchuc Nov 6, 2025
c67f7c2
test: update transaction tests for upload and delete
edmondchuc Nov 7, 2025
c56a5b6
fix: improve error handling
edmondchuc Nov 7, 2025
fc15b97
feat: dynamically import httpx by checking its existence with find_sp…
edmondchuc Nov 7, 2025
dd7f3e4
Merge branch '7.x' into v7/feat/rdf4j
edmondchuc Nov 7, 2025
40f86ac
test: put httpx import behind has_httpx condition
edmondchuc Nov 7, 2025
fefbb06
test: fix test annotations
edmondchuc Nov 7, 2025
1faa1e3
fix: add conditional import for GraphDBClient
edmondchuc Nov 7, 2025
89171df
test: ignore rdf4j and graphdb client.py for docstring tests
edmondchuc Nov 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,11 @@ tasks:
sys.stderr.write(f"removing {path}\n")
shutil.rmtree(path, ignore_errors=True)
' {{.RIMRAF_TARGET}}

test:rdf4j:
desc: Run fast tests against rdflib.contrib.rdf4j package
cmd: '{{.TEST_HARNESS}}{{.RUN_PREFIX}} pytest -m "not (testcontainer or webtest)" test/test_rdf4j'

test:rdf4j:all:
desc: Run all tests against rdflib.contrib.rdf4j package
cmd: '{{.TEST_HARNESS}}{{.RUN_PREFIX}} pytest test/test_rdf4j'
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ nav:
- Container: apidocs/rdflib.container.md
- Collection: apidocs/rdflib.collection.md
- Paths: apidocs/rdflib.paths.md
- RDF4J: apidocs/rdflib.contrib.rdf4j.md
- Util: apidocs/rdflib.util.md
- Plugins:
- Parsers: apidocs/rdflib.plugins.parsers.md
Expand Down
1,091 changes: 733 additions & 358 deletions poetry.lock

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ rdfs2dot = 'rdflib.tools.rdfs2dot:main'
rdfgraphisomorphism = 'rdflib.tools.graphisomorphism:main'

[tool.poetry.dependencies]
python = ">=3.8.1"
# TODO: temporarily add new python version constraints for testcontainers
# We can remove the upper bound once testcontainers releases a new version
# https://github.com/testcontainers/testcontainers-python/pull/909
python = ">=3.9.2, <4.0"
isodate = {version=">=0.7.2,<1.0.0", python = "<3.11"}
pyparsing = ">=2.1.0,<4"
berkeleydb = {version = "^18.1.0", optional = true}
networkx = {version = ">=2,<4", optional = true}
html5rdf = {version = ">=1.2,<2", optional = true}
lxml = {version = ">=4.3,<6.0", optional = true}
orjson = {version = ">=3.9.14,<4", optional = true}
httpx = {version = "^0.28.1", optional = true}

[tool.poetry.group.dev.dependencies]
black = "24.8.0"
Expand All @@ -63,6 +67,7 @@ coverage = {version = "^7.0.1", extras = ["toml"]}
types-setuptools = ">=68.0.0.3,<72.0.0.0"
setuptools = ">=68,<72"
wheel = ">=0.42,<0.46"
testcontainers = "^4.13.2"

[tool.poetry.group.docs.dependencies]
typing-extensions = "^4.11.0"
Expand All @@ -85,6 +90,7 @@ html = ["html5rdf"]
# lxml support is optional, it is used only for parsing XML-formatted SPARQL results
lxml = ["lxml"]
orjson = ["orjson"]
rdf4j = ["httpx"]

[build-system]
requires = ["poetry-core>=1.4.0"]
Expand Down Expand Up @@ -207,6 +213,8 @@ addopts = [
"--ignore=admin",
"--ignore=devtools",
"--ignore=rdflib/extras/external_graph_libs.py",
"--ignore=rdflib/contrib/graphdb/client.py",
"--ignore=rdflib/contrib/rdf4j/client.py",
"--ignore-glob=docs/*.py",
"--ignore-glob=site/*",
"--strict-markers",
Expand All @@ -218,6 +226,7 @@ filterwarnings = [
"ignore:Code. _pytestfixturefunction is not defined in namespace .*:UserWarning",
]
markers = [
"testcontainer: mark a test that uses testcontainer",
"webtest: mark a test as using the internet",
]
# log_cli = true
Expand Down
Empty file added rdflib/contrib/__init__.py
Empty file.
6 changes: 6 additions & 0 deletions rdflib/contrib/graphdb/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from rdflib.contrib.rdf4j import has_httpx

if has_httpx:
from .client import GraphDBClient

__all__ = ["GraphDBClient"]
61 changes: 61 additions & 0 deletions rdflib/contrib/graphdb/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import httpx

import rdflib.contrib.rdf4j
from rdflib.contrib.rdf4j import RDF4JClient
from rdflib.contrib.rdf4j.exceptions import (
RepositoryNotFoundError,
RepositoryNotHealthyError,
)


class Repository(rdflib.contrib.rdf4j.client.Repository):
"""GraphDB Repository"""

def health(self, timeout: int = 5) -> bool:
"""Repository health check.

Parameters:
timeout: A timeout parameter in seconds. If provided, the endpoint attempts
to retrieve the repository within this timeout. If not, the passive
check is performed.

Returns:
bool: True if the repository is healthy, otherwise an error is raised.

Raises:
RepositoryNotFoundError: If the repository is not found.
RepositoryNotHealthyError: If the repository is not healthy.
httpx.RequestError: On network/connection issues.
httpx.HTTPStatusError: Unhandled status code error.
"""
try:
params = {"passive": str(timeout)}
response = self.http_client.get(
f"/repositories/{self.identifier}/health", params=params
)
response.raise_for_status()
return True
except httpx.HTTPStatusError as err:
if err.response.status_code == 404:
raise RepositoryNotFoundError(
f"Repository {self._identifier} not found."
)
raise RepositoryNotHealthyError(
f"Repository {self._identifier} is not healthy. {err.response.status_code} - {err.response.text}"
)
except httpx.RequestError:
raise


class RepositoryManager(rdflib.contrib.rdf4j.client.RepositoryManager):
"""GraphDB Repository Manager"""

def get(self, repository_id: str) -> Repository:
_repo = super().get(repository_id)
return Repository(_repo.identifier, _repo.http_client)


class GraphDBClient(RDF4JClient):
"""GraphDB Client"""

# TODO: GraphDB specific API methods.
10 changes: 10 additions & 0 deletions rdflib/contrib/rdf4j/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from importlib.util import find_spec

has_httpx = find_spec("httpx") is not None

if has_httpx:
from .client import RDF4JClient

__all__ = ["RDF4JClient", "has_httpx"]
else:
__all__ = ["has_httpx"]
Loading
Loading