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
- Application - regular python dictionary with python objects
- Hub - serialize dictionary in
StartTaskRequestmodel- Referencify
bytesvalues with attachments
- Referencify
- gRPC - serialize
StartTaskRequestto string viaJSONstring +attachmentsmap
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.1.tar.gz
(24.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
ywpi-0.1.1-py3-none-any.whl
(29.8 kB
view details)
File details
Details for the file ywpi-0.1.1.tar.gz.
File metadata
- Download URL: ywpi-0.1.1.tar.gz
- Upload date:
- Size: 24.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c294e99739a7a58d070834762cc64356ec8237b50ddf244ecd30939228cdff7
|
|
| MD5 |
bab0f5dac740e06d46ac7fc1fca31f5a
|
|
| BLAKE2b-256 |
79fcf41c6134b9dab53a44e52083c6e59b27a5d11ded53eb2213f9d874b7fd78
|
File details
Details for the file ywpi-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ywpi-0.1.1-py3-none-any.whl
- Upload date:
- Size: 29.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72291ea61d8e18e9d3b00c19b37ff5644b5155b64a83670364822a8772a19f71
|
|
| MD5 |
03c9e524a1b8de9940647928ce4a3080
|
|
| BLAKE2b-256 |
107bf6bb65c99cda186ca5322cea22e15ddfa2a7f3cef8291363387a177763b3
|