mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
17 lines
354 B
Python
17 lines
354 B
Python
from typing import List
|
|
|
|
from pydantic import BaseModel, parse_obj_as
|
|
|
|
|
|
class Item(BaseModel):
|
|
id: int
|
|
name: str
|
|
|
|
|
|
# `item_data` could come from an API call, eg., via something like:
|
|
# item_data = requests.get('https://my-api.com/items').json()
|
|
item_data = [{'id': 1, 'name': 'My Item'}]
|
|
|
|
items = parse_obj_as(List[Item], item_data)
|
|
print(items)
|