Go API & Programmatic Usage

ETLX is not only a CLI tool โ€” it is also a Go library that you can embed directly into your own applications.

The official etlx binary is built using the same public Go APIs exposed by the project. This page documents those APIs in a ready-to-use way, based on how cmd/main.go constructs and executes pipelines.

๐Ÿ”ง CLI Internals (Important Context)

The ETLX CLI:

  • Uses Goโ€™s standard flag package
  • Does not rely on Cobra or subcommands
  • Internally calls the same APIs you can call from Go

This means:

๐Ÿ‘‰ Anything the CLI can do, you can do programmatically

๐Ÿ“ฆ Installing as a Go Dependency

  go get github.com/realdatadriven/etlx
  

๐Ÿง  Core Concepts (Go Perspective)

At runtime, ETLX works in three phases:

  1. Parse Markdown configuration
  2. Resolve execution scope (date, only, skip, steps, etc.)
  3. Execute pipeline + collect logs

The Go API mirrors this exactly.

๐Ÿ— Creating an ETLX Engine

  import "github.com/realdatadriven/etlx"
  
  engine := &etlx.ETLX{}
  

This ETLX instance holds:

  • Parsed pipeline configuration
  • Execution options
  • Runtime state
  • Execution logs

๐Ÿ“„ Loading a Pipeline Configuration

Load from file

  err := engine.ConfigFromFile("pipeline.md")
if err != nil {
    panic(err)
}
  

Load from in-memory Markdown

Useful for dynamic or generated pipelines:

  md := `# ETLX Pipeline...`

err := engine.ConfigFromMDText(md)
if err != nil {
    panic(err)
}
  

๐Ÿ“† Running a Pipeline (Equivalent to CLI)

Equivalent CLI:

  etlx --config pipeline.md --date 2025-01-01
  

Minimal execution

  dates := []time.Time{
    time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC),
}

logs, err := engine.RunETL(dates, nil, nil)
if err != nil {
    panic(err)
}
  

๐ŸŽฏ Execution Options (--only, --skip, --steps)

The CLI flags are translated into a simple options map.

Run only specific keys

  opts := map[string]any{
    "only": []string{"sales", "customers"},
}

logs, err := engine.RunETL(dates, nil, opts)
  

Equivalent CLI:

  etlx --config pipeline.md --only sales,customers
  

Skip specific keys

  opts := map[string]any{
    "skip": []string{"debug_tables"},
}
  

Run specific lifecycle steps

  opts := map[string]any{
    "steps": []string{"extract", "load"},
}
  

Equivalent CLI:

  etlx --config pipeline.md --steps extract,load
  

๐Ÿงน Clean & Drop Operations

Equivalent CLI:

  etlx --config pipeline.md --clean
etlx --config pipeline.md --drop
  

Clean SQL blocks

  opts := map[string]any{
    "clean": true,
}

engine.RunETL(dates, nil, opts)
  

Drop SQL blocks

  opts := map[string]any{
    "drop": true,
}

engine.RunETL(dates, nil, opts)
  

๐Ÿ“Š Accessing Execution Logs

Every execution returns structured logs.

  logs, _ := engine.RunETL(dates, nil, nil)

for _, log := range logs {
    fmt.Println(
        log.Name,
        log.Ref,
        log.Duration,
        log.Success,
        log.Msg,
    )
}
  

Each log entry typically contains:

FieldDescription
nameStep or block name
refReference date
startStart timestamp
endEnd timestamp
durationExecution time
successSuccess / failure
msgMessage or error

๐Ÿงช Running Specific Sections

ETLX exposes explicit execution entry points for each pipeline capability.

All functions share the same execution model:

  func(dates []time.Time, cfg any, opts map[string]any) ([]etlx.Log, error)
  

The difference is which Markdown sections are executed.

โ–ถ๏ธ RunETL

Executes the full ETL / ELT lifecycle see ETL / ELT

  logs, err := engine.RunETL(dates, nil, nil)
  

๐Ÿงช RunDATA_QUALITY

Runs operational or auxiliary scripts see Data Quality

  logs, err := engine.RunDATA_QUALITY(dates, nil, nil)
  

๐Ÿ“ค RunEXPORTS

Executes export definitions see Exports

  logs, err := engine.RunEXPORTS(dates, nil, nil)
  

๐Ÿ“œ RunSCRIPTS

Runs operational or auxiliary scripts see Scripts

  logs, err := engine.RunSCRIPTS(dates, nil, nil)
  

โš™๏ธ RunACTIONS

Runs post-processing or orchestration actions see Actions

  logs, err := engine.RunACTIONS(dates, nil, nil)
  

๐Ÿงพ RunLOGS

Processes logging or audit blocks see Logs / Observability

  logs, err := engine.RunLOGS(dates, nil, nil)
  

๐Ÿ”” RunNOTIFY

Executes notification definitions see Notificatios

  logs, err := engine.RunNOTIFY(dates, nil, nil)
  

๐Ÿงต Using ETLX Inside Long-Running Services

  func runPipeline(ref time.Time) error {
    engine := &etlx.ETLX{}

    if err := engine.ConfigFromFile("pipeline.md"); err != nil {
        return err
    }

    _, err := engine.RunETL([]time.Time{ref}, nil, nil)
    return err
}
  

๐Ÿง  Why This Matters

Because ETLX is:

  • A runtime
  • An open specification
  • A Go library

You are not locked into:

  • A closed binary
  • A hidden execution model
  • A proprietary DSL

The Markdown pipeline is the documentation, and the Go API is the execution layer.

๐Ÿ Summary

โœ” CLI uses standard Go flags โœ” Go API mirrors the CLI exactly โœ” Pipelines can be executed from files or memory โœ” Each lifecycle has its own entry point โœ” Structured logs for audit & observability โœ” Ideal for embedding, automation, and regulated workloads

Last updated 09 Jan 2026, 11:14 -01 . history

Was this page helpful?