graflo.architecture.transform¶
Data transformation and mapping system for graph databases.
This module provides a flexible system for transforming and mapping data in graph databases. It supports both functional transformations and declarative mappings, with support for field switching and parameter configuration.
Key Components
- ProtoTransform: Base class for transform definitions
- Transform: Concrete transform implementation
- TransformException: Custom exception for transform errors
The transform system supports
- Functional transformations through imported modules
- Field mapping and switching
- Parameter configuration
- Input/output field specification
- Transform composition and inheritance
Example
transform = Transform( ... module="my_module", ... foo="process_data", ... input=("field1", "field2"), ... output=("result1", "result2") ... ) result = transform({"field1": 1, "field2": 2})
ProtoTransform
¶
Bases: ConfigBaseModel
Base class for transform definitions.
This class provides the foundation for data transformations, supporting both functional transformations and declarative mappings.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str | None
|
Optional name of the transform |
module |
str | None
|
Optional module containing the transform function |
params |
dict[str, Any]
|
Dictionary of transform parameters |
foo |
str | None
|
Optional name of the transform function |
input |
tuple[str, ...]
|
Tuple of input field names |
output |
tuple[str, ...]
|
Tuple of output field names |
_foo |
Any
|
Internal reference to the transform function |
Source code in graflo/architecture/transform.py
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 | |
__lt__(other)
¶
Compare transforms for ordering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
Other transform to compare with |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if this transform should be ordered before other |
Source code in graflo/architecture/transform.py
Transform
¶
Bases: ProtoTransform
Concrete transform implementation.
This class extends ProtoTransform with additional functionality for field mapping, switching, and transform composition.
Attributes:
| Name | Type | Description |
|---|---|---|
fields |
tuple[str, ...]
|
Tuple of fields to transform |
map |
dict[str, str]
|
Dictionary mapping input fields to output fields |
switch |
dict[str, Any]
|
Dictionary for field switching logic |
functional_transform |
bool
|
Whether this is a functional transform |
Source code in graflo/architecture/transform.py
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 | |
is_dummy
property
¶
Check if this is a dummy transform.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if this is a dummy transform |
is_mapping
property
¶
True when the transform is pure mapping (no function).
__call__(*nargs, **kwargs)
¶
Execute the transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*nargs
|
Any
|
Positional arguments for the transform |
()
|
**kwargs
|
Any
|
Keyword arguments for the transform |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any] | Any
|
Transformed data |
Source code in graflo/architecture/transform.py
get_barebone(other)
¶
Get the barebone transform configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Transform | None
|
Optional transform to use as base |
required |
Returns:
| Type | Description |
|---|---|
Transform | None
|
tuple[Transform | None, Transform | None]: Updated self transform |
Transform | None
|
and transform to store in library |
Source code in graflo/architecture/transform.py
merge_from(t)
¶
Merge another transform's configuration into a copy of it.
Returns a new Transform with values from self overriding t where set. Does not override ConfigBaseModel.update (in-place); use this for copy-and-merge semantics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t
|
Transform
|
Transform to merge from |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Transform |
Transform
|
New transform with merged configuration |