Block
. The Block
base class builds
on Pydantic’s BaseModel
, so you can declare custom fields just like a Pydantic model.
We’ve already seen an example of a Cube
block that represents a cube and holds information about the length of each edge in inches:
register_type_and_schema
method shown above, you can register blocks from a Python module with a CLI command:
.py
file, you can register the block with the CLI command:
SecretStr
field type provided by Pydantic to automatically obfuscate those values.
You can use this capability for fields that store credentials such as passwords and API tokens.
Here’s an example of an AwsCredentials
block that uses SecretStr
:
aws_secret_access_key
has the SecretStr
type hint assigned to it,
the value of that field is not exposed if the object is logged:
SecretDict
field type allows you to add a dictionary field to your block
that automatically obfuscates values at all levels in the UI or in logs.
This capability is useful for blocks where typing or structure of secret fields is not known until configuration time.
Here’s an example of a block that uses SecretDict
:
system_secrets
is obfuscated when system_configuration_block
is displayed, but system_variables
show up in plain-text:
Property | Description |
---|---|
_block_type_name | Display name of the block in the UI. Defaults to the class name. |
_block_type_slug | Unique slug used to reference the block type in the API. Defaults to a lowercase, dash-delimited version of the block type name. |
_logo_url | URL pointing to an image that should be displayed for the block type in the UI. Default to None . |
_description | Short description of block type. Defaults to docstring, if provided. |
_code_example | Short code snippet shown in UI for how to load/use block type. Defaults to first example provided in the docstring of the class, if provided. |
Block
typesbucket_folder
field to your custom S3Bucket
block; it represents the default path to
read and write objects from (this field exists on our implementation).
Add the new field to the class definition: