Skip to content

Commit

Permalink
Merge branch 'main' into jean/oss-85-support-deploymentconcurrency_li…
Browse files Browse the repository at this point in the history
…mit-in-flowserve
  • Loading branch information
abrookins authored Aug 28, 2024
2 parents 3e651b1 + f893077 commit a5a3120
Showing 1 changed file with 42 additions and 51 deletions.
93 changes: 42 additions & 51 deletions docs/3.0rc/get-started/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,23 @@ if __name__ == "__main__":
<Installation />

<Tip>
If needed, see [Install Prefect](/3.0rc/get-started/install/) for other options.
See [Install Prefect](/3.0rc/get-started/install/) for more details on installation.
</Tip>

## Connect to Prefect's API
## Connect to a Prefect API

Connect to the Prefect API, either Prefect Cloud hosted by us, or a self-hosted Prefect server that you maintain:
Connect to a Prefect API:

<Tabs>
<Tab title="Self-hosted">
1. Start a local API server:

```bash
prefect server start
```

1. Open the Prefect dashboard in your browser at [http://localhost:4200](http://localhost:4200).
</Tab>
<Tab title="Prefect Cloud">
1. Head to [https://app.prefect.cloud/](https://app.prefect.cloud/) and sign in or create a forever-free Prefect Cloud account.
1. Log in to Prefect Cloud from your development environment:
Expand All @@ -50,32 +59,16 @@ Your CLI is now authenticated with your Prefect Cloud account through a locally

If you have any issues with browser-based authentication, you can [authenticate with a manually created API key](/3.0rc/manage/cloud/manage-users/api-keys/) instead.
</Tab>
<Tab title="Local server">
1. Ensure your current profile isn't authenticated to Prefect Cloud:

```bash
prefect cloud logout
```

1. Start a local API server:

```bash
prefect server start
```

1. Open the Prefect dashboard in your browser at [http://localhost:4200](http://localhost:4200).
</Tab>
</Tabs>

## Convert your script to a Prefect workflow

The easiest way to convert a Python script into a workflow is to add a `@flow` decorator to the script's entrypoint, the Python function that runs first.
[Flows](/3.0rc/develop/write-flows/) are containers for workflow logic as code.
They're the core observable, orchestrated, deployable units of work in Prefect.
The easiest way to convert a Python script into a workflow is to add a `@flow` decorator to the script's entrypoint.
This will create a corresponding [flow](/3.0rc/develop/write-flows/).

Adding `@task` decorators to the functions called by the flow converts them to tasks.
Adding `@task` decorators to any functions called by the flow converts them to [tasks](/3.0rc/develop/write-tasks/).
Tasks receive metadata about upstream dependencies and the state of those dependencies before they run.
Prefect will record these dependencies and states as it orchestrates these tasks when they run.
Prefect will then record these dependencies and states as it orchestrates these tasks.

```python my_gh_workflow.py
import httpx # an HTTP client library and dependency of Prefect
Expand Down Expand Up @@ -116,18 +109,18 @@ if __name__ == "__main__":
```

<Note>
The `log_prints=True` argument provided to the `@flow` decorator logs output from `print` statements within the function.
The `log_prints=True` argument provided to the `@flow` decorator automatically converts any `print` statements within the function to `INFO` level logs.
</Note>

## Run your flow

Run your Prefect flow just as you would a Python script:
You can run your Prefect flow just as you would a Python script:

```bash
python my_gh_workflow.py
```

Prefect automatically tracks the state of the flow run and logs the output in the UI and CLI.
Prefect automatically tracks the state of the flow run and logs the output, which can be viewed directly in the terminal or in the UI.

```bash
14:28:31.099 | INFO | prefect.engine - Created flow run 'energetic-panther' for flow 'repo-info'
Expand All @@ -145,28 +138,16 @@ Prefect automatically tracks the state of the flow run and logs the output in th

## Create a work pool

Running a flow locally is a good start, but you should use a remote destination for production flows.
A [work pool](/3.0rc/deploy/infrastructure-concepts/work-pools/) is the most common way to do this.
Running a flow locally is a good start, but most use cases require a remote execution environment.
A [work pool](/3.0rc/deploy/infrastructure-concepts/work-pools/) is the most common interface for deploying flows to remote infrastructure.

<Tabs>
<Tab title="Prefect Cloud">
Deploy your flow to Cloud using a managed work pool.
<Tab title="Self-hosted">

1. Create a [managed work pool](/3.0rc/deploy/infrastructure-concepts/work-pools):
Deploy your flow to a self-hosted Prefect server instance using a `Process` work pool.
All flow runs submitted to this work pool will run in a local subprocess (the mechanics are similar for other work pool types that run on remote infrastructure).

```bash
prefect work-pool create my-work-pool --type prefect:managed
```

1. View your new work pool on the **Work Pools** page of the UI.
</Tab>

<Tab title="Local server">

Deploy your flow to a self-hosted Prefect server instance using a Process type work pool.
This flow will run in a local subprocess, but the mechanics are similar for other work pool types that run on remote infrastructure.

1. Create a Process type work pool:
1. Create a `Process` work pool:

```bash
prefect work-pool create --type process my-work-pool
Expand All @@ -184,18 +165,30 @@ This flow will run in a local subprocess, but the mechanics are similar for othe
prefect worker start --pool my-work-pool
```

</Tab>
<Tab title="Prefect Cloud">
Deploy your flow to Prefect Cloud using a managed work pool.

1. Create a [managed work pool](/3.0rc/deploy/infrastructure-concepts/work-pools):

```bash
prefect work-pool create my-work-pool --type prefect:managed
```

1. View your new work pool on the **Work Pools** page of the UI.
</Tab>
</Tabs>

<Tip>
You can also choose from other [work pool types](https://docs.prefect.io/concepts/work-pools/#worker-types).
</Tip>
</Tab>
</Tabs>

## Deploy and schedule your flow

A [deployment](/3.0rc/deploy/infrastructure-examples/docker/) is used to determine when, where, and how a flow function should run.
A [deployment](/3.0rc/deploy/infrastructure-examples/docker/) is used to determine when, where, and how a flow should run.
Deployments elevate flows to remotely configurable entities that have their own API.

1. Create a deployment script:
1. Create a deployment in code:

```bash create_deployment.py
from prefect import flow
Expand Down Expand Up @@ -244,12 +237,10 @@ Deployments elevate flows to remotely configurable entities that have their own
prefect deployment run 'repo-info/my-first-deployment'
```

After a minute or so, you should see the flow run graph and logs on the Flow Run page in the UI.
Soon you should see the flow run graph and logs on the Flow Run page in the UI.

![Flow run graph and logs](/3.0rc/img/ui/qs-flow-run.png)

1. When you're done, click the **More** > **Delete** button on the **Deployments** page to stop further scheduled runs.

## Next steps

You've seen how to move from a Python script to a scheduled, observable, remotely orchestrated workflow with Prefect.
Expand Down

0 comments on commit a5a3120

Please sign in to comment.