ETLFacade¶
The ETL facade composes pipelines of stages (fetch, transform, filter, aggregate, export) with shared configuration injection. Pipelines are declared as a list of stage definitions; the SDK executes them sequentially with structured error propagation.
API reference¶
The full reference is generated from the SDK's docstrings via mkdocstrings.
ETLFacade
¶
Public facade for the ETL pipeline layer.
Exposed via :attr:un_comtrade.client.ComtradeClient.etl so
callers can build pipelines that share the client's
:class:un_comtrade.config.Configuration without re-supplying
it each time.
Construction::
client = ComtradeClient()
pipeline = client.etl.pipeline(
name="trade_ingest",
stages=(stage_spec_a, stage_spec_b),
)
result = pipeline.run(source=...)
The facade does not duplicate the ETLPipeline runner; it
is a thin factory that injects the client's configuration.
Source code in un_comtrade/etl.py
configuration
property
¶
The :class:un_comtrade.config.Configuration this
facade injects into new pipelines.
pipeline
¶
Build an :class:ETLPipeline that inherits the
client's configuration.
Parameters¶
name
Pipeline identifier (mirrored on the resulting
:class:PipelineResult.pipeline_name).
stages
Ordered tuple / list of :class:StageSpec
entries.
Returns¶
ETLPipeline
A ready-to-run pipeline. Call pipeline.run(source)
with the input dataset / payload.
Source code in un_comtrade/etl.py
ETLPipeline
dataclass
¶
Declarative orchestrator for an ETL pipeline.
The pipeline is composed of a tuple of StageSpec
entries. Stages run in the order declared; each
stage receives the previous stage's output (or
the source, for the first stage) and the shared
PipelineContext.
This is orchestration only: the pipeline does
NOT implement any concrete stage. Stages are
supplied by the caller (built by the
StageSpec.factory callables). The MVP supports
a sequential pipeline; parallel / streaming is
reserved for future versions per OQ-ETL-002.
Construction::
pipeline = ETLPipeline(
name="trade_ingest",
stages=(
StageSpec(
name="extract",
kind=StageKind.EXTRACT,
factory=lambda ctx: MyExtractor(...),
),
StageSpec(
name="validate",
kind=StageKind.VALIDATE,
factory=lambda ctx: MyValidator(...),
),
...
),
config={"batch_size": 1000},
)
Execution::
result = pipeline.run(source=response_envelope)
if result.status is PipelineStatus.SUCCESS:
for record in result.output:
...
else:
for error in result.errors:
...
Mutability:
nameis required and non-empty.stagesis required and MUST be a sequence ofStageSpec. The constructor accepts lists / tuples but freezes to a tuple.configis a free-form mapping; the pipeline shallow-copies it into thePipelineContextat run time so stages cannot mutate the pipeline's config.
Composition:
with_stage(spec)returns a NEW pipeline with the stage appended. The original is unchanged (the pipeline is logically immutable once constructed; this matches the frozen semantics of the SDK's other orchestrators).
Source code in un_comtrade/etl.py
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 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
with_stage
¶
Return a new pipeline with spec appended.
The original pipeline is unchanged. Used to build pipelines incrementally.
Source code in un_comtrade/etl.py
with_config
¶
Return a new pipeline with config overridden.
Original pipeline is unchanged.
Source code in un_comtrade/etl.py
run
¶
Execute the pipeline against source.
Stages run in declared order. The first stage
receives source as its input; subsequent
stages receive the previous stage's output. A
stage failure (any Exception) short-circuits
the pipeline and records FAILED status; the
exception is NOT re-raised so the caller can
inspect the partial output.
Returns a PipelineResult capturing output,
warnings, errors, and per-stage timings. Even
on failure the result is returned (with
status=FAILED); the pipeline never raises
from run() itself.
Source code in un_comtrade/etl.py
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
Examples¶
from un_comtrade import ComtradeClient
with ComtradeClient() as client:
pipeline = client.etl.pipeline(
name="india_exports",
stages=[
("fetch", {"reporter_code": 699, "period": "2022"}),
("export", {"path": "india_exports.parquet"}),
],
)
pipeline.run()
Related Recipes¶
- RECIPE-031 — ETL pipeline.
- RECIPE-111 — India exports to report.
Related Guides¶
- Python SDK → ETL — full Python API surface.