Hi everyone, is it possible to delete / remove a b...
# ask-community
a
Hi everyone, is it possible to delete / remove a block that was registered with an Orion server from Python code? Sort of the opposite of
my_block.save("my-block-slug")
Or perhaps an
.archive()
command like was possible for workflows in Prefect 1?
s
Hi, in our project, we had the same needs, in order to do so from Python code, we used the Prefect REST API endpoint
api/block_documents/{block_id}
because indeed
block.delete("my-block-slug")
does not exist, it looks like the following snippet. You need to capture the
block_id
from the result of save() function call
Copy code
import requests
from prefect.settings import PREFECT_ORION_API_HOST, PREFECT_ORION_API_PORT
my_block_id = block.save("my-block-slug")
api_host = PREFECT_ORION_API_HOST
api_port = PREFECT_ORION_API_PORT
delete_block_api = f"http://{api_host}:{api_port}/api/block_documents/{my_block_id}"
response = requests.delete(delete_block_api)
response.raise_for_status()
It does the job for our use case but not sure if there is a better way
a
Frankly that documentation link is a bit bare.
r
yeah the api's/features are moving quick, very hard for them to keep up
👍 2