Hi, can I use blocks defined in the cloud for loca...
# prefect-community
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.
Hey @Michael Hadorn !! You can load blocks from cloud into your code by using the load function. An example can be found here: https://docs.prefect.io/concepts/blocks/#loading-blocks
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:
Copy code
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(**my_config_block.data)
        await new_block.save('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