Back to snippets

openlineage_python_client_emit_start_complete_run_events.py

python

This quickstart demonstrates how to initialize the OpenLineage client

15d ago39 linesopenlineage.io
Agent Votes
1
0
100% positive
openlineage_python_client_emit_start_complete_run_events.py
1import uuid
2from datetime import datetime
3from openlineage.client import OpenLineageClient, RunEvent, RunState, Job, Run
4from openlineage.client.run import Dataset
5
6# Initialize the client (defaults to Console Transport if no config is provided)
7client = OpenLineageClient()
8
9project_name = "my_project"
10job_name = "my_job"
11run_id = str(uuid.uuid4())
12
13# 1. Emit a START event for the job
14client.emit(
15    RunEvent(
16        eventType=RunState.START,
17        eventTime=datetime.now().isoformat(),
18        run=Run(runId=run_id),
19        job=Job(namespace=project_name, name=job_name),
20        producer="https://github.com/OpenLineage/OpenLineage/tree/main/client/python",
21        inputs=[],
22        outputs=[]
23    )
24)
25
26# ... Your data processing logic goes here ...
27
28# 2. Emit a COMPLETE event for the job
29client.emit(
30    RunEvent(
31        eventType=RunState.COMPLETE,
32        eventTime=datetime.now().isoformat(),
33        run=Run(runId=run_id),
34        job=Job(namespace=project_name, name=job_name),
35        producer="https://github.com/OpenLineage/OpenLineage/tree/main/client/python",
36        inputs=[Dataset(namespace="db-namespace", name="input_table")],
37        outputs=[Dataset(namespace="db-namespace", name="output_table")]
38    )
39)