forked from discdiver/demos
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmy_workflow.py
41 lines (27 loc) · 922 Bytes
/
my_workflow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import httpx
from prefect import flow, task # Prefect flow and task decorators
@flow(log_prints=True)
def show_stars(github_repos: list[str]):
"""Flow: Show the number of stars that GitHub repos have"""
for repo in github_repos:
# Call Task 1
repo_stats = fetch_stats(repo)
# Call Task 2
stars = get_stars(repo_stats)
# Print the result
print(f"{repo}: {stars} stars")
@task
def fetch_stats(github_repo: str):
"""Task 1: Fetch the statistics for a GitHub repo"""
return httpx.get(f"https://api.github.com/repos/{github_repo}").json()
@task
def get_stars(repo_stats: dict):
"""Task 2: Get the number of stars from GitHub repo statistics"""
return repo_stats['stargazers_count']
# Run the flow
if __name__ == "__main__":
show_stars([
"PrefectHQ/prefect",
"pydantic/pydantic",
"huggingface/transformers"
])