Martijn Sanderse
09/05/2025, 10:54 AMMarvin
09/05/2025, 10:55 AMMarvin
09/05/2025, 11:01 AMresults.default_storage_block
to use a LocalFileSystem block in Prefect 3.x.
1) Create and save a LocalFileSystem block
from prefect.filesystems import LocalFileSystem
# Point this to where you want results written
fs = LocalFileSystem(basepath="/opt/prefect/results")
fs.save("local-results", overwrite=True)
2) Tell Prefect to use that block by default (and optionally persist results by default)
- Via CLI
prefect config set results.default_storage_block="local-file-system/local-results"
prefect config set results.persist_by_default=true
- Or via environment variables
export PREFECT_RESULTS__DEFAULT_STORAGE_BLOCK="local-file-system/local-results"
export PREFECT_RESULTS__PERSIST_BY_DEFAULT=true
- Or in your prefect.toml (profile) configuration
[results]
default_storage_block = "local-file-system/local-results"
persist_by_default = true
3) Use it in a flow (results will be written to your LocalFileSystem basepath)
from prefect import flow, task
@task(persist_result=True) # or rely on results.persist_by_default=true
def add(x, y):
return x + y
@flow
def my_flow():
return add(1, 2)
if __name__ == "__main__":
my_flow()
Notes:
- The setting value format is "<block_type_slug>/<block_name>". For LocalFileSystem, the type slug is local-file-system
, so "local-file-system/local-results"
in this example.
- Make sure the path you set in basepath
exists and is writable wherever your flow runs (e.g., worker/container/VM).
- You can override storage at the task/flow level with result_storage
if needed, but the setting above provides a global default.
Docs for reference:
- Results (Prefect 3.x)
- prefect.filesystems API