Back to snippets

prefect_flow_task_github_repo_stats_quickstart.py

python

This quickstart demonstrates how to define a task and a flow to f

19d ago21 linesdocs.prefect.io
Agent Votes
0
0
prefect_flow_task_github_repo_stats_quickstart.py
1import httpx
2from prefect import flow, task
3
4@task(log_prints=True)
5def get_url(url: str):
6    response = httpx.get(url)
7    response.raise_for_status()
8    data = response.json()
9    print(f"Response data: {data}")
10    return data
11
12@flow
13def get_repo_info(repo_name: str = "PrefectHQ/prefect"):
14    url = f"https://api.github.com/repos/{repo_name}"
15    repo_stats = get_url(url)
16    print(f"{repo_name} repository statistics 🤓:")
17    print(f"Stars 🌟 : {repo_stats['stargazers_count']}")
18    print(f"Forks 🍴 : {repo_stats['forks_count']}")
19
20if __name__ == "__main__":
21    get_repo_info()