Skip to content

Use Pydantic models instead of dataclasses #511

@CoreOxide

Description

@CoreOxide

Consider using Pydantic models, at least for user facing classes.

for example, the amazingly complex ApplyGuardrailInput class becomes:

class ApplyGuardrailInput(BaseModel):
    """
    Input for applying a guardrail.
    """
    guardrail_identifier: Optional[str] = Field(
        default=None,
        description="The guardrail identifier used in the request to apply the guardrail."
    )
    guardrail_version: Optional[str] = Field(
        default=None,
        description=" The guardrail version used in the request to apply the guardrail."
    )
    source: Optional[str] = Field(
        default=None,
        description=" The source of data used in the request to apply the guardrail."
    )
    content: Optional[List[GuardrailContentBlock]] = Field(
        default=None,
        description="* The content details used in the request to apply the guardrail."
    )
    output_scope: Optional[str] = Field(
        default=None,
        description=(
            "Specifies the scope of the output that you get in the response. 
        )
    )

You get serialization and deserialization OOTB, plus complex field validations, inheritance and readability.
I'm not sure on what you base your generation, but you can check out aws_resource_validator, as a reference. It generates Pydantic models from boto3 stubs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions