MCPcopy Create free account
hub / github.com/ScrapeGraphAI/toonify / example_field_aliases

Function example_field_aliases

examples/pydantic_usage.py:152–174  ·  view source on GitHub ↗

Example: Using field aliases.

()

Source from the content-addressed store, hash-verified

150
151
152def example_field_aliases():
153 """Example: Using field aliases."""
154 print("=== Field Aliases ===")
155
156 order = Order(
157 orderId='ORD-12345',
158 customerName='Diana Prince',
159 products=[
160 Product(sku='LAP-001', name='Gaming Laptop', price=1299.99, stock=15),
161 Product(sku='MOU-042', name='Wireless Mouse', price=29.99, stock=128)
162 ],
163 total=1329.98
164 )
165
166 print("Without aliases (internal field names):")
167 toon_no_alias = encode_pydantic(order, by_alias=False)
168 print(toon_no_alias)
169 print()
170
171 print("With aliases (API field names):")
172 toon_alias = encode_pydantic(order, by_alias=True)
173 print(toon_alias)
174 print()
175
176
177def example_decoding():

Callers 1

pydantic_usage.pyFile · 0.85

Calls 3

encode_pydanticFunction · 0.90
OrderClass · 0.85
ProductClass · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…