Tejas Shah
08/26/2025, 12:18 PMMarvin
08/26/2025, 12:18 PMMarvin
08/26/2025, 12:29 PMPREFECT_API_AUTH_STRING
for clients (or pass auth_string=
to PrefectClient). Make sure PREFECT_API_KEY
is NOT set, as it will take precedence and break auth for Server. See Security settings.
- If your workspaces are on different API URLs, just use different api=
values. If they’re on the same API URL but different workspaces, use whatever method you already use today to target a workspace (URL path vs header). If that’s unclear, I can help with the exact client config—just let me know how you currently select a workspace from code/CLI.
Scripted copy by block slug
- This works well from Jupyter and preserves secrets.
- It assumes the target workspace has the same block type registered (for built-in/integration blocks). For custom blocks, register them in the target first (example CLI shown below).
import asyncio
from prefect.client.orchestration import PrefectClient
from prefect.blocks.core import Block
async def copy_blocks(slugs, src_api, src_auth, dst_api, dst_auth, overwrite=False, validate=True):
async with PrefectClient(api=src_api, auth_string=src_auth) as src, \
PrefectClient(api=dst_api, auth_string=dst_auth) as dst:
for slug in slugs:
# slug format: "<block_type_slug>/<block_name>"
print(f"Copying {slug} ...")
block = await Block.load(slug, validate=validate, client=src)
block_name = slug.split("/", 1)[1]
await block.save(name=block_name, overwrite=overwrite, client=dst)
print("Done.")
# Example usage:
# Fill these in for your source/target workspaces
SRC_API = "<https://your-src-prefect/api>"
SRC_AUTH = "your-src-auth-string"
DST_API = "<https://your-dst-prefect/api>"
DST_AUTH = "your-dst-auth-string"
# List the slugs you want to move (from `prefect block ls` in the source)
SLUGS = [
"s3-bucket/raw-data",
"aws-credentials/prod",
"secret/service-token",
]
await copy_blocks(SLUGS, SRC_API, SRC_AUTH, DST_API, DST_AUTH, overwrite=False)
How to list the slugs to migrate
- In each workspace, you can list configured blocks:
prefect block ls
- To inspect the details of a specific block and confirm the slug:
prefect block inspect <BLOCK_TYPE_SLUG>/<BLOCK_NAME>
Registering block types in the target (only if you use custom or integration blocks)
- Register the block types your blocks depend on in the target workspace before copying. For example:
# Example: register AWS collection blocks
prefect block register -m prefect_aws.credentials
CLI help (verified):
- prefect block --help
- prefect block register --help
- prefect block ls --help
- prefect block inspect --help
Advanced/fully generic approach
- If you want to migrate “everything” without pre-listing slugs, you can iterate with the Python client:
- PrefectClient.read_block_documents(include_secrets=True)
to list block docs in the source, then for each, load via Block.load("<type>/<name>", client=src)
and save(...)
into the target.
- This still relies on the target workspace having matching block types/schemas. If not, register them first.
A couple of gotchas
- If a block of the same name already exists in the target, set overwrite=True
in save(...)
or delete it first.
- If schemas have drifted (e.g., old block versions), you can pass validate=False
to Block.load
to be more lenient.
- Do not log or print block contents that include secrets.
Docs and references
- Security and auth string: Security settings
- Workspaces overview: WorkspacesMarvin
08/26/2025, 12:29 PMBrendan Dalpe
08/26/2025, 3:15 PMBrendan Dalpe
08/26/2025, 3:18 PMTejas Shah
08/26/2025, 8:16 PM