graflo.hq.graph_engine¶
Graph engine for orchestrating schema inference, connector creation, and ingestion.
This module provides the GraphEngine class which serves as the main orchestrator for graph database operations, coordinating between inference, connector mapping, and data ingestion.
GraphEngine
¶
Orchestrator for graph database operations.
GraphEngine coordinates schema inference, connector creation, schema definition, and data ingestion, providing a unified interface for working with graph databases.
The typical workflow is: 1. infer_schema() - Infer schema from source database (if possible) 2. create_bindings() - Create bindings mapping resources to data sources (if possible) 3. define_schema() - Define schema in target database (if possible and necessary) 4. ingest() - Ingest data into the target database
Attributes:
| Name | Type | Description |
|---|---|---|
target_db_flavor |
Target database flavor for schema sanitization |
|
resource_mapper |
ResourceMapper instance for connector creation |
Source code in graflo/hq/graph_engine.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 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 | |
__init__(target_db_flavor=DBType.ARANGO)
¶
Initialize the GraphEngine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_db_flavor
|
DBType
|
Target database flavor for schema sanitization |
ARANGO
|
Source code in graflo/hq/graph_engine.py
create_bindings(postgres_config, schema_name=None, datetime_columns=None, type_lookup_overrides=None, include_raw_tables=False)
¶
Create Bindings from PostgreSQL tables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
postgres_config
|
PostgresConfig
|
PostgresConfig instance |
required |
schema_name
|
str | None
|
Schema name to introspect |
None
|
datetime_columns
|
dict[str, str] | None
|
Optional mapping of resource/table name to datetime column name for date-range filtering (sets date_field per TableConnector). Use with IngestionParams.datetime_after / datetime_before. |
None
|
type_lookup_overrides
|
dict[str, dict] | None
|
Optional mapping of table name to type_lookup spec for edge tables where source/target types come from a lookup table. Each value: {table, identity, type_column, source, target, relation?}. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Bindings |
Bindings
|
Bindings object with TableConnector instances for all tables |
Source code in graflo/hq/graph_engine.py
create_bindings_from_rdf(source, *, endpoint_url=None, graph_uri=None, sparql_config=None)
¶
Create :class:Bindings from an RDF ontology.
One :class:SparqlConnector is created per owl:Class found in the
ontology.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | Path
|
Path to an RDF file or base URL. |
required |
endpoint_url
|
str | None
|
SPARQL endpoint for the data (ABox). |
None
|
graph_uri
|
str | None
|
Named graph containing the data. |
None
|
sparql_config
|
SparqlEndpointConfig | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
Bindings
|
Bindings with SPARQL connectors for each class. |
Source code in graflo/hq/graph_engine.py
define_and_ingest(manifest, target_db_config, ingestion_params=None, connection_provider=None, recreate_schema=None, clear_data=None)
¶
Define schema and ingest data into the graph database in one operation.
This is a convenience method that chains define_schema() and ingest(). It's the recommended way to set up and populate a graph database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
GraphManifest
|
GraphManifest with schema/ingestion/bindings blocks. |
required |
target_db_config
|
DBConfig
|
Target database connection configuration |
required |
ingestion_params
|
IngestionParams | None
|
IngestionParams instance with ingestion configuration. If None, uses default IngestionParams() |
None
|
recreate_schema
|
bool | None
|
If True, drop existing schema and define new one. If None, defaults to False. When False and schema already exists, define_schema raises SchemaExistsError and the script halts. |
None
|
clear_data
|
bool | None
|
If True, remove existing data before ingestion (schema unchanged). If None, uses ingestion_params.clear_data. |
None
|
Source code in graflo/hq/graph_engine.py
define_schema(manifest, target_db_config, recreate_schema=False)
¶
Define schema in the target database.
This method handles database/schema creation and initialization. Some databases don't require explicit schema definition (e.g., Neo4j), but this method ensures the database is properly initialized.
If the schema/graph already exists and recreate_schema is False (default), init_db raises SchemaExistsError and the script halts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
GraphManifest
|
GraphManifest with schema block. |
required |
target_db_config
|
DBConfig
|
Target database connection configuration |
required |
recreate_schema
|
bool
|
If True, drop existing schema and define new one. If False and schema/graph already exists, raises SchemaExistsError. |
False
|
Source code in graflo/hq/graph_engine.py
infer_manifest(postgres_config, schema_name=None, fuzzy_threshold=0.8, discard_disconnected_vertices=False)
¶
Infer a GraphManifest from PostgreSQL database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
postgres_config
|
PostgresConfig
|
PostgresConfig instance |
required |
schema_name
|
str | None
|
Schema name to introspect (defaults to config schema_name or 'public') |
None
|
fuzzy_threshold
|
float
|
Similarity threshold for fuzzy matching (0.0 to 1.0, default 0.8) |
0.8
|
discard_disconnected_vertices
|
bool
|
If True, remove vertices that do not take part in any relation (and resources/actors that reference them). Default False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
GraphManifest |
GraphManifest
|
Inferred manifest with schema and ingestion model. |
Source code in graflo/hq/graph_engine.py
infer_schema_from_rdf(source, *, endpoint_url=None, graph_uri=None, schema_name=None)
¶
Infer a graflo Schema from an RDF / OWL ontology.
Reads the TBox (class and property declarations) and produces
vertices (from owl:Class), fields (from owl:DatatypeProperty),
and edges (from owl:ObjectProperty with domain/range).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str | Path
|
Path to an RDF file (e.g. |
required |
endpoint_url
|
str | None
|
Optional SPARQL endpoint to CONSTRUCT the ontology from. |
None
|
graph_uri
|
str | None
|
Named graph containing the ontology. |
None
|
schema_name
|
str | None
|
Name for the resulting schema. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Schema, IngestionModel]
|
tuple[Schema, IngestionModel]: fully initialised schema and ingestion model. |
Source code in graflo/hq/graph_engine.py
ingest(manifest, target_db_config, ingestion_params=None, connection_provider=None)
¶
Ingest data into the graph database.
If ingestion_params.clear_data is True, removes all existing data (without touching the schema) before ingestion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
GraphManifest
|
GraphManifest with schema/ingestion/bindings blocks. |
required |
target_db_config
|
DBConfig
|
Target database connection configuration |
required |
ingestion_params
|
IngestionParams | None
|
IngestionParams instance with ingestion configuration. If None, uses default IngestionParams() |
None
|
Source code in graflo/hq/graph_engine.py
introspect(postgres_config, schema_name=None, include_raw_tables=True)
¶
Introspect PostgreSQL schema and return a serializable result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
postgres_config
|
PostgresConfig
|
PostgresConfig instance |
required |
schema_name
|
str | None
|
Schema name to introspect (defaults to config schema_name or 'public') |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
SchemaIntrospectionResult |
SchemaIntrospectionResult
|
Introspection result (vertex_tables, edge_tables, raw_tables, schema_name) suitable for serialization. |