Prefect tasks and subflows for interacting with Google Cloud Platform.
Project description
prefect-gcp
Welcome!
prefect-gcp
is a collection of prebuilt Prefect tasks that can be used to quickly construct Prefect flows.
Getting Started
Python setup
Requires an installation of Python 3.7+.
We recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.
These tasks are designed to work with Prefect 2.0. For more information about how to use Prefect, please refer to the Prefect documentation.
Installation
To use prefect-gcp
and Cloud Run:
pip install prefect-gcp
To use Cloud Storage:
pip install "prefect-gcp[cloud_storage]"
To use BigQuery:
pip install "prefect-gcp[bigquery]"
To use Secret Manager:
pip install "prefect-gcp[secret_manager]"
Then, register to view the blocks on Prefect Cloud:
prefect block register -m prefect_gcp.credentials
prefect block register -m prefect_gcp.cloud_run
Note, to use the load
method on Blocks, you must already have a block document saved through code or saved through the UI.
Download blob from bucket
from prefect import flow
from prefect_gcp import GcpCredentials
from prefect_gcp.cloud_storage import cloud_storage_download_blob_as_bytes
@flow
def cloud_storage_download_blob_flow():
gcp_credentials = GcpCredentials(
service_account_file="/path/to/service/account/keyfile.json")
contents = cloud_storage_download_blob_as_bytes("bucket", "blob", gcp_credentials)
return contents
cloud_storage_download_blob_flow()
Deploy command on Cloud Run
Save the following as prefect_gcp_flow.py
:
from prefect import flow
from prefect_gcp import GcpCredentials
from prefect_gcp.cloud_run import CloudRunJob
@flow
def cloud_run_job_flow():
cloud_run_job = CloudRunJob(
image="us-docker.pkg.dev/cloudrun/container/job:latest",
credentials=GcpCredentials.load("MY_BLOCK_NAME"),
region="us-central1",
command=["echo", "hello world"],
)
return cloud_run_job.run()
Deploy prefect_gcp_flow.py
:
from prefect.deployments import Deployment
from prefect_gcp_flow import cloud_run_job_flow
deployment = Deployment.build_from_flow(
flow=cloud_run_job_flow,
name="cloud_run_job_deployment",
version=1,
work_queue_name="demo",
)
deployment.apply()
Run the deployment either on the UI or through the CLI:
prefect deployment run cloud-run-job-flow/cloud_run_job_deployment
Visit Prefect Deployments for more information about deployments.
Resources
If you encounter any bugs while using prefect-gcp
, feel free to open an issue in the prefect-gcp repository.
If you have any questions or issues while using prefect-gcp
, you can find help in either the Prefect Discourse forum or the Prefect Slack community.
Feel free to ⭐️ or watch prefect-gcp
for updates too!
Development
If you'd like to install a version of prefect-gcp
for development, clone the repository and perform an editable install with pip
:
git clone https://github.com/PrefectHQ/prefect-gcp.git
cd prefect-gcp/
pip install -e ".[dev]"
# Install linting pre-commit hooks
pre-commit install
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for prefect_gcp-0.1.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83b4723f015063a6245ca636d301a69e4c0b8904ea1cf8376c96ecb0f626a994 |
|
MD5 | 5d19eb0c38def32f96d5f3734abfb059 |
|
BLAKE2b-256 | ae60daf1339d6fa72193aeb2c5890e24005cd351dacd397367343a352b2afefb |