Results represent the data returned by a flow or a task and enable features such as caching.
PREFECT_RESULTS_PERSIST_BY_DEFAULT
setting:PREFECT_RESULTS_PERSIST_BY_DEFAULT
setting, and the PREFECT_TASKS_DEFAULT_PERSIST_RESULT
setting for tasks specifically.result_storage
keyword and the PREFECT_DEFAULT_RESULT_STORAGE_BLOCK
setting.result_serializer
keyword and the PREFECT_RESULTS_DEFAULT_SERIALIZER
setting.result_storage_key
, cache_policy
, or cache_key_fn
.PREFECT_RESULTS_PERSIST_BY_DEFAULT
setting or
through any of the mechanisms described below - Prefect’s default
result storage configuration is activated.
If you enable result persistence and don’t specify a filesystem block, your results will be stored locally.
By default, results are persisted to ~/.prefect/storage/
.
You can configure the location of these results through the PREFECT_LOCAL_STORAGE_PATH
setting.
PREFECT_RESULTS_PERSIST_BY_DEFAULT
and PREFECT_TASKS_DEFAULT_PERSIST_RESULT
settings,
result persistence can also be enabled or disabled on both individual flows and individual tasks.
Specifying a non-null value for any of the following keywords on the task decorator will enable result
persistence for that task:
persist_result
: a boolean that allows you to explicitly enable or disable result persistence.result_storage
: accepts either a string reference to a storage block or a storage block class that
specifies where results should be stored.result_storage_key
: a string that specifies the filename of the result within the task’s result storage.result_serializer
: a string or serializer that configures how the data should be serialized and deserialized.cache_policy
: a cache policy specifying the behavior of the task’s cache.cache_key_fn
: a function that configures a custom cache policy.persist_result=True
, result_storage
, or result_serializer
on a flow will enable
persistence for that flow.
PREFECT_TASKS_DEFAULT_PERSIST_RESULT
environment variable can be used to globally control the default persistence behavior for tasks, overriding the default behavior set by a parent flow or task.result_storage
keyword argument.
This keyword accepts an instantiated filesystem block, or a block slug. Find your blocks’ slugs with prefect block ls
.
Note that if you want your tasks to share a common cache, your result storage should be accessible by
the infrastructure in which those tasks run. Integrations have cloud-specific storage blocks.
For example, a common distributed filesystem for result storage is AWS S3.
Additionally, you can control the default persistence behavior for task results using the default_persist_result
setting. This setting allows you to specify whether results should be persisted by default for all tasks. You can set this to True
to enable persistence by default, or False
to disable it. This setting can be overridden at the individual task or flow level.
PREFECT_DEFAULT_RESULT_STORAGE_BLOCK
setting.
Specifying a block document slug here will enable result persistence using that filesystem as the default.
For example:
result_storage
on either a flow or task will override this default.result_storage_key
: a templated string that can use any of the fields within prefect.runtime
and
the task’s individual parameter values. These templated values will be populated at runtime.cache_key_fn
: a function that accepts the task run context and its runtime parameters and returns
a string. See task caching documentation for more information.result_storage_key
and cache_key_fn
are provided, only the result_storage_key
will be used.name
parameter passed to the task:
result_serializer
keyword on both tasks and flows.
A default value can be set using the PREFECT_RESULTS_DEFAULT_SERIALIZER
setting, which defaults to pickle
.
Current built-in options include "pickle"
, "json"
, "compressed/pickle"
and "compressed/json"
.
The result_serializer
accepts both a string identifier or an instance of a ResultSerializer
class, allowing
you to customize serialization behavior.
cache_result_in_memory
: