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.3.tar.gz (26.0 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.3-py3-none-any.whl (31.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ywpi-0.1.3.tar.gz
Algorithm Hash digest
SHA256 135100d9458e8c8f8d8b5676e0687011c9157edacc60046881e4d3013f36b0eb
MD5 c1c20a2a930e4f34d0f943d87c308412
BLAKE2b-256 cefb30a7e7e299cc0aad17a8233c5152909f170b6b18724f7ff96e4b296c766e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ywpi-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 76f04fe205054363fe9598339c3acf22a51be18c4e71cd58c4de7357ad3eb677
MD5 bf214c3fc71145c01ad1f370bf36bc21
BLAKE2b-256 00c8fd3845f0eaa5e3cc9de9b757b8265fac781d09730ad30308a969cda88183

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