rdf4j-python 0.1.1a0__py3-none-any.whl → 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rdf4j_python/__init__.py +9 -4
- rdf4j_python/_client/_client.py +156 -5
- rdf4j_python/_driver/__init__.py +2 -0
- rdf4j_python/_driver/_async_named_graph.py +76 -0
- rdf4j_python/_driver/_async_rdf4j_db.py +60 -34
- rdf4j_python/_driver/_async_repository.py +307 -25
- rdf4j_python/exception/__init__.py +5 -0
- rdf4j_python/exception/repo_exception.py +26 -5
- rdf4j_python/model/__init__.py +5 -10
- rdf4j_python/model/_namespace.py +115 -14
- rdf4j_python/model/_repository_info.py +36 -15
- rdf4j_python/model/{_repository_config.py → repository_config.py} +671 -70
- rdf4j_python/model/term.py +20 -0
- rdf4j_python/model/vocabulary.py +7 -0
- rdf4j_python/utils/__init__.py +3 -0
- rdf4j_python/utils/const.py +4 -4
- rdf4j_python/utils/helpers.py +20 -0
- {rdf4j_python-0.1.1a0.dist-info → rdf4j_python-0.1.3.dist-info}/METADATA +13 -13
- rdf4j_python-0.1.3.dist-info/RECORD +23 -0
- {rdf4j_python-0.1.1a0.dist-info → rdf4j_python-0.1.3.dist-info}/WHEEL +1 -1
- rdf4j_python/model/_base_model.py +0 -26
- rdf4j_python-0.1.1a0.dist-info/RECORD +0 -19
- {rdf4j_python-0.1.1a0.dist-info → rdf4j_python-0.1.3.dist-info}/licenses/LICENSE +0 -0
- {rdf4j_python-0.1.1a0.dist-info → rdf4j_python-0.1.3.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from typing import TypeAlias
|
|
2
|
+
|
|
3
|
+
import pyoxigraph as og
|
|
4
|
+
|
|
5
|
+
IRI: TypeAlias = og.NamedNode
|
|
6
|
+
BlankNode: TypeAlias = og.BlankNode
|
|
7
|
+
Literal: TypeAlias = og.Literal
|
|
8
|
+
DefaultGraph: TypeAlias = og.DefaultGraph
|
|
9
|
+
Variable: TypeAlias = og.Variable
|
|
10
|
+
|
|
11
|
+
Quad: TypeAlias = og.Quad
|
|
12
|
+
Triple: TypeAlias = og.Triple
|
|
13
|
+
|
|
14
|
+
Subject: TypeAlias = IRI | BlankNode | Triple
|
|
15
|
+
Predicate: TypeAlias = IRI
|
|
16
|
+
Object: TypeAlias = IRI | BlankNode | Literal
|
|
17
|
+
Context: TypeAlias = IRI | BlankNode | DefaultGraph | None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
QuadResultSet: TypeAlias = og.QuadParser
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
from rdf4j_python.model import Namespace
|
|
2
|
+
|
|
3
|
+
# Common namespaces
|
|
4
|
+
RDF = Namespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#")
|
|
5
|
+
RDFS = Namespace("rdfs", "http://www.w3.org/2000/01/rdf-schema#")
|
|
6
|
+
EXAMPLE = Namespace("ex", "http://example.org/")
|
|
7
|
+
XSD = Namespace("xsd", "http://www.w3.org/2001/XMLSchema#")
|
rdf4j_python/utils/__init__.py
CHANGED
rdf4j_python/utils/const.py
CHANGED
|
@@ -12,11 +12,11 @@ class Rdf4jContentType(str, Enum):
|
|
|
12
12
|
RDF_XML = "application/rdf+xml"
|
|
13
13
|
RDF_JSON = "application/rdf+json"
|
|
14
14
|
LD_JSON = "application/ld+json"
|
|
15
|
-
NTRIPLES = "
|
|
15
|
+
NTRIPLES = "application/n-triples"
|
|
16
16
|
TURTLE = "text/turtle"
|
|
17
|
-
N3 = "text/
|
|
18
|
-
NQUADS = "
|
|
19
|
-
TRIG = "application/
|
|
17
|
+
N3 = "text/n3"
|
|
18
|
+
NQUADS = "application/n-quads"
|
|
19
|
+
TRIG = "application/trig"
|
|
20
20
|
TRIX = "application/trix"
|
|
21
21
|
BINARY_RDF = "application/x-binary-rdf"
|
|
22
22
|
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from io import BytesIO
|
|
2
|
+
from typing import Iterable
|
|
3
|
+
|
|
4
|
+
import pyoxigraph as og
|
|
5
|
+
|
|
6
|
+
from rdf4j_python.model.term import Quad, Triple
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def serialize_statements(statements: Iterable[Quad] | Iterable[Triple]) -> bytes:
|
|
10
|
+
"""Serializes statements to RDF data.
|
|
11
|
+
|
|
12
|
+
Args:
|
|
13
|
+
statements (Iterable[Quad] | Iterable[Triple]): RDF statements.
|
|
14
|
+
|
|
15
|
+
Returns:
|
|
16
|
+
bytes: Serialized RDF data.
|
|
17
|
+
"""
|
|
18
|
+
io = BytesIO()
|
|
19
|
+
og.serialize(statements, output=io, format=og.RdfFormat.N_QUADS)
|
|
20
|
+
return io.getvalue()
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rdf4j-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: The Python client for RDF4J
|
|
5
|
+
Author-email: Chengxu Bian <cbian564@gmail.com>
|
|
5
6
|
Requires-Python: >=3.10
|
|
6
7
|
Description-Content-Type: text/markdown
|
|
7
8
|
License-File: LICENSE
|
|
8
9
|
Requires-Dist: httpx>=0.28.1
|
|
9
|
-
Requires-Dist:
|
|
10
|
+
Requires-Dist: pyoxigraph>=0.4.10
|
|
10
11
|
Dynamic: license-file
|
|
11
12
|
|
|
12
13
|
# 🐍 rdf4j-python
|
|
@@ -42,24 +43,23 @@ pip install rdf4j-python
|
|
|
42
43
|
Here's a basic example of how to use `rdf4j-python` to create an in-memory sail repository
|
|
43
44
|
|
|
44
45
|
```python
|
|
45
|
-
from rdf4j_python import AsyncRdf4j
|
|
46
|
-
from rdf4j_python.model import MemoryStoreConfig, RepositoryConfig
|
|
47
|
-
from rdf4j_python.utils.const import Rdf4jContentType
|
|
48
|
-
|
|
49
46
|
async with AsyncRdf4j("http://localhost:19780/rdf4j-server") as db:
|
|
50
47
|
repo_config = (
|
|
51
|
-
RepositoryConfig.
|
|
52
|
-
MemoryStoreConfig.Builder().persist(False).build(),
|
|
53
|
-
)
|
|
48
|
+
RepositoryConfig.Builder()
|
|
54
49
|
.repo_id("example-repo")
|
|
55
50
|
.title("Example Repository")
|
|
51
|
+
.sail_repository_impl(
|
|
52
|
+
MemoryStoreConfig.Builder().persist(False).build(),
|
|
53
|
+
)
|
|
56
54
|
.build()
|
|
57
55
|
)
|
|
58
|
-
await db.create_repository(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
repo = await db.create_repository(config=repo_config)
|
|
57
|
+
await repo.add_statement(
|
|
58
|
+
IRI("http://example.com/subject"),
|
|
59
|
+
IRI("http://example.com/predicate"),
|
|
60
|
+
Literal("test_object"),
|
|
62
61
|
)
|
|
62
|
+
await repo.get_statements(subject=IRI("http://example.com/subject"))
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
For more detailed examples, refer to the [examples](https://github.com/odysa/rdf4j-python/tree/main/examples) directory.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
rdf4j_python/__init__.py,sha256=E8gojaWuLHo2AfNn5HBc5cF7K8_dK2jOBcZaH_qoZs4,347
|
|
2
|
+
rdf4j_python/_client/__init__.py,sha256=L5q5RTHXCNyHp2WNP4xTemGXNntUW4RF_QJPoCWciUQ,98
|
|
3
|
+
rdf4j_python/_client/_client.py,sha256=JfHFudRDVkzmb_jWx1u2meqqFONImBQHuaoYkb4mWPc,7390
|
|
4
|
+
rdf4j_python/_driver/__init__.py,sha256=au0r15mQBVaJkqBknw9CoVswe7_rPPFs1wFWI_ttdy4,224
|
|
5
|
+
rdf4j_python/_driver/_async_named_graph.py,sha256=BqJRpN-JzGpvlSnWY2RrM5TrnIHg6W4PortZ0y-4mgw,2685
|
|
6
|
+
rdf4j_python/_driver/_async_rdf4j_db.py,sha256=LkeLwLhp_lSYhrJVY98LHv9V4jkxF0U5RWQiZmVI9zw,4435
|
|
7
|
+
rdf4j_python/_driver/_async_repository.py,sha256=E6DfW05LFh5KY2X081tW9gg1ksr7DyiM90_j29v71VQ,14212
|
|
8
|
+
rdf4j_python/exception/__init__.py,sha256=PFdUyIMsHIL5e2P2z33Qr2pwlUAJVI0G5T8114W4-1A,83
|
|
9
|
+
rdf4j_python/exception/repo_exception.py,sha256=WXlfIYzOYfNU8LpwtOct9fAZADR-P3cZx4jAX9v_HaA,704
|
|
10
|
+
rdf4j_python/model/__init__.py,sha256=wHboqZX2bN3AubXvWRwKOWwnrefpeiiB_nnry2Ba_a4,176
|
|
11
|
+
rdf4j_python/model/_namespace.py,sha256=6iOvPc2Z6XFY44wmVucQCrjZbFuxdBtoTfDq_bSHJS0,3854
|
|
12
|
+
rdf4j_python/model/_repository_info.py,sha256=fdKwjoQz6_D95Q8uZEuEYhXEUeqElsdBkHRCRRNxjzM,2010
|
|
13
|
+
rdf4j_python/model/repository_config.py,sha256=Uawni9kTjUpH3gCXQxh026NJaGVaJxDd5M-A5U9Ho_4,56654
|
|
14
|
+
rdf4j_python/model/term.py,sha256=JBxndQESR2KEY6y9s6TqoELUQaegKcIUO0ctR818QaA,508
|
|
15
|
+
rdf4j_python/model/vocabulary.py,sha256=Yam0F_YNlO-7wDi2fc0DkAqIKB4ZqCpqq56wKRrFAcw,307
|
|
16
|
+
rdf4j_python/utils/__init__.py,sha256=LAyzkmO5QOIjJogQE1m4Eszwb2cCU8ytKRfhjAGoraw,34
|
|
17
|
+
rdf4j_python/utils/const.py,sha256=HKH9ZGe7m_dvMx1RwT6zhu2HUkvwOX2Y4e8vQFs3uE8,849
|
|
18
|
+
rdf4j_python/utils/helpers.py,sha256=4ubvrx3OV_0Y2_YECNIJhkJUB-JthdCJA8d6Hz_G_kE,506
|
|
19
|
+
rdf4j_python-0.1.3.dist-info/licenses/LICENSE,sha256=sGjA7CzoCG1LVlkh0ZB76ZdgWHVpUFegLU41YYDkGIA,1499
|
|
20
|
+
rdf4j_python-0.1.3.dist-info/METADATA,sha256=Qo5X3u9Mw5r3ABzTmHzlUEEfO01DEsFm_BL2tyfWmAU,2857
|
|
21
|
+
rdf4j_python-0.1.3.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
|
|
22
|
+
rdf4j_python-0.1.3.dist-info/top_level.txt,sha256=Lf2K8d8WcEkmvo5giLGuZ3gl20rNEwMssyAFBeVzbCs,13
|
|
23
|
+
rdf4j_python-0.1.3.dist-info/RECORD,,
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
from abc import ABC
|
|
2
|
-
from typing import Mapping, Optional
|
|
3
|
-
|
|
4
|
-
from rdflib.term import Identifier, Literal, URIRef, Variable
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class _BaseModel(ABC):
|
|
8
|
-
@staticmethod
|
|
9
|
-
def get_literal(
|
|
10
|
-
result: Mapping[Variable, Identifier],
|
|
11
|
-
var_name: str,
|
|
12
|
-
default: Optional[str] = None,
|
|
13
|
-
):
|
|
14
|
-
"""Extract and convert an RDFLib Literal to a Python value."""
|
|
15
|
-
val = result.get(Variable(var_name))
|
|
16
|
-
return val.toPython() if isinstance(val, Literal) else default
|
|
17
|
-
|
|
18
|
-
@staticmethod
|
|
19
|
-
def get_uri(
|
|
20
|
-
result: Mapping[Variable, Identifier],
|
|
21
|
-
var_name: str,
|
|
22
|
-
default: Optional[str] = None,
|
|
23
|
-
):
|
|
24
|
-
"""Extract and convert an RDFLib URIRef to a string."""
|
|
25
|
-
val = result.get(Variable(var_name))
|
|
26
|
-
return str(val) if isinstance(val, URIRef) else default
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
rdf4j_python/__init__.py,sha256=Ltuo15XbZKeKwBTbl2q03OYDZvmYshsMbxxlRtpgJiE,209
|
|
2
|
-
rdf4j_python/_client/__init__.py,sha256=L5q5RTHXCNyHp2WNP4xTemGXNntUW4RF_QJPoCWciUQ,98
|
|
3
|
-
rdf4j_python/_client/_client.py,sha256=gBuw0tfV18SXUmoh4JgJcaa-RwxkGejm2LnQwYlbmIo,3105
|
|
4
|
-
rdf4j_python/_driver/__init__.py,sha256=p4UG1SImBOJHRQFqfYczTv3WnLoy2Me-bpcAYC1nK9E,153
|
|
5
|
-
rdf4j_python/_driver/_async_rdf4j_db.py,sha256=FG0ziBVBmjKQat2voalgvY944hPVyIVXAavIXgNmH5c,3493
|
|
6
|
-
rdf4j_python/_driver/_async_repository.py,sha256=X_IeQaRcLmFlCNTkTH5hTqhPQlzE69PbOac1NuvI7K4,4700
|
|
7
|
-
rdf4j_python/exception/repo_exception.py,sha256=29lQ_1_Ir4GIoCbbOCMCCy0a_YxhMfsjxYTwUNNpRjQ,249
|
|
8
|
-
rdf4j_python/model/__init__.py,sha256=qBJeBaIS_eTBbvxn8IrEbEAbZawRs2-cIG4SQOd3kZE,335
|
|
9
|
-
rdf4j_python/model/_base_model.py,sha256=YOcgb83NfObDlrj7-d8f3yg1ZJGzkKs4blI7wOYb4LA,812
|
|
10
|
-
rdf4j_python/model/_namespace.py,sha256=9ic_Nh1pKWNn4g2qTgAtlKiSr1DzzY8qWAPvqgjWuIw,1483
|
|
11
|
-
rdf4j_python/model/_repository_config.py,sha256=iWfC-81d-blzqPQ6CiQEvZViOQQMGFz6LMYR9AnSLxg,34451
|
|
12
|
-
rdf4j_python/model/_repository_info.py,sha256=ZFwIjL_ZzdF_PZPOQRgxF8iMBM1MI261ZVxK3o1FLJU,1373
|
|
13
|
-
rdf4j_python/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
-
rdf4j_python/utils/const.py,sha256=awf0oGwDs54K02v2GPl2vTgUvrjG0YbX6cAUfXFMsug,838
|
|
15
|
-
rdf4j_python-0.1.1a0.dist-info/licenses/LICENSE,sha256=sGjA7CzoCG1LVlkh0ZB76ZdgWHVpUFegLU41YYDkGIA,1499
|
|
16
|
-
rdf4j_python-0.1.1a0.dist-info/METADATA,sha256=17yBFlB7wTbduJapzrQWc_ZgRCRMEpSK8v7IFyrtq2w,2842
|
|
17
|
-
rdf4j_python-0.1.1a0.dist-info/WHEEL,sha256=DnLRTWE75wApRYVsjgc6wsVswC54sMSJhAEd4xhDpBk,91
|
|
18
|
-
rdf4j_python-0.1.1a0.dist-info/top_level.txt,sha256=Lf2K8d8WcEkmvo5giLGuZ3gl20rNEwMssyAFBeVzbCs,13
|
|
19
|
-
rdf4j_python-0.1.1a0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|