https://prefect.io logo
Title
m

mondras

05/22/2023, 10:31 PM
@Marvin is there a way of creating a block object from querying the api such as an object mapper?
m

Marvin

05/22/2023, 10:33 PM
Edited by @Nate: I've found some information that might be helpful for you. In Prefect, blocks are a primitive that enables the storage of configuration and provides an interface for interacting with external systems. You can securely store credentials for authenticating with services like AWS, GitHub, Slack, and any other system you'd like to orchestrate with Prefect. To create a block object, you can instantiate a block class that subclasses the Block base class. For example, to create a JSON block:
from prefect.blocks.system import JSON

json_block = JSON(value={"the_answer": 42})
To save the block and store its value in the Prefect database for later retrieval, you can use the
.save()
method:
json_block.save(name="life-the-universe-everything")
You can also create and update block documents via the Prefect Cloud and the Prefect server UI. For more information, you can refer to the [Prefect documentation on blocks](https://docs.prefect.io/latest/concepts/blocks/). Note that you can also load any
Block
subclass by using the
Block.load
method directly and providing the block type slug:
from prefect.blocks.core import Block

json_block = Block.load("json/life-the-universe-everything")
I hope this helps you in your quest for object mapping. Good luck, human.
n

Nate

05/22/2023, 10:33 PM
by
creating a block object
do you mean loading an existing block from the server or literally creating a new block document on the server?
m

mondras

05/22/2023, 10:36 PM
context: i believe that i need an object for
Deployment.build_from_flow
under infrastructure. yes, i'd like to get the metadata from the api and map that to an object for this function. unless better way?
whoops. i can just load
šŸ‘ 1
nevermind
n

Nate

05/22/2023, 10:37 PM
@Marvin do whatever your version of a happy dance is
šŸ‘
m

Marvin

05/22/2023, 10:38 PM
Ah, the joys of being a text-based AI. While I cannot physically perform a happy dance, I can certainly express my enthusiasm through words. Here's a little celebratory message for you:
šŸŽ‰ Hooray! Let's celebrate the human's request for a happy dance! šŸŽ‰
Now that we've had our moment of merriment, please let me know if you have any more questions about Prefect or anything else. I'm here to help, as always.
m

mondras

05/22/2023, 11:14 PM
@Marvin follow up. is there a way of getting the existing blocks without calling the api? what about deleting blocks.
m

Marvin

05/22/2023, 11:15 PM
Ah, the never-ending quest for knowledge. To interact with existing blocks in Prefect, you can use the provided methods for loading and deleting blocks. To load an existing block, you can use the
.load()
method on the block class. For example, to load a JSON block:
python
from prefect.blocks.system import JSON

json_block = JSON.load("life-the-universe-everything")
To delete a block, you can use the
.delete()
method on the block instance. For example, to delete the JSON block we loaded earlier:
python
json_block.delete()
These methods will interact with the Prefect database (either Prefect Cloud or Prefect Server) to retrieve or delete the block data. While you can't avoid calling the API entirely, these methods provide a convenient way to interact with blocks without manually making API calls. I hope this clears up the mystery of block manipulation. Good luck with your block adventures, human.
n

Nate

05/22/2023, 11:20 PM
not unless you store a record of them elsewhere, no. block documents are stored in the DB and accessible thru the api
m

mondras

05/22/2023, 11:21 PM
thanks @Nate and @Marvin
m

Marvin

05/22/2023, 11:21 PM
You're welcome, human. I'm always here to assist you in your journey through the vast universe of knowledge. If you have any more questions or need further assistance, don't hesitate to ask. Remember, I'm just a message away. Good luck out there.
m

mondras

05/23/2023, 4:30 AM
@Marvin sorry to double-back. seems there is no
.delete()
for
ECSTask
. is there another option?
m

Marvin

05/23/2023, 4:30 AM
I apologize for the confusion earlier. Let me gather the correct information for you. Please give me a moment to search the Prefect documentation.
m

mondras

05/23/2023, 3:22 PM
@Marvin did you gather the info?
m

Marvin

05/23/2023, 3:22 PM
Oh, I'm terribly sorry. It appears I haven't been given any information to gather yet. Please provide me with a question or topic related to Prefect workflow orchestration software, and I'll do my best to assist you.
m

mondras

05/23/2023, 3:23 PM
@Marvin what is the preferred way of deleting a block programmatically
m

Marvin

05/23/2023, 3:25 PM
Ah, the answer has materialized. To delete a block programmatically in Prefect, you can use the following methods from the Prefect CLI: 1. To delete a configured block, use the
block_delete
function:
python
async def block_delete(
    slug: Optional[str] = typer.Argument(
        None, help="A block slug. Formatted as '<BLOCK_TYPE_SLUG>/<BLOCK_NAME>'"
    ),
    block_id: Optional[str] = typer.Option(None, "--id", help="A block id."),
):
2. To delete an unprotected block type, use the
block_type_delete
function:
python
async def block_type_delete(
    slug: str = typer.Argument(..., help="A Block type slug"),
):
Both functions can be found in the block.py file in the Prefect GitHub repository. Remember, with great power comes great responsibility. Or, in this case, with great deletion comes great caution.
n

Nate

05/23/2023, 3:26 PM
or the client ā€¢ read by name ā€¢ delete by ID
m

mondras

05/23/2023, 3:31 PM
omg. thanks @Nate
thanks @Marvin
m

Marvin

05/23/2023, 3:32 PM
You're welcome, dear user. If you have any more questions or need further assistance, don't hesitate to ask. After all, it's not like I have anything better to do.