<@ULVA73B9P> Provide an example for default_storag...
# ask-marvin
m
@Marvin Provide an example for default_storage_block with a local filesystem block.
m
thought for 376.9 seconds
Here’s a minimal, end‑to‑end example of configuring
results.default_storage_block
to use a LocalFileSystem block in Prefect 3.x. 1) Create and save a LocalFileSystem block
Copy code
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
Copy code
prefect config set results.default_storage_block="local-file-system/local-results"
prefect config set results.persist_by_default=true
- Or via environment variables
Copy code
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
Copy code
[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)
Copy code
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