mondras
05/22/2023, 10:31 PMMarvin
05/22/2023, 10:33 PMfrom 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.Nate
05/22/2023, 10:33 PMcreating a block objectdo you mean loading an existing block from the server or literally creating a new block document on the server?
mondras
05/22/2023, 10:36 PMDeployment.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?Nate
05/22/2023, 10:37 PMMarvin
05/22/2023, 10:38 PMš 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.mondras
05/22/2023, 11:14 PMMarvin
05/22/2023, 11:15 PM.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.Nate
05/22/2023, 11:20 PMmondras
05/22/2023, 11:21 PMMarvin
05/22/2023, 11:21 PMmondras
05/23/2023, 4:30 AM.delete()
for ECSTask
. is there another option?Marvin
05/23/2023, 4:30 AMmondras
05/23/2023, 3:22 PMMarvin
05/23/2023, 3:22 PMmondras
05/23/2023, 3:23 PMMarvin
05/23/2023, 3:25 PMblock_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.Nate
05/23/2023, 3:26 PMmondras
05/23/2023, 3:31 PMMarvin
05/23/2023, 3:32 PM