new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Pydantic · Integrations · all subjects

devtools

5 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

python-devtools integration with Pydantic

Pydantic integrates with python-devtools by implementing the __pretty__ method on most public classes. This allows devtools to format Pydantic models in a readable way during development.

Using debug() to inspect Pydantic models

The debug() function from python-devtools is useful when inspecting Pydantic models. It formats output in a way that is easier to read than print(), and provides information about which file/line the statement is on and what value was printed.

devtools installation

Install devtools using pip: pip install devtools

Example of debug() with Pydantic BaseModel

The following example demonstrates using debug() to inspect a Pydantic model with nested models and various field types: ```python from datetime import datetime from devtools import debug from pydantic import BaseModel class Address(BaseModel): street: str country: str lat: float lng: float class User(BaseModel): id: int name: str signup_ts: datetime friends: list[int] address: Address user = User( id='123', name='John Doe', signup_ts='2019-06-01 12:22', friends=[1234, 4567, 7890], address=dict(street='Testing', country='uk', lat=51.5, lng=0), ) debug(user) print('\nshould be much easier read than:\n') print('user:', user) ``` The debug() call produces formatted output that is much easier to read than the standard print() output.

debug() is a development-time tool

debug() is a development-time tool that prints to the terminal of a process you're watching. For deployed applications, the closest equivalent is Logfire, where models and validations show up as structured output you can browse and query.

Give your agent this brain