graflo.hq.graph_engine¶
Graph engine for orchestrating schema inference, pattern creation, and ingestion.
This module provides the GraphEngine class which serves as the main orchestrator for graph database operations, coordinating between inference, pattern mapping, and data ingestion.
GraphEngine
¶
Orchestrator for graph database operations.
GraphEngine coordinates schema inference, pattern 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_patterns() - Create patterns 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 pattern creation |
Source code in graflo/hq/graph_engine.py
23 24 25 26 27 28 29 30 31 32 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 | |
__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_patterns(postgres_config, schema_name=None, datetime_columns=None)
¶
Create Patterns 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 TablePattern). Use with IngestionParams.datetime_after / datetime_before. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Patterns |
Patterns
|
Patterns object with TablePattern instances for all tables |
Source code in graflo/hq/graph_engine.py
define_and_ingest(schema, target_db_config, patterns=None, ingestion_params=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 |
|---|---|---|---|
schema
|
Schema
|
Schema configuration for the graph |
required |
target_db_config
|
DBConfig
|
Target database connection configuration |
required |
patterns
|
Patterns | None
|
Patterns instance mapping resources to data sources. If None, defaults to empty Patterns() |
None
|
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(schema, 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 |
|---|---|---|---|
schema
|
Schema
|
Schema configuration for the graph |
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_schema(postgres_config, schema_name=None, fuzzy_threshold=0.8, discard_disconnected_vertices=False)
¶
Infer a graflo Schema 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 |
|---|---|---|
Schema |
Schema
|
Inferred schema with vertices, edges, and resources |
Source code in graflo/hq/graph_engine.py
ingest(schema, target_db_config, patterns=None, ingestion_params=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 |
|---|---|---|---|
schema
|
Schema
|
Schema configuration for the graph |
required |
target_db_config
|
DBConfig
|
Target database connection configuration |
required |
patterns
|
Patterns | None
|
Patterns instance mapping resources to data sources. If None, defaults to empty Patterns() |
None
|
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)
¶
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. |