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
Riccardo Tesselli
07/19/2022, 1:21 PM
and connected to this question, how can I delete from Prefect cloud a definition of a custom block?
a
alex
07/19/2022, 2:00 PM
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
Riccardo Tesselli
07/19/2022, 2:33 PM
thank you @alex!
Riccardo Tesselli
07/19/2022, 3:07 PM
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
Anna Geller
07/19/2022, 11:18 PM
@Riccardo Tesselli if you wait 1-2 weeks, it's very likely that the CLI for this will already exist
Bring your towel and join one of the fastest growing data communities. Welcome to our second-generation open source orchestration platform, a completely rethought approach to dataflow automation.