There Is No Game: Wrong Dimension
Steam achievements and progress for There Is No Game: Wrong Dimension - 11.76% complete with 4/34 achievements unlocked.
Core Keeper
Steam achievements and progress for Core Keeper - 0.0% complete with 0/51 achievements unlocked.
Starbound - Unstable
Steam achievements and progress for Starbound - Unstable - 9.8% complete with 5/51 achievements unlocked.
Colossal Order Game
Steam achievements and progress for Colossal Order Game - 3.94% complete with 5/127 achievements unlocked.
Poly Bridge 2
Steam achievements and progress for Poly Bridge 2 - 9.09% complete with 2/22 achievements unlocked.
Mimpi Dreams
Steam achievements and progress for Mimpi Dreams - 17.54% complete with 10/57 achievements unlocked.
Pycon 2023
Craftopia
Steam achievements and progress for Craftopia - 0.0% complete with 0/50 achievements unlocked.
global Field
global BaseModel
from pydantic import BaseModel
from pydantic import Field
Pydantic is a Python library for serializing data into models that can be validated with a deep set of built in valitators or your own custom validators, and deserialize back to JSON or dictionary.
Installation #
To install pydantic you will first need python and pip. Once you have pip installed you can install pydantic with pip.
pip install pydantic
Always install in a virtual environment
Creating a Pydantic model #
To get started with pydantic you will first need to create a Pydantic model.
This is a python class that inherits from pydantic.BaseModel.
from pydantic import BaseModel
from pydantic import Field
from typing import Optional
class Person(BaseModel):
name: str = Field(...)
age: int
parsing an object #
person = Person(name="John Doe", age=30)
print(person)
name='John Doe' age=30
data serialization #
Pydantic has some very robust serialization methods that will automatically coherse your data into the type specified by the type-hint in the model if it can.
person = Person(name=12, age="30")
print(f'name: {person.name}, type: {type(person.name)}')
print(f'age: {person.age}, type: {type(person.age)}')
1 validation error for Person
name
Input should be a valid string [type=string_type, input_value=12, input_type=int]
For further information visit https://errors.pydantic.dev/2.3/v/string_type
person = Person(name="John Doe", age='thirty')
print(f'name: {person.name}, type: {type(person.name)}')
print(f'age: {person.age}, type: {type(person.age)}')
1 validation error for Person
age
Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='thirty', input_type=str]
For further information visit https://errors.pydantic.dev/2.3/v/int_parsing
loading from json #
serializing to json #
validation #
Knockout City™
Steam achievements and progress for Knockout City™ - 2.0% complete with 1/50 achievements unlocked.
Badger
Steam achievements and progress for Badger - 12.5% complete with 5/40 achievements unlocked.
Frozen Flame
Steam achievements and progress for Frozen Flame - 6.25% complete with 2/32 achievements unlocked.
MultiVersus
Steam achievements and progress for MultiVersus - 53.57% complete with 15/28 achievements unlocked.
useful btrfs tools
Subnautica
Steam achievements and progress for Subnautica - 5.88% complete with 1/17 achievements unlocked.
Poly Bridge
Steam achievements and progress for Poly Bridge - 9.09% complete with 2/22 achievements unlocked.
devops philosophy
Steep
Steam achievements and progress for Steep - 0.0% complete with 0/41 achievements unlocked.