# Storage
The Prefect Storage interface encapsulates logic for storing, serializing and even running Flows. Each storage unit is able to store multiple flows (possibly with the constraint of name uniqueness within a given unit), and exposes the following methods and attributes:
- a name attribute
- a
flows
attribute that is a dictionary of Flows -> location - an
add_flow(flow: Flow) -> str
method for adding flows to Storage, and that will return the location of the given flow in the Storage unit - the
__contains__(self, obj) -> bool
special method for determining whether the Storage contains a given Flow - one of
get_flow(flow_location: str)
orget_env_runner(flow_location: str)
for retrieving a way of interfacing with eitherflow.run
or aFlowRunner
for the flow;get_env_runner
is intended for situations where flow execution can only be interacted with via environment variables - a
build() -> Storage
method for "building" the storage - a
serialize() -> dict
method for serializing the relevant information about this Storage for later re-use.
# Docker
class
prefect.environments.storage.docker.Docker
(registry_url=None, base_image=None, dockerfile=None, python_dependencies=None, image_name=None, image_tag=None, env_vars=None, files=None, prefect_version=None, local_image=False, ignore_healthchecks=False, secrets=None, base_url=None, tls_config=False, build_kwargs=None)[source]Docker storage provides a mechanism for storing Prefect flows in Docker images and optionally pushing them to a registry.
A user specifies a registry_url
, base_image
and other optional dependencies (e.g., python_dependencies
) and build()
will create a temporary Dockerfile that is used to build the image.
Note that the base_image
must be capable of pip
installing. Note that registry behavior with respect to image names can differ between providers - for example, Google's GCR registry allows for registry URLs of the form gcr.io/my-registry/subdir/my-image-name
whereas DockerHub requires the registry URL to be separate from the image name.
Args:
registry_url (str, optional)
: URL of a registry to push the image to; image will not be pushed if not providedbase_image (str, optional)
: the base image for this environment (e.g.python:3.6
), defaults to theprefecthq/prefect
image matching your python version and prefect core library version used at runtime.dockerfile (str, optional)
: a path to a Dockerfile to use in building this storage; note that, if provided, your present working directory will be used as the build contextpython_dependencies (List[str], optional)
: list of pip installable dependencies for the imageimage_name (str, optional)
: name of the image to use when building, populated with a UUID after buildimage_tag (str, optional)
: tag of the image to use when building, populated with a UUID after buildenv_vars (dict, optional)
: a dictionary of environment variables to use when buildingfiles (dict, optional)
: a dictionary of files to copy into the image when buildingprefect_version (str, optional)
: an optional branch, tag, or commit specifying the version of prefect you want installed into the container; defaults to the version you are currently using or"master"
if your version is ahead of the latest taglocal_image (bool, optional)
: an optional flag whether or not to use a local docker image, if True then a pull will not be attemptedignore_healthchecks (bool, optional)
: if True, the Docker healthchecks are not added to the Dockerfile. If False (default), healthchecks are included.secrets (List[str], optional)
: a list of Prefect Secrets which will be used to populateprefect.context
for each flow run. Used primarily for providing authentication credentials.base_url (str, optional)
: a URL of a Docker daemon to use when for Docker related functionality. Defaults to DOCKER_HOST env var if not settls_config (Union[bool, docker.tls.TLSConfig], optional)
: a TLS configuration to pass to the Docker client. Documentationbuild_kwargs (dict, optional)
: Additional keyword arguments to pass to Docker's build step. Documentation
ValueError
: if bothbase_image
anddockerfile
are provided
methods: |
---|
prefect.environments.storage.docker.Docker.add_flow (flow)[source] |
Method for adding a new flow to this Storage object.
|
prefect.environments.storage.docker.Docker.build (push=True)[source] |
Build the Docker storage object. If image name and tag are not set, they will be autogenerated.
|
prefect.environments.storage.docker.Docker.create_dockerfile_object (directory)[source] |
Writes a dockerfile to the provided directory using the specified arguments on this Docker storage object.
|
prefect.environments.storage.docker.Docker.get_env_runner (flow_location)[source] |
Given a flow_location within this Storage object, returns something with a
|
prefect.environments.storage.docker.Docker.get_flow (flow_location)[source] |
Given a file path within this Docker container, returns the underlying Flow. Note that this method should only be run within the container itself.
|
prefect.environments.storage.docker.Docker.pull_image ()[source] |
Pull the image specified so it can be built.
|
prefect.environments.storage.docker.Docker.push_image (image_name, image_tag)[source] |
Push this environment to a registry
|
# Local
Local storage class. This class represents the Storage interface for Flows stored as bytes in the local filesystem.
Note that if you register a Flow with Prefect Cloud using this storage, your flow's environment will automatically be labeled with your machine's hostname. This ensures that only agents that are known to be running on the same filesystem can run your flow.
Args:
directory (str, optional)
: the directory the flows will be stored in; defaults to~/.prefect/flows
. If it doesn't already exist, it will be created for you.validate (bool, optional)
: a boolean specifying whether to validate the provided directory path; ifTrue
, the directory will be converted to an absolute path and created. Defaults toTrue
secrets (List[str], optional)
: a list of Prefect Secrets which will be used to populateprefect.context
for each flow run. Used primarily for providing authentication credentials.
methods: |
---|
prefect.environments.storage.local.Local.add_flow (flow)[source] |
Method for storing a new flow as bytes in the local filesytem.
|
prefect.environments.storage.local.Local.build ()[source] |
Build the Storage object.
|
prefect.environments.storage.local.Local.get_flow (flow_location)[source] |
Given a flow_location within this Storage object, returns the underlying Flow (if possible).
|
# S3
class
prefect.environments.storage.s3.S3
(bucket, client_options=None, key=None, secrets=None)[source]S3 storage class. This class represents the Storage interface for Flows stored as bytes in an S3 bucket.
This storage class optionally takes a key
which will be the name of the Flow object when stored in S3. If this key is not provided the Flow upload name will take the form slugified-flow-name/slugified-current-timestamp
.
Note: Flows registered with this Storage option will automatically be labeled with s3-flow-storage
.
Args:
bucket (str)
: the name of the S3 Bucket to store Flowskey (str, optional)
: a unique key to use for uploading a Flow to S3. This is only useful when storing a single Flow using this storage object.client_options (dict, optional)
: Additional options for theboto3
client.secrets (List[str], optional)
: a list of Prefect Secrets which will be used to populateprefect.context
for each flow run. Used primarily for providing authentication credentials.
methods: |
---|
prefect.environments.storage.s3.S3.add_flow (flow)[source] |
Method for storing a new flow as bytes in the local filesytem.
|
prefect.environments.storage.s3.S3.build ()[source] |
Build the S3 storage object by uploading Flows to an S3 bucket. This will upload all of the flows found in
|
prefect.environments.storage.s3.S3.get_flow (flow_location)[source] |
Given a flow_location within this Storage object, returns the underlying Flow (if possible). If the Flow is not found an error will be logged and
|
# GCS
GoogleCloudStorage storage class. This class represents the Storage interface for Flows stored as bytes in an GCS bucket. To authenticate with Google Cloud, you need to ensure that your Prefect Agent has the proper credentials available (see https://cloud.google.com/docs/authentication/production for all the authentication options).
This storage class optionally takes a key
which will be the name of the Flow object when stored in GCS. If this key is not provided the Flow upload name will take the form slugified-flow-name/slugified-current-timestamp
.
Note: Flows registered with this Storage option will automatically be labeled with gcs-flow-storage
.
Args:
bucket (str, optional)
: the name of the GCS Bucket to store the Flowkey (str, optional)
: a unique key to use for uploading this Flow to GCS. This is only useful when storing a single Flow using this storage object.project (str, optional)
: the google project where any GCS API requests are billed to; if not provided, the project will be inferred from your Google Cloud credentials.secrets (List[str], optional)
: a list of Prefect Secrets which will be used to populateprefect.context
for each flow run. Used primarily for providing authentication credentials.
methods: |
---|
prefect.environments.storage.gcs.GCS.add_flow (flow)[source] |
Method for storing a new flow as bytes in a GCS bucket.
|
prefect.environments.storage.gcs.GCS.build ()[source] |
Build the GCS storage object by uploading Flows to an GCS bucket. This will upload all of the flows found in
|
prefect.environments.storage.gcs.GCS.get_flow (flow_location)[source] |
Given a flow_location within this Storage object, returns the underlying Flow (if possible).
|
# Azure
class
prefect.environments.storage.azure.Azure
(container, connection_string=None, blob_name=None, secrets=None)[source]Azure Blob storage class. This class represents the Storage interface for Flows stored as bytes in an Azure container.
This storage class optionally takes a blob_name
which will be the name of the Flow object when stored in Azure. If this key is not provided the Flow upload name will take the form slugified-flow-name/slugified-current-timestamp
.
Note: Flows registered with this Storage option will automatically be labeled with azure-flow-storage
.
Args:
container (str)
: the name of the Azure Blob Container to store the Flowconnection_string (str, optional)
: an Azure connection string for communicating with Blob storage. If not provided the value set in the environment asAZURE_STORAGE_CONNECTION_STRING
will be usedblob_name (str, optional)
: a unique key to use for uploading this Flow to Azure. This is only useful when storing a single Flow using this storage object.secrets (List[str], optional)
: a list of Prefect Secrets which will be used to populateprefect.context
for each flow run. Used primarily for providing authentication credentials.
methods: |
---|
prefect.environments.storage.azure.Azure.add_flow (flow)[source] |
Method for storing a new flow as bytes in an Azure Blob container.
|
prefect.environments.storage.azure.Azure.build ()[source] |
Build the Azure storage object by uploading Flows to an Azure Blob container. This will upload all of the flows found in
|
prefect.environments.storage.azure.Azure.get_flow (flow_location)[source] |
Given a flow_location within this Storage object, returns the underlying Flow (if possible).
|
This documentation was auto-generated from commit n/a
on June 17, 2020 at 17:27 UTC