Python API¶
Most projects only need the decorator and the helpers below. The Project class in pipeloom.api runs the same
stages as the command line from Python, for notebooks, tests and tools. Both are part of the
stable surface.
Authoring¶
Mark a function as a pipeloom model, as @model or @model(...). Returns the same
function with a ModelSpec in __pipeloom_model__.
Source code in src/pipeloom/authoring.py
What a Python model receives as ctx.
Source code in src/pipeloom/runtime/context.py
interval = None
class-attribute
instance-attribute
¶
Since 1.3: the UTC window [start, end) an interval model is running, else None. The
incremental input is already filtered to it (ADR-0054).
lower_bound = None
class-attribute
instance-attribute
¶
The last three are used from 0.3. Fields after them are wiring, not part of the API.
log(message, *, level='info', **fields)
¶
Emit a model.log event.
sql(query, *, dialect=None, inputs=None)
¶
Run query over the model's inputs, named by alias as read (after the incremental
filter). inputs adds or replaces frames by name. dialect (else the model's
sql_dialect) is translated to the engine's when it differs. Returns the native frame,
or a Narwhals frame under frame_api: narwhals.
Source code in src/pipeloom/runtime/context.py
Running from Python¶
A project on disk. Each step runs once and is remembered.
Source code in src/pipeloom/api.py
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 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 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 | |
discovery = None
instance-attribute
¶
The project's model discovery, kept so docs serve can refresh it.
redactor = redactor or Redactor()
instance-attribute
¶
Holds every secret the run resolves; pass the same one to the event bus.
registry
property
¶
Discovered on first use from the options' --plugin specs and the environment.
secrets
property
¶
Resolves ${secret:...} references for plugins built to execute. One per project, so
each provider is built once per invocation.
bind()
¶
Load, then pick the target and bind its plugins.
Source code in src/pipeloom/api.py
build(opts=None, bus=None, control=None)
¶
Run the unit tests of the selected models, then, when every case passed, run them
with data tests on (ADR-0045). A failed case stops the build with exit 1 before a run id
exists and before any write.
Source code in src/pipeloom/api.py
compile(selection=None, boundary=None)
¶
Validate, then build the plan. Units always cover the whole project; the selection
only marks which models are selected. boundary defaults to the target's.
Source code in src/pipeloom/api.py
diff(model, state, *, key=(), samples=False)
¶
Compare model's relation in the state reference (the source) with its relation on
this target (ADR-0053). It writes nothing. key wins over the model's
write.unique_key. Exit code 0 no differences, 1 differences or a failure, 2 usage.
Source code in src/pipeloom/api.py
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 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | |
finalize(opts, bus=None)
¶
Close a run an orchestrator drove unit by unit: merge the unit results, record the run
and emit run.completed. Repeating the call rewrites the same results.
Source code in src/pipeloom/api.py
load()
¶
Read and check pipeloom.yml and properties files (layers L0 and L1).
Source code in src/pipeloom/api.py
resolve()
¶
Bind, apply defaults, check references (L2) and build the graph (L3).
Source code in src/pipeloom/api.py
retry(parent_run_id, opts=None, bus=None, control=None, *, full_refresh=None)
¶
Run again what run parent_run_id did not finish: its failed, skipped and cancelled
units. The new run has its own id and records the parent as parent_run_id; it inherits
the parent's vars (under this project's own), full_refresh (full_refresh wins), state
and defer, and compiles the project fresh. A parent that cannot be retried is PLX113; one
with nothing to retry gives a succeeded outcome with no run results.
Source code in src/pipeloom/api.py
run(opts=None, bus=None, control=None)
¶
Validate, plan and run the selected units. Events go to bus; without one they are dropped.
control.request_stop() stops the run gracefully from any thread; hard=True skips the
grace period. The outcome is then cancelled with exit code 130.
Source code in src/pipeloom/api.py
test(selection=None)
¶
Run the unit tests of the selected models (ADR-0045). It writes nothing: no run id, no lock, no artifacts. The outcome holds one event payload per case and a summary.
Source code in src/pipeloom/api.py
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 390 391 392 | |
validate()
¶
Resolve, then run the plan checks (L4 to L6). None when any layer found an error.
with_vars(vars_)
¶
This project with other vars, which are read at load; self when they are the same. It keeps the registry, clock, identity, invocation id and redactor.