forked from qodo-benchmark/prefect
-
Notifications
You must be signed in to change notification settings - Fork 0
Add documentation for prefect sdk generate CLI #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tomerqodo
wants to merge
8
commits into
coderabbit_full_base_add_documentation_for_prefect_sdk_generate_cli_pr1
Choose a base branch
from
coderabbit_full_head_add_documentation_for_prefect_sdk_generate_cli_pr1
base: coderabbit_full_base_add_documentation_for_prefect_sdk_generate_cli_pr1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
544ae48
Add documentation for prefect sdk generate CLI
desertaxle cfbaa0f
Revert unrelated CLI doc regeneration
desertaxle 8c5bd5c
Skip markdown doc tests for SDK how-to guide
desertaxle 0611e54
Rename page
desertaxle 17a4233
Rewrite SDK how-to guide to match docs style
desertaxle ce6ecab
Rewrite custom SDK how-to guide to match docs style
desertaxle 17c7fab
Move custom SDK guide to Advanced section
desertaxle 37e272d
update pr
tomerqodo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| --- | ||
| title: How to generate a custom SDK for your deployments | ||
| sidebarTitle: Generate a Custom SDK | ||
| description: Generate a custom Python SDK from your deployments for IDE autocomplete and type checking. | ||
| --- | ||
|
|
||
| The `prefect sdk generate` command creates a typed Python file from your [deployments](/v3/concepts/deployments). This gives you IDE autocomplete and static type checking when triggering deployment runs programmatically. | ||
|
|
||
| <Note> | ||
| This feature is in **beta**. APIs may change in future releases. | ||
| </Note> | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - An active Prefect API connection (Prefect Cloud or self-hosted server) | ||
| - At least one [deployment](/v3/how-to-guides/deployments/create-deployments) in your workspace | ||
|
|
||
| ## Generate an SDK from the CLI | ||
|
|
||
| Generate a typed SDK for all deployments in your workspace: | ||
|
|
||
| ```bash | ||
| prefect sdk generate --output ./my_sdk.py | ||
| ``` | ||
|
|
||
| ### Filter to specific flows or deployments | ||
|
|
||
| Generate an SDK for specific flows: | ||
|
|
||
| ```bash | ||
| prefect sdk generate --output ./my_sdk.py --flow my-etl-flow | ||
| ``` | ||
|
|
||
| Generate an SDK for specific deployments: | ||
|
|
||
| ```bash | ||
| prefect sdk generate --output ./my_sdk.py --deployment my-flow/production | ||
| ``` | ||
|
|
||
| Combine multiple filters: | ||
|
|
||
| ```bash | ||
| prefect sdk generate --output ./my_sdk.py \ | ||
| --flow etl-flow \ | ||
| --flow data-sync \ | ||
| --deployment analytics/daily | ||
| ``` | ||
|
|
||
| ## Run deployments with the generated SDK | ||
|
|
||
| The generated SDK provides a `deployments.from_name()` method that returns a typed deployment object: | ||
|
|
||
| {/* pmd-metadata: notest */} | ||
| ```python | ||
| from my_sdk import deployments | ||
|
|
||
| # Get a deployment by name | ||
| deployment = deployments.from_name("my-etl-flow/production") | ||
|
|
||
| # Run with parameters | ||
| future = deployment.run( | ||
| source="s3://my-bucket/data", | ||
| batch_size=100, | ||
| ) | ||
|
|
||
| # Get the flow run ID immediately | ||
| print(f"Started flow run: {future.flow_run_id}") | ||
|
|
||
| # Wait for completion and get result | ||
| result = future.result() | ||
| ``` | ||
|
|
||
| ### Configure run options | ||
|
|
||
| Use `with_options()` to set tags, scheduling, and other run configuration: | ||
|
|
||
| {/* pmd-metadata: notest */} | ||
| ```python | ||
| from my_sdk import deployments | ||
| from datetime import datetime, timedelta | ||
|
|
||
| future = deployments.from_name("my-etl-flow/production").with_options( | ||
| tags=["manual", "production"], | ||
| idempotency_key="daily-run-2024-01-15", | ||
| scheduled_time=datetime.now() + timedelta(hours=1), | ||
| flow_run_name="custom-run-name", | ||
| ).run( | ||
| source="s3://bucket", | ||
| ) | ||
| ``` | ||
|
|
||
| Available options: | ||
| - `tags`: Tags to apply to the flow run | ||
| - `idempotency_key`: Unique key to prevent duplicate runs | ||
| - `work_queue_name`: Override the work queue | ||
| - `as_subflow`: Run as a subflow of the current flow | ||
| - `scheduled_time`: Schedule the run for a future time | ||
| - `flow_run_name`: Custom name for the flow run | ||
|
|
||
| ### Override job variables | ||
|
|
||
| Use `with_infra()` to override work pool job variables: | ||
|
|
||
| {/* pmd-metadata: notest */} | ||
| ```python | ||
| from my_sdk import deployments | ||
|
|
||
| future = deployments.from_name("my-etl-flow/production").with_infra( | ||
| image="my-registry/my-image:latest", | ||
| cpu_request="2", | ||
| memory="8Gi", | ||
| ).run( | ||
| source="s3://bucket", | ||
| ) | ||
| ``` | ||
|
|
||
| The available job variables depend on your work pool type. The generated SDK provides type hints for the options available on each deployment's work pool. | ||
|
|
||
| ### Async usage | ||
|
|
||
| In an async context, use `run_async()`: | ||
|
|
||
| {/* pmd-metadata: notest */} | ||
| ```python | ||
| import asyncio | ||
| from my_sdk import deployments | ||
|
|
||
| async def trigger_deployment(): | ||
| future = await deployments.from_name("my-etl-flow/production").run_async( | ||
| source="s3://bucket", | ||
| ) | ||
| result = await future.result() | ||
| return result | ||
|
|
||
| # Run it | ||
| result = asyncio.run(trigger_deployment()) | ||
| ``` | ||
|
|
||
| ### Chain methods together | ||
|
|
||
| {/* pmd-metadata: notest */} | ||
| ```python | ||
| from my_sdk import deployments | ||
|
|
||
| future = ( | ||
| deployments.from_name("my-etl-flow/production") | ||
| .with_options(tags=["production"]) | ||
| .with_infra(memory="8Gi") | ||
| .run(source="s3://bucket", batch_size=100) | ||
| ) | ||
| ``` | ||
|
|
||
| ## Regenerate the SDK after changes | ||
|
|
||
| The SDK is generated from server-side metadata. Regenerate it when: | ||
| - Deployments are added, removed, or renamed | ||
| - Flow parameter schemas change | ||
| - Work pool job variable schemas change | ||
|
|
||
| The `generate` command overwrites the existing file: | ||
|
|
||
| ```bash | ||
| prefect sdk generate --output ./my_sdk.py | ||
| ``` | ||
|
|
||
| <Tip> | ||
| Add SDK regeneration to your CI/CD pipeline to keep it in sync with your deployments. | ||
| </Tip> | ||
|
|
||
| ## Further reading | ||
|
|
||
| - [Create deployments](/v3/how-to-guides/deployments/create-deployments) | ||
| - [Trigger ad-hoc deployment runs](/v3/how-to-guides/deployments/run-deployments) | ||
| - [Override job configuration](/v3/how-to-guides/deployments/customize-job-variables) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| --- | ||
| title: " " | ||
| sidebarTitle: prefect sdk | ||
| --- | ||
|
|
||
| # `prefect sdk` | ||
|
|
||
|
|
||
|
|
||
| ```command | ||
| prefect sdk [OPTIONS] COMMAND [ARGS]... | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
| <Info> | ||
| Manage Prefect SDKs. (beta) | ||
| </Info> | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| ## `prefect sdk generate` | ||
|
|
||
|
|
||
|
|
||
| ```command | ||
| prefect sdk generate [OPTIONS] | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
| <Info> | ||
| (beta) Generate a typed Python SDK from workspace deployments. | ||
|
|
||
| The generated SDK provides IDE autocomplete and type checking for your deployments. | ||
| Requires an active Prefect API connection (use `prefect cloud login` or configure | ||
| PREFECT_API_URL). | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the stray control character near Line 44. Line 44 contains a hidden control character (looks like a backspace). It can cause render or lint issues; please delete it. 🤖 Prompt for AI Agents |
||
| Examples: | ||
| Generate SDK for all deployments: | ||
| \$ prefect sdk generate --output ./my_sdk.py | ||
|
|
||
| Generate SDK for specific flows: | ||
| \$ prefect sdk generate --output ./my_sdk.py --flow my-etl-flow | ||
|
|
||
| Generate SDK for specific deployments: | ||
| \$ prefect sdk generate --output ./my_sdk.py --deployment my-flow/production | ||
| </Info> | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| <AccordionGroup> | ||
|
|
||
|
|
||
|
|
||
|
|
||
| <Accordion title="Options" defaultOpen> | ||
|
|
||
| <ResponseField name="--output"> | ||
| Output file path for the generated SDK. | ||
| </ResponseField> | ||
|
|
||
| <ResponseField name="--flow"> | ||
| Filter to specific flow(s). Can be specified multiple times. | ||
| </ResponseField> | ||
|
|
||
| <ResponseField name="--deployment"> | ||
| Filter to specific deployment(s). Can be specified multiple times. Use 'flow-name/deployment-name' format for exact matching. | ||
| </ResponseField> | ||
|
|
||
| </Accordion> | ||
|
|
||
| </AccordionGroup> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a descriptive
titlein frontmatter.Line 2 is a blank title; this yields empty page metadata. Consider a meaningful title for SEO and page headers.
🛠 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents