Skip to content

Commit 07c2fa3

Browse files
DanLeeBenBirt
DanLee
andauthored
add python REST API example (#1019)
* adding a python api example * Update index.md * Update content/docs/dataform-web/api/index.md Co-authored-by: BenBirt <[email protected]> * Update content/docs/dataform-web/api/index.md Co-authored-by: BenBirt <[email protected]> * Update index.md Co-authored-by: BenBirt <[email protected]>
1 parent 32fb043 commit 07c2fa3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

content/docs/dataform-web/api/index.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,30 @@ This will return a [`RunGetResponse`](api/reference#/definitions/v1RunGetRespons
6060
"runLogUrl": "https://app.dataform.co/#/1234/run/5678"
6161
}
6262
```
63+
64+
## Triggering a Dataform schedule from a 3rd party orchestration tool
65+
66+
Using the REST API it's possible to trigger Dataform schedules from a third party orchestration tool, like Airflow or Luigi.
67+
68+
The following example, written in Python, shows how you can trigger a schedule, check its status every 10 seconds, and exit when the schedule finishes.
69+
70+
```python
71+
import requests
72+
import time
73+
import json
74+
75+
base_url='https://api.dataform.co/v1/project/<PROJECT_ID>/run'
76+
headers={'Authorization': 'Bearer <API_TOKEN>'}
77+
run_create_request={"environmentName": "<ENVIRONMENT_NAME>", "scheduleName": "<SCHEDULE_NAME>"}
78+
79+
response = requests.post(base_url, data=json.dumps(run_create_request), headers=headers)
80+
81+
run_url = base_url + '/' + response.json()['id']
82+
83+
response = requests.get(run_url, headers=headers)
84+
85+
while response.json()['status'] == 'RUNNING':
86+
time.sleep(10)
87+
response = requests.get(run_url, headers=headers)
88+
print(response.json())
89+
```

0 commit comments

Comments
 (0)