kiran
06/14/2023, 3:10 PMJeff Hale
06/14/2023, 3:11 PMJeff Hale
06/14/2023, 3:18 PMbrittany bennett
06/14/2023, 3:34 PMJeff Hale
06/14/2023, 3:48 PMJeff Hale
06/14/2023, 3:49 PMJeff Hale
06/14/2023, 3:58 PMJeff Hale
06/14/2023, 4:04 PMJeff Hale
06/14/2023, 4:05 PMBenjamin Nicholson
06/14/2023, 4:13 PMimport requests
from prefect import flow, task
@task
def call_api(url):
response = requests.get(url)
print(response.status_code)
return response.json()
@flow
def api_flow(url):
fact_json = call_api(url)
return fact_json
print(api_flow("<https://catfact.ninja/fact>"))
Jeff Hale
06/14/2023, 4:15 PMKrishna Lodha
06/14/2023, 4:15 PMfrom prefect import flow,task
import httpx
# API to hit - <https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=weathercode,windspeed_10m,soil_temperature_0cm>
@task
def get_windspeed_10m(lat,lon):
r = httpx.get(f'<https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&hourly=windspeed_10m&forecast_days=1>')
wind_speed = r.json()['hourly']['windspeed_10m'][0]
return wind_speed
@task
def get_windspeed_80m(lat,lon):
r = httpx.get(f'<https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&hourly=windspeed_80m&forecast_days=1>')
wind_speed = r.json()['hourly']['windspeed_80m'][0]
return wind_speed
@flow
def get_weather(lat,lon):
wind_speed_80 = get_windspeed_80m(lat,lon)
wind_speed = get_windspeed_10m(lat,lon)
return {
"wind_speed_80m" :wind_speed_80,
"wind_speed_10m" :wind_speed
}
@task
def get_soil_temperature_0cm(lat,lon):
r = httpx.get(f'<https://api.open-meteo.com/v1/forecast?latitude={lat}&longitude={lon}&hourly=soil_temperature_0cm&forecast_days=1>')
soil_temp = r.json()['hourly']['soil_temperature_0cm'][0]
return soil_temp
@flow
def get_all(lat,lon):
obj = get_weather(lat,lon)
soil_temp = get_soil_temperature_0cm(lat,lon)
print({
"wind_10m" : obj['wind_speed_10m'],
"wind_80m" :obj['wind_speed_80m'],
"soil_temp" :soil_temp,
})
if __name__ == '__main__' :
get_all(52,17)
Lavanya
06/14/2023, 4:19 PMJeff Hale
06/14/2023, 4:20 PMLavanya
06/14/2023, 4:21 PMJeff Hale
06/14/2023, 4:32 PMJonathan Seery
06/14/2023, 4:32 PMprefect server start
running 🧵Jeff Hale
06/14/2023, 4:38 PMbrittany bennett
06/14/2023, 4:45 PM@task(cache_key_fn=task_input_hash)
i read the docs here https://docs.prefect.io/2.10.13/api-ref/prefect/tasks/#prefect.tasks.task_input_hash and I’m still a lil confusedCarlos Baldellou
06/14/2023, 4:49 PMCody
06/14/2023, 4:53 PMLavanya
06/14/2023, 4:54 PMJeff Hale
06/14/2023, 4:55 PMSahil Rangwala
06/14/2023, 4:56 PMJeff Hale
06/14/2023, 4:58 PMJeff Moszuti
06/14/2023, 4:59 PMJonathan Seery
06/14/2023, 5:11 PM.py
files between the two labs we’ve done, but without thinking I’ve named the top-level flows in each file pipeline()
. In the Prefect UI I think they seem to be treated as one flow, but the flow runs will have different contents / tasks depending on which file I run. Seems like this could be helpful or really confusing - any thoughts about how this might work in practice?Cody
06/14/2023, 5:13 PMCody
06/14/2023, 5:13 PMCharlie Henry
06/14/2023, 5:13 PM