Gunnar
10/23/2024, 1:50 AMprefect server start
I export the API URL ( I am on osx )
export PREFECT_API_URL="<http://localhost:4200/api>"
This is the code I run locally
import httpx # an HTTP client library and dependency of Prefect
from prefect import flow, task
@task(retries=2)
def get_repo_info(repo_owner: str, repo_name: str):
"""Get info about a repo - will retry twice after failing"""
url = f"<https://api.github.com/repos/{repo_owner}/{repo_name}>"
api_response = httpx.get(url)
api_response.raise_for_status()
repo_info = api_response.json()
return repo_info
@task
def get_contributors(repo_info: dict):
"""Get contributors for a repo"""
contributors_url = repo_info["contributors_url"]
response = httpx.get(contributors_url)
response.raise_for_status()
contributors = response.json()
return contributors
@flow(log_prints=True)
def log_repo_info(repo_owner: str = "PrefectHQ", repo_name: str = "prefect"):
"""
Given a GitHub repository, logs the number of stargazers
and contributors for that repo.
"""
repo_info = get_repo_info(repo_owner, repo_name)
print(f"Stars 🌠 : {repo_info['stargazers_count']}")
contributors = get_contributors(repo_info)
print(f"Number of contributors 👷: {len(contributors)}")
if __name__ == "__main__":
log_repo_info()
This is what I get in the logs
18:39:02.707 | INFO | prefect.engine - Created flow run 'smoky-perch' for flow 'log-repo-info'
18:39:02.708 | INFO | prefect.engine - View at <http://localhost:4200/runs/flow-run/d63d462d-e83d-409c-aa7d-bc03193150fe>
18:39:03.051 | INFO | Task run 'get_repo_info-168' - Finished in state Completed()
18:39:03.058 | INFO | Flow run 'smoky-perch' - Stars 🌠 : 16204
18:39:03.412 | INFO | Task run 'get_contributors-b97' - Finished in state Completed()
18:39:03.414 | INFO | Flow run 'smoky-perch' - Number of contributors 👷: 30
18:39:03.448 | INFO | Flow run 'smoky-perch' - Finished in state Completed()
This is what I get at the URL :
<http://localhost:4200/runs/flow-run/d63d462d-e83d-409c-aa7d-bc03193150fe>
Adri
10/23/2024, 6:08 AMGunnar
10/23/2024, 9:01 AMGunnar
10/23/2024, 9:26 AMAdri
10/23/2024, 9:26 AMsudo apt install sqlite3
Adri
10/23/2024, 9:26 AM