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

Function example_decoding

examples/pydantic_usage.py:177–197  ·  view source on GitHub ↗

Example: Decoding TOON back to Pydantic models.

()

Source from the content-addressed store, hash-verified

175
176
177def example_decoding():
178 """Example: Decoding TOON back to Pydantic models."""
179 print("=== Decoding TOON to Pydantic ===")
180
181 # TOON string representing a list of users
182 toon = """[3]{id,name,email,age,active}:
183 1,Alice Smith,alice@example.com,30,true
184 2,Bob Johnson,bob@example.com,35,true
185 3,Charlie Brown,charlie@example.com,28,false"""
186
187 print("TOON input:")
188 print(toon)
189 print()
190
191 # Decode to list of User objects
192 users = decode_to_pydantic(toon, User)
193
194 print("Decoded Pydantic models:")
195 for user in users:
196 print(f" User(id={user.id}, name='{user.name}', age={user.age}, active={user.active})")
197 print()
198
199
200def example_roundtrip():

Callers 1

pydantic_usage.pyFile · 0.70

Calls 1

decode_to_pydanticFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…