-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathannotated_schema.py
More file actions
31 lines (22 loc) · 973 Bytes
/
annotated_schema.py
File metadata and controls
31 lines (22 loc) · 973 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""Minimal example that uses Annotated + ExcelMeta declarations."""
from typing import Annotated
from pydantic import BaseModel, Field
from excelalchemy import Email, ExcelAlchemy, ExcelMeta, ImporterConfig, Number, String
class EmployeeImporter(BaseModel):
full_name: Annotated[
String,
Field(min_length=2),
ExcelMeta(label='Full name', order=1, hint='Use the legal name'),
]
age: Annotated[Number, Field(ge=18), ExcelMeta(label='Age', order=2)]
work_email: Annotated[
Email,
Field(min_length=8),
ExcelMeta(label='Work email', order=3, hint='Use your company email address'),
]
def main() -> None:
alchemy = ExcelAlchemy(ImporterConfig.for_create(EmployeeImporter, locale='en'))
template = alchemy.download_template_artifact(filename='employee-template.xlsx')
print(f'Generated template: {template.filename} ({len(template.as_bytes())} bytes)')
if __name__ == '__main__':
main()