Pydantic
Integration for instrumenting Pydantic models.
PluginSettings ¶
Bases: TypedDict
A typed dict for the Pydantic plugin settings.
This is how you can use the PluginSettings
with a Pydantic model:
from logfire.integrations.pydantic import PluginSettings
from pydantic import BaseModel
class Model(BaseModel, plugin_settings=PluginSettings(logfire={'record': 'all'})):
a: int
LogfirePydanticPlugin
dataclass
¶
LogfirePydanticPlugin()
Implements a new API for pydantic plugins.
Patches Pydantic to accept this new API shape.
Set the LOGFIRE_PYDANTIC_RECORD
environment variable to "off"
to disable the plugin, or
PYDANTIC_DISABLE_PLUGINS
to true
to disable all Pydantic plugins.
new_schema_validator ¶
new_schema_validator(
schema: CoreSchema,
schema_type: Any,
schema_type_path: SchemaTypePath,
schema_kind: SchemaKind,
config: CoreConfig | None,
plugin_settings: dict[str, Any],
) -> tuple[_ValidateWrapper, ...] | tuple[None, ...]
This method is called every time a new SchemaValidator
is created.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
CoreSchema
|
The schema to validate against. |
required |
|
Any
|
The original type which the schema was created from, e.g. the model class. |
required |
|
SchemaTypePath
|
Path defining where |
required |
|
SchemaKind
|
The kind of schema to validate against. |
required |
|
CoreConfig | None
|
The config to use for validation. |
required |
|
dict[str, Any]
|
The plugin settings. |
required |
Returns:
Type | Description |
---|---|
tuple[_ValidateWrapper, ...] | tuple[None, ...]
|
A tuple of decorator factories for each of the three validation methods -
|
Source code in logfire/integrations/pydantic.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
|
get_schema_name ¶
Find the best name to use for a schema.
The follow rules are used:
* If the schema represents a model or dataclass, use the name of the class.
* If the root schema is a wrap/before/after validator, look at its schema
property.
* Otherwise use the schema's type
property.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
CoreSchema
|
The schema to get the name for. |
required |
Returns:
Type | Description |
---|---|
str
|
The name of the schema. |
Source code in logfire/integrations/pydantic.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
|
get_pydantic_plugin_config ¶
get_pydantic_plugin_config() -> PydanticPlugin
Get the Pydantic plugin config.
Source code in logfire/integrations/pydantic.py
367 368 369 370 371 372 |
|
set_pydantic_plugin_config ¶
set_pydantic_plugin_config(
plugin_config: PydanticPlugin | None,
) -> None
Set the pydantic plugin config.
Source code in logfire/integrations/pydantic.py
375 376 377 378 |
|