Michael Hadorn

09/28/2022, 5:48 AM
Hi, can I use blocks defined in the cloud for local filesystem runs (developing)? Or do I have to setup all blocks locally, to let it run? I would like to do a local run, but using all blocks from the cloud.

Rob Freedy

09/28/2022, 12:46 PM
Hey @Michael Hadorn !! You can load blocks from cloud into your code by using the load function. An example can be found here:

Michael Hadorn

09/29/2022, 5:11 AM
Hey @Rob Freedy Thanks for your answer. I was more thinking of using cloud blocks in the local enviroment. So that i don't have to reconfigure config blocks for every local development. But i figured out, how to copy cloud block to the local instance:
import asyncio
from prefect.client import get_client
from prefect.settings import PREFECT_API_URL, temporary_settings

from blocks.my_config import MyConfig

async def do_work():
    # this loades the cloud client (defined via active profile -> PREFECT_API_URL)
    client_cloud = get_client()
    my_config_block = await client_cloud.read_block_document_by_name('dev', block_type_slug='my-config')

    # switch to local instance: will set PREFECT_API_URL to empty
    with temporary_settings(restore_defaults={PREFECT_API_URL}):
        # everything here will be done in local instance.
        new_block = MyConfig(**
        await'dev', True)

if __name__ == "__main__":
So this solve my problem. Maybe I could also solve my request, if I would read the blocks from cloud similar i load in this code from local instance.
👍 1