graflo.data_source.rdf¶
RDF data source hierarchy.
Provides two concrete data sources that share a common abstract parent:
- :class:
RdfFileDataSource– reads local RDF files (Turtle, RDF/XML, N3, JSON-LD, …) via rdflib. - :class:
SparqlEndpointDataSource– queries a remote SPARQL endpoint (e.g. Apache Fuseki) via SPARQLWrapper.
Both convert RDF triples into flat dictionaries grouped by subject URI, one
dict per rdf:Class instance. Each document has _uri (full subject URI)
and _key (URI local name — the fragment or last path segment). All other
identity decisions (e.g. using a domain-specific literal as the storage key)
belong in the schema layer, not here.
Uses rdflib and SPARQLWrapper, which are core dependencies of
graflo (see pyproject.toml).
Attributes¶
SparqlDataSource = SparqlEndpointDataSource
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Classes¶
RdfDataSource
¶
Bases: AbstractDataSource, ABC
Abstract base for RDF data sources (file and endpoint).
Captures the fields and batch-yielding logic shared by both
:class:RdfFileDataSource and :class:SparqlEndpointDataSource.
Attributes:
| Name | Type | Description |
|---|---|---|
rdf_class |
str | None
|
Optional URI of the |
Source code in graflo/data_source/rdf.py
RdfFileDataSource
¶
Bases: RdfDataSource
Data source for local RDF files.
Parses RDF files using rdflib and yields flat dictionaries grouped by
subject URI. Optionally filters by rdf_class so that only instances
of a specific class are returned.
Attributes:
| Name | Type | Description |
|---|---|---|
path |
Path
|
Path to the RDF file. |
rdf_format |
str | None
|
Explicit rdflib format string (e.g. |
Source code in graflo/data_source/rdf.py
Attributes¶
path
instance-attribute
¶
rdf_format = Field(default=None, description='rdflib serialization format')
class-attribute
instance-attribute
¶
Methods:¶
iter_batches(batch_size=1000, limit=None)
¶
Parse the RDF file and yield batches of flat dictionaries.
Source code in graflo/data_source/rdf.py
SparqlEndpointDataSource
¶
Bases: RdfDataSource
Data source that reads from a SPARQL endpoint.
Uses SPARQLWrapper to query an endpoint and returns flat dictionaries
grouped by subject.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
SparqlSourceConfig
|
SPARQL source configuration. |
Source code in graflo/data_source/rdf.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | |
Attributes¶
config
instance-attribute
¶
Methods:¶
iter_batches(batch_size=1000, limit=None)
¶
Query the SPARQL endpoint and yield batches of flat dictionaries.
Paginates with SPARQL LIMIT/OFFSET on bindings (triple rows), merges rows into subject documents in a streaming fashion, and stops fetching once limit subjects have been yielded (when set).
Source code in graflo/data_source/rdf.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 | |
SparqlSourceConfig
¶
Bases: ConfigBaseModel
Configuration for a SPARQL endpoint data source.
Attributes:
| Name | Type | Description |
|---|---|---|
endpoint_url |
str
|
Full SPARQL query endpoint URL
(e.g. |
rdf_class |
str | None
|
URI of the rdf:Class whose instances to fetch |
graph_uri |
str | None
|
Named graph to restrict the query to (optional) |
sparql_query |
str | None
|
Custom SPARQL query override (optional) |
username |
str | None
|
HTTP basic-auth username (optional) |
password |
str | None
|
HTTP basic-auth password (optional) |
page_size |
int
|
Number of results per SPARQL LIMIT/OFFSET page |
Source code in graflo/data_source/rdf.py
Attributes¶
endpoint_url
instance-attribute
¶
graph_uri = None
class-attribute
instance-attribute
¶
page_size = Field(default=10000, description='SPARQL pagination page size')
class-attribute
instance-attribute
¶
password = None
class-attribute
instance-attribute
¶
rdf_class = None
class-attribute
instance-attribute
¶
sparql_query = None
class-attribute
instance-attribute
¶
username = None
class-attribute
instance-attribute
¶
Methods:¶
build_query(offset=0, limit=None)
¶
Build a SPARQL SELECT query.
If sparql_query is set it is returned with LIMIT/OFFSET appended. Otherwise generates::
SELECT ?s ?p ?o WHERE { ?s a <rdf_class> . ?s ?p ?o . }