mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
6564bbb4ce
* Add parse_as_type function * Add changes * Incorporate feedback * Add naming tests * Fix double quotes * Fix docs example * Reorder parameters; add dataclass and mapping tests * Rename parse_as_type to parse_obj, and add parse_file * Incorporate feedback * Incorporate feedback * use custom root types
15 lines
352 B
Python
15 lines
352 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)
|