hello, in Prefect 2.0 I’ve defined a new custom bl...
# prefect-community
r
hello, in Prefect 2.0 I’ve defined a new custom block as described in https://orion-docs.prefect.io/concepts/blocks/#creating-blocks. Once I’ve defined the model, is there a way to upload the definition of the block in Prefect cloud without having to create a block instance from code and the save it? I mean, I want to be able to see in the UI the new custom block definition without having to define a dummy instance of it
and connected to this question, how can I delete from Prefect cloud a definition of a custom block?
a
Hey @Riccardo Tesselli, great questions! Currently, the best way to register a custom block without saving it is to use the
register_type_and_schema
method. Here’s an example:
Copy code
from prefect.blocks.core import Block

class Custom(Block):
    value: str

Custom.register_type_and_schema()
Running this script will register the
Custom
block for configuration in the UI. We’re working on building out the capability to register blocks via the CLI, so this process should improve in the future. For deleting custom block types, you’ll need to use the REST API for now. Here’s a link to the documentation for the endpoint that handles deleting block types: https://orion-docs.prefect.io/api-ref/rest-api/#/Block%20types/delete_block_type_block_types__id__delete.
r
thank you @alex!
just un update. The code example you provided gave me an error (coro was never awaited). This is how I’ve done:
Copy code
asyncio.run(Custom.register_type_and_schema())
a
@Riccardo Tesselli if you wait 1-2 weeks, it's very likely that the CLI for this will already exist
🎉 1