Please see the this guide if you need assistance creating a Python virtual environment.
Much of Prefect's functionality is backed by an API. Sign up for a forever free Prefect Cloud account or accept your organization's invite to join their Prefect Cloud account. To access Prefect's UI, head to our SSO login page to sign in to Prefect Cloud.
Sign in with SSO
to avoid creating a duplicate account.
Now that you've logged into the cloud UI, we need to set up your local dev environment so that you can author flows.
For more info see our Install Guide!
pip install -U prefect
Check that you have a recent version:
prefect version
3. Log in to Cloud from a terminal
prefect cloud login
Select Log in with a web browser
Find trouble shooting tips for login errors here!
4. Change Workspaces to your workspace of choice
prefect cloud workspace set
Then select the desired workspace from list if there is more than one, press enter if there is only one.
5. Run a hello world flow and verify that you can see the flow run in the UI
pacc2024/hello_world_flow.py
from prefect import flow
@flow(log_prints=True)
def hello_world():
print("Hello world!")
if __name__ == "__main__":
hello_world()
python pacc2024/hello_world_flow.py
Click on the link listed in the flow run logs:
(venv) ➜ prefect-pacc-2024 git:(main) python hello_world_flow.py
09:23:52.648 | INFO | prefect.engine - Created flow run 'noisy-frog' for flow 'hello-world'
09:23:52.650 | INFO | Flow run 'noisy-frog' - View at https://app.prefect.cloud/account/9b649228-0419-40e1-9e0d-44954b5c0ab6/workspace/f7fe0729-5a91-40a4-a800-4bb8c5b6a6f5/flow-runs/flow-run/ea412cbd-9878-41e6-9e36-0be279230875
09:23:52.867 | INFO | Flow run 'noisy-frog' - Hello world!
09:23:53.393 | INFO | Flow run 'noisy-frog' - Finished in state Completed()
In the UI, you should see a flow run with a randomly generated adjective-animal name that has no tasks:
🎉 Congrats! You're all set to start diving in and learning Prefect!
(Optional) Prefect Profiles
Prefect allows you to persist settings instead of setting an environment variable each time you open a new shell. Settings are persisted to profiles, which allow you to move between groups of settings quickly.
To create a profile:
prefect profile create test
To switch to a selected profile:
prefect profile use test
Profiles are stored by default in your PREFECT_HOME directory:
vim ~/.prefect/profiles.toml
Example profiles.toml
file:
active = "default"
[profiles.local]
PREFECT_API_URL = "http://127.0.0.1:4200/api"
[profiles.default]
PREFECT_API_KEY = "pnu_----replace-me----"
PREFECT_API_URL = "https://api.prefect.cloud/api/accounts/--replace-me--/workspaces/--replace-me--"
[profiles.staging]
PREFECT_API_KEY = "pnu_----replace-me----"
PREFECT_API_URL = "https://api.prefect.cloud/api/accounts/--replace-me--/workspaces/--staging-workspace-replace-me--"
PREFECT_LOGGING_LEVEL = "DEBUG"
[profiles.n]
PREFECT_API_KEY = "pnu_----replace-me----"
PREFECT_API_URL = "https://api.prefect.cloud/api/accounts/--replace-me--/workspaces/--n-workspace-replace-me--"