Skip to main content

Add your description here

Project description

Supported annotation variants

import typing
import ywpi

def fn(
    a1: int,
    a2: str,
    a3: float,

    # String as text
    a4: typing.Annotated[str, ywpi.Text],

    # File content
    a5: typing.Annotated[bytes, ywpi.File],

    # File reference
    a6: typing.Annotated[ywpi.Ref, ywpi.File],
):
    pass

Referenced JSON

{
    "output_str": {
        "type": "str",
        "value": ""
    },
    "output_int": {
        "type": "int",
        "value": 0
    },
    "output_url": {
        "type": "url",
        "value": "https://python.org/"
    },
    "output_ref": {
        "type": "ref",
        "value": {
            "drive_id": "",
            "preview_href": ""
        }
    }
}

Multiple level of serialization

  1. Application - regular python dictionary with python objects
  2. Hub - serialize dictionary in StartTaskRequest model
    • Referencify bytes values with attachments
  3. gRPC - serialize StartTaskRequest to string via JSON string + attachments map

Serialization for model with bytes fields

Ywpi pass additional context to pydantic model_validate method. Context has next format:

{
    "attachments": {
        "attachment_key": b"binary content"
    }
}
class Model(pydantic.BaseModel):
    class File(pydantic.BaseModel):
        content: bytes 

        @pydantic.field_validator('content', mode='before')
        def validate(data, info: pydantic.ValidationInfo) -> bytes:
            print("Validate", data, "\n")
            if isinstance(data, dict):
                key = data["$attachment"]
                if key in info.context["attachments"]:
                    return info.context["attachments"][key]
                else:
                    raise ValueError(f'conten with key "{key}" does not present in the attachments')
            return data

    files: list['Model.File'] = []

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ywpi-0.1.2.tar.gz (24.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ywpi-0.1.2-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file ywpi-0.1.2.tar.gz.

File metadata

  • Download URL: ywpi-0.1.2.tar.gz
  • Upload date:
  • Size: 24.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for ywpi-0.1.2.tar.gz
Algorithm Hash digest
SHA256 f3b8b6524831645e9c2e1d403c84a8ebda9eea4e0ff1757c56c9f250a0dae8a3
MD5 65e487a21b6fbd878bc4902866f41def
BLAKE2b-256 1661de3e7aa11e529848f054be650db95bed8dded70ead3df9ff77ae0b8b947b

See more details on using hashes here.

File details

Details for the file ywpi-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: ywpi-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for ywpi-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 17be17572a63caf3b1e60c801d6ab6e77cd072cde40e813293b1cf1ca8b0fe8a
MD5 57f89711688f9a92d092692e046e5601
BLAKE2b-256 97200a9bb03db05a1b35338567e09ee0d35b8839bb8716c56658fbd960568239

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page