cli
¤
bioimageio CLI
Some docstrings use a hair space ' '
to place the added '(default: ...)' on a new line.
Classes:
| Name | Description |
|---|---|
AddWeightsCmd |
Add additional weights to a model description by converting from available formats. |
ArgMixin |
|
Bioimageio |
bioimageio - CLI for bioimage.io resources 🦒 |
CmdBase |
|
EmptyCache |
Empty the bioimageio cache directory. |
PackageCmd |
Save a resource's metadata with its associated files. |
PredictCmd |
Run inference on your data with a bioimage.io model. |
TestCmd |
Test a bioimageio resource (beyond meta data formatting). |
UpdateCmdBase |
|
UpdateFormatCmd |
Update the metadata format to the latest format version. |
UpdateHashesCmd |
Create a bioimageio.yaml description with updated file hashes. |
ValidateFormatCmd |
Validate the meta data format of a bioimageio resource. |
WithSource |
|
WithSummaryLogging |
|
Attributes:
| Name | Type | Description |
|---|---|---|
JSON_FILE |
|
|
WEIGHT_FORMAT_ALIASES |
|
|
YAML_FILE |
|
WEIGHT_FORMAT_ALIASES
module-attribute
¤
WEIGHT_FORMAT_ALIASES = AliasChoices('weight-format', 'weights-format', 'weight_format', 'weights_format')
AddWeightsCmd
¤
AddWeightsCmd(**data: Any)
Bases: CmdBase, WithSource, WithSummaryLogging
flowchart TD
bioimageio.core.cli.AddWeightsCmd[AddWeightsCmd]
bioimageio.core.cli.CmdBase[CmdBase]
bioimageio.core.cli.WithSource[WithSource]
bioimageio.core.cli.WithSummaryLogging[WithSummaryLogging]
bioimageio.core.cli.ArgMixin[ArgMixin]
pydantic.main.BaseModel[BaseModel]
bioimageio.core.cli.CmdBase --> bioimageio.core.cli.AddWeightsCmd
pydantic.main.BaseModel --> bioimageio.core.cli.CmdBase
bioimageio.core.cli.WithSource --> bioimageio.core.cli.AddWeightsCmd
bioimageio.core.cli.ArgMixin --> bioimageio.core.cli.WithSource
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
bioimageio.core.cli.WithSummaryLogging --> bioimageio.core.cli.AddWeightsCmd
bioimageio.core.cli.ArgMixin --> bioimageio.core.cli.WithSummaryLogging
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
click bioimageio.core.cli.AddWeightsCmd href "" "bioimageio.core.cli.AddWeightsCmd"
click bioimageio.core.cli.CmdBase href "" "bioimageio.core.cli.CmdBase"
click bioimageio.core.cli.WithSource href "" "bioimageio.core.cli.WithSource"
click bioimageio.core.cli.WithSummaryLogging href "" "bioimageio.core.cli.WithSummaryLogging"
click bioimageio.core.cli.ArgMixin href "" "bioimageio.core.cli.ArgMixin"
click pydantic.main.BaseModel href "" "pydantic.main.BaseModel"
Add additional weights to a model description by converting from available formats.
Raises ValidationError if the input data cannot be
validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Methods:
| Name | Description |
|---|---|
__class_getitem__ |
|
__copy__ |
Returns a shallow copy of the model. |
__deepcopy__ |
Returns a deep copy of the model. |
__delattr__ |
|
__eq__ |
|
__get_pydantic_core_schema__ |
|
__get_pydantic_json_schema__ |
Hook into generating the model's JSON schema. |
__getattr__ |
|
__getstate__ |
|
__init_subclass__ |
This signature is included purely to help type-checkers check arguments to class declaration, which |
__iter__ |
So |
__pydantic_init_subclass__ |
This is intended to behave just like |
__pydantic_on_complete__ |
This is called once the class and its fields are fully initialized and ready to be used. |
__replace__ |
|
__repr__ |
|
__repr_args__ |
|
__setattr__ |
|
__setstate__ |
|
__str__ |
|
cli_cmd |
|
construct |
|
copy |
Returns a copy of the model. |
dict |
|
from_orm |
|
json |
|
log |
|
model_computed_fields |
A mapping of computed field names to their respective |
model_construct |
Creates a new instance of the |
model_copy |
Usage Documentation |
model_dump |
Usage Documentation |
model_dump_json |
Usage Documentation |
model_fields |
A mapping of field names to their respective |
model_json_schema |
Generates a JSON schema for a model class. |
model_parametrized_name |
Compute the class name for parametrizations of generic classes. |
model_post_init |
Override this method to perform additional initialization after |
model_rebuild |
Try to rebuild the pydantic-core schema for the model. |
model_validate |
Validate a pydantic model instance. |
model_validate_json |
Usage Documentation |
model_validate_strings |
Validate the given object with string data against the Pydantic model. |
parse_file |
|
parse_obj |
|
parse_raw |
|
schema |
|
schema_json |
|
update_forward_refs |
|
validate |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__class_vars__ |
set[str]
|
The names of the class variables defined on the model. |
__fields__ |
dict[str, FieldInfo]
|
|
__fields_set__ |
set[str]
|
|
__pretty__ |
|
|
__private_attributes__ |
Dict[str, ModelPrivateAttr]
|
Metadata about the private attributes of the model. |
__pydantic_complete__ |
bool
|
Whether model building is completed, or if there are still undefined fields. |
__pydantic_computed_fields__ |
Dict[str, ComputedFieldInfo]
|
A dictionary of computed field names and their corresponding |
__pydantic_core_schema__ |
CoreSchema
|
The core schema of the model. |
__pydantic_custom_init__ |
bool
|
Whether the model has a custom |
__pydantic_decorators__ |
_decorators.DecoratorInfos
|
Metadata containing the decorators defined on the model. |
__pydantic_extra__ |
Dict[str, Any] | None
|
A dictionary containing extra values, if |
__pydantic_fields__ |
Dict[str, FieldInfo]
|
A dictionary of field names and their corresponding |
__pydantic_fields_set__ |
set[str]
|
The names of fields explicitly set during instantiation. |
__pydantic_generic_metadata__ |
_generics.PydanticGenericMetadata
|
Metadata for generic models; contains data used for a similar purpose to |
__pydantic_parent_namespace__ |
Dict[str, Any] | None
|
Parent namespace of the model, used for automatic rebuilding of models. |
__pydantic_post_init__ |
None | Literal['model_post_init']
|
The name of the post-init method for the model, if defined. |
__pydantic_private__ |
Dict[str, Any] | None
|
Values of private attributes set on the model instance. |
__pydantic_root_model__ |
bool
|
Whether the model is a |
__pydantic_serializer__ |
SchemaSerializer
|
The |
__pydantic_setattr_handlers__ |
Dict[str, Callable[[BaseModel, str, Any], None]]
|
|
__pydantic_validator__ |
SchemaValidator | PluggableSchemaValidator
|
The |
__repr_name__ |
|
|
__repr_recursion__ |
|
|
__repr_str__ |
|
|
__rich_repr__ |
|
|
__signature__ |
Signature
|
The synthesized |
__slots__ |
|
|
descr |
|
|
descr_id |
str
|
a more user-friendly description id |
model_config |
ConfigDict
|
Configuration for the model, should be a dictionary conforming to |
model_extra |
dict[str, Any] | None
|
Get extra fields set during validation. |
model_fields_set |
set[str]
|
Returns the set of fields that have been explicitly set on this model instance. |
output |
CliPositionalArg[Path]
|
The path to write the updated model package to. |
source |
CliPositionalArg[str]
|
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file |
source_format |
Optional[SupportedWeightsFormat]
|
Exclusively use these weights to convert to other formats. |
summary |
List[Union[Literal['display'], Path]]
|
Display the validation summary or save it as JSON, Markdown or HTML. |
target_format |
Optional[SupportedWeightsFormat]
|
Exclusively add this weight format. |
tracing |
bool
|
Allow tracing when converting pytorch_state_dict to torchscript |
verbose |
bool
|
Log more (error) output. |
Source code in pydantic/main.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__class_vars__
class-attribute
¤
__class_vars__: set[str]
The names of the class variables defined on the model.
__private_attributes__
class-attribute
¤
__private_attributes__: Dict[str, ModelPrivateAttr]
Metadata about the private attributes of the model.
__pydantic_complete__
class-attribute
¤
__pydantic_complete__: bool = False
Whether model building is completed, or if there are still undefined fields.
__pydantic_computed_fields__
class-attribute
¤
__pydantic_computed_fields__: Dict[str, ComputedFieldInfo]
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
__pydantic_core_schema__
class-attribute
¤
__pydantic_core_schema__: CoreSchema
The core schema of the model.
__pydantic_custom_init__
class-attribute
¤
__pydantic_custom_init__: bool
Whether the model has a custom __init__ method.
__pydantic_decorators__
class-attribute
¤
__pydantic_decorators__: _decorators.DecoratorInfos = _decorators.DecoratorInfos()
Metadata containing the decorators defined on the model.
This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
__pydantic_extra__
pydantic-field
¤
__pydantic_extra__: Dict[str, Any] | None
A dictionary containing extra values, if extra is set to 'allow'.
__pydantic_fields__
class-attribute
¤
__pydantic_fields__: Dict[str, FieldInfo]
A dictionary of field names and their corresponding FieldInfo objects.
This replaces Model.__fields__ from Pydantic V1.
__pydantic_fields_set__
pydantic-field
¤
__pydantic_fields_set__: set[str]
The names of fields explicitly set during instantiation.
__pydantic_generic_metadata__
class-attribute
¤
__pydantic_generic_metadata__: _generics.PydanticGenericMetadata
Metadata for generic models; contains data used for a similar purpose to args, origin, parameters in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__
class-attribute
¤
__pydantic_parent_namespace__: Dict[str, Any] | None = None
Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__
class-attribute
¤
__pydantic_post_init__: None | Literal['model_post_init']
The name of the post-init method for the model, if defined.
__pydantic_private__
pydantic-field
¤
__pydantic_private__: Dict[str, Any] | None
Values of private attributes set on the model instance.
__pydantic_root_model__
class-attribute
¤
__pydantic_root_model__: bool = False
Whether the model is a RootModel.
__pydantic_serializer__
class-attribute
¤
__pydantic_serializer__: SchemaSerializer
The pydantic-core SchemaSerializer used to dump instances of the model.
__pydantic_setattr_handlers__
class-attribute
¤
__pydantic_setattr_handlers__: Dict[str, Callable[[BaseModel, str, Any], None]]
__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__
__pydantic_validator__
class-attribute
¤
__pydantic_validator__: SchemaValidator | PluggableSchemaValidator
The pydantic-core SchemaValidator used to validate instances of the model.
__signature__
class-attribute
¤
__signature__: Signature
The synthesized __init__ [Signature][inspect.Signature] of the model.
__slots__
pydantic-field
¤
__slots__ = ('__dict__', '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__')
descr_id
property
¤
descr_id: str
a more user-friendly description id (replacing legacy ids with their nicknames)
model_config
class-attribute
¤
model_config: ConfigDict = ConfigDict()
Configuration for the model, should be a dictionary conforming to ConfigDict.
model_extra
property
¤
model_extra: dict[str, Any] | None
Get extra fields set during validation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dictionary of extra fields, or |
model_fields_set
property
¤
model_fields_set: set[str]
Returns the set of fields that have been explicitly set on this model instance.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of strings representing the fields that have been set, i.e. that were not filled from defaults. |
output
instance-attribute
¤
output: CliPositionalArg[Path]
The path to write the updated model package to.
source
instance-attribute
¤
source: CliPositionalArg[str]
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file or a bioimage.io resource identifier, e.g. 'affable-shark'
source_format
class-attribute
instance-attribute
¤
source_format: Optional[SupportedWeightsFormat] = Field(None, alias='source-format')
Exclusively use these weights to convert to other formats.
summary
class-attribute
instance-attribute
¤
summary: List[Union[Literal['display'], Path]] = Field(default_factory=lambda: ['display'], examples=[Path('summary.md'), Path('bioimageio_summaries/'), ['display', Path('summary.md')]])
Display the validation summary or save it as JSON, Markdown or HTML.
The format is chosen based on the suffix: .json, .md, .html.
If a folder is given (path w/o suffix) the summary is saved in all formats.
Choose/add "display" to render the validation summary to the terminal.
target_format
class-attribute
instance-attribute
¤
target_format: Optional[SupportedWeightsFormat] = Field(None, alias='target-format')
Exclusively add this weight format.
tracing
class-attribute
instance-attribute
¤
tracing: bool = True
Allow tracing when converting pytorch_state_dict to torchscript (still uses scripting if possible).
__class_getitem__
¤
__class_getitem__(typevar_values: type[Any] | tuple[type[Any], ...]) -> type[BaseModel] | _forward_ref.PydanticRecursiveRef
Source code in pydantic/main.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
__copy__
¤
__copy__() -> Self
Returns a shallow copy of the model.
Source code in pydantic/main.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
__deepcopy__
¤
__deepcopy__(memo: dict[int, Any] | None = None) -> Self
Returns a deep copy of the model.
Source code in pydantic/main.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
__delattr__
¤
__delattr__(item: str) -> Any
Source code in pydantic/main.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
__eq__
¤
__eq__(other: Any) -> bool
Source code in pydantic/main.py
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
__get_pydantic_core_schema__
classmethod
¤
__get_pydantic_core_schema__(source: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema
Source code in pydantic/main.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
__get_pydantic_json_schema__
classmethod
¤
__get_pydantic_json_schema__(core_schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue
Hook into generating the model's JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CoreSchema
|
A |
required |
|
GetJsonSchemaHandler
|
Call into Pydantic's internal JSON schema generation.
This will raise a |
required |
Returns:
| Type | Description |
|---|---|
JsonSchemaValue
|
A JSON schema, as a Python object. |
Source code in pydantic/main.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
__getattr__
¤
__getattr__(item: str) -> Any
Source code in pydantic/main.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
__getstate__
¤
__getstate__() -> dict[Any, Any]
Source code in pydantic/main.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
__init_subclass__
¤
__init_subclass__(**kwargs: Unpack[ConfigDict])
This signature is included purely to help type-checkers check arguments to class declaration, which provides a way to conveniently set model_config key/value pairs.
from pydantic import BaseModel
class MyModel(BaseModel, extra='allow'): ...
However, this may be deceiving, since the actual calls to __init_subclass__ will not receive any
of the config arguments, and will only receive any keyword arguments passed during class initialization
that are not expected keys in ConfigDict. (This is due to the way ModelMetaclass.__new__ works.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Unpack[ConfigDict]
|
Keyword arguments passed to the class definition, which set model_config |
{}
|
Note
You may want to override __pydantic_init_subclass__ instead, which behaves similarly but is called
after the class is fully initialized.
Source code in pydantic/main.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
__iter__
¤
__iter__() -> TupleGenerator
So dict(model) works.
Source code in pydantic/main.py
1229 1230 1231 1232 1233 1234 | |
__pydantic_init_subclass__
classmethod
¤
__pydantic_init_subclass__(**kwargs: Any) -> None
This is intended to behave just like __init_subclass__, but is called by ModelMetaclass
only after basic class initialization is complete. In particular, attributes like model_fields will
be present when this is called, but forward annotations are not guaranteed to be resolved yet,
meaning that creating an instance of the class may fail.
This is necessary because __init_subclass__ will always be called by type.__new__,
and it would require a prohibitively large refactor to the ModelMetaclass to ensure that
type.__new__ was called in such a manner that the class would already be sufficiently initialized.
This will receive the same kwargs that would be passed to the standard __init_subclass__, namely,
any kwargs passed to the class definition that aren't used internally by Pydantic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Any keyword arguments passed to the class definition that aren't used internally by Pydantic. |
{}
|
Note
You may want to override __pydantic_on_complete__()
instead, which is called once the class and its fields are fully initialized and ready for validation.
Source code in pydantic/main.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
__pydantic_on_complete__
classmethod
¤
__pydantic_on_complete__() -> None
This is called once the class and its fields are fully initialized and ready to be used.
This typically happens when the class is created (just before
__pydantic_init_subclass__() is called on the superclass),
except when forward annotations are used that could not immediately be resolved.
In that case, it will be called later, when the model is rebuilt automatically or explicitly using
model_rebuild().
Source code in pydantic/main.py
877 878 879 880 881 882 883 884 885 886 | |
__replace__
¤
__replace__(**changes: Any) -> Self
Source code in pydantic/main.py
1125 1126 | |
__repr__
¤
__repr__() -> str
Source code in pydantic/main.py
1236 1237 | |
__repr_args__
¤
__repr_args__() -> _repr.ReprArgs
Source code in pydantic/main.py
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
__setattr__
¤
__setattr__(name: str, value: Any) -> None
Source code in pydantic/main.py
1028 1029 1030 1031 1032 1033 1034 | |
__setstate__
¤
__setstate__(state: dict[Any, Any]) -> None
Source code in pydantic/main.py
1139 1140 1141 1142 1143 | |
__str__
¤
__str__() -> str
Source code in pydantic/main.py
1274 1275 | |
cli_cmd
¤
cli_cmd()
Source code in src/bioimageio/core/cli.py
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 | |
construct
classmethod
¤
construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Source code in pydantic/main.py
1477 1478 1479 1480 1481 1482 1483 1484 1485 | |
copy
¤
copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) -> Self
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in pydantic/main.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | |
dict
¤
dict(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> Dict[str, Any]
Source code in pydantic/main.py
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | |
from_orm
classmethod
¤
from_orm(obj: Any) -> Self
Source code in pydantic/main.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
json
¤
json(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
log
¤
log(descr: Union[ResourceDescr, InvalidDescr])
Source code in src/bioimageio/core/cli.py
131 132 | |
model_computed_fields
classmethod
¤
model_computed_fields() -> dict[str, ComputedFieldInfo]
A mapping of computed field names to their respective ComputedFieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
273 274 275 276 277 278 279 280 281 282 | |
model_construct
classmethod
¤
model_construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Note
model_construct() generally respects the model_config.extra setting on the provided model.
That is, if model_config.extra == 'allow', then all extra passed values are added to the model instance's __dict__
and __pydantic_extra__ fields. If model_config.extra == 'ignore' (the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct(), having model_config.extra == 'forbid' does not result in
an error if extra values are passed, but they will be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
set[str] | None
|
A set of field names that were originally explicitly set during instantiation. If provided,
this is directly used for the |
None
|
|
Any
|
Trusted or pre-validated data dictionary. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
A new instance of the |
Source code in pydantic/main.py
303 304 305 306 307 308 309 310 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
model_copy
¤
Usage Documentation
Returns a copy of the model.
Note
The underlying instance's [__dict__][object.__dict__] attribute is copied. This
might have unexpected side effects if you store anything in it, on top of the model
fields (e.g. the value of [cached properties][functools.cached_property]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, Any] | None
|
Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data. |
None
|
|
bool
|
Set to |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
New model instance. |
Source code in pydantic/main.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
model_dump
¤
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> dict[str, Any]
Usage Documentation
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Literal['json', 'python'] | str
|
The mode in which |
'python'
|
|
IncEx | None
|
A set of fields to include in the output. |
None
|
|
IncEx | None
|
A set of fields to exclude from the output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to use the field's alias in the dictionary key if defined. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representation of the model. |
Source code in pydantic/main.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
model_dump_json
¤
model_dump_json(*, indent: int | None = None, ensure_ascii: bool = False, include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> str
Usage Documentation
Generates a JSON representation of the model using Pydantic's to_json method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
|
bool
|
If |
False
|
|
IncEx | None
|
Field(s) to include in the JSON output. |
None
|
|
IncEx | None
|
Field(s) to exclude from the JSON output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to serialize using field aliases. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representation of the model. |
Source code in pydantic/main.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
model_fields
classmethod
¤
A mapping of field names to their respective FieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
262 263 264 265 266 267 268 269 270 271 | |
model_json_schema
classmethod
¤
model_json_schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema, mode: JsonSchemaMode = 'validation', *, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of') -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to use attribute aliases or not. |
True
|
|
str
|
The reference template. |
DEFAULT_REF_TEMPLATE
|
|
Literal['any_of', 'primitive_type_array']
|
The format to use when combining schemas from unions together. Can be one of:
|
'any_of'
|
|
type[GenerateJsonSchema]
|
To override the logic used to generate the JSON schema, as a subclass of
|
GenerateJsonSchema
|
|
JsonSchemaMode
|
The mode in which to generate the schema. |
'validation'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON schema for the given model class. |
Source code in pydantic/main.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
model_parametrized_name
classmethod
¤
model_parametrized_name(params: tuple[type[Any], ...]) -> str
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
| Type | Description |
|---|---|
str
|
String representing the new class where |
Raises:
| Type | Description |
|---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in pydantic/main.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
model_post_init
¤
model_post_init(context: Any) -> None
Override this method to perform additional initialization after __init__ and model_construct.
This is useful if you want to do some validation that requires the entire model to be initialized.
Source code in pydantic/main.py
612 613 614 615 | |
model_rebuild
classmethod
¤
model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to force the rebuilding of the model schema, defaults to |
False
|
|
bool
|
Whether to raise errors, defaults to |
True
|
|
int
|
The depth level of the parent namespace, defaults to 2. |
2
|
|
MappingNamespace | None
|
The types namespace, defaults to |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
Returns |
Source code in pydantic/main.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
model_validate
classmethod
¤
model_validate(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, from_attributes: bool | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate a pydantic model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
bool | None
|
Whether to extract data from object attributes. |
None
|
|
Any | None
|
Additional context to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the object could not be validated. |
Returns:
| Type | Description |
|---|---|
Self
|
The validated model instance. |
Source code in pydantic/main.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
model_validate_json
classmethod
¤
model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Usage Documentation
Validate the given JSON data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in pydantic/main.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
model_validate_strings
classmethod
¤
model_validate_strings(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate the given object with string data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object containing string data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Source code in pydantic/main.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
parse_file
classmethod
¤
parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
parse_obj
classmethod
¤
parse_obj(obj: Any) -> Self
Source code in pydantic/main.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 | |
parse_raw
classmethod
¤
parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
schema
classmethod
¤
schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE) -> Dict[str, Any]
Source code in pydantic/main.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 | |
schema_json
classmethod
¤
schema_json(*, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
update_forward_refs
classmethod
¤
update_forward_refs(**localns: Any) -> None
Source code in pydantic/main.py
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
validate
classmethod
¤
validate(value: Any) -> Self
Source code in pydantic/main.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 | |
ArgMixin
¤
ArgMixin(**data: Any)
Bases: BaseModel
flowchart TD
bioimageio.core.cli.ArgMixin[ArgMixin]
pydantic.main.BaseModel[BaseModel]
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
click bioimageio.core.cli.ArgMixin href "" "bioimageio.core.cli.ArgMixin"
click pydantic.main.BaseModel href "" "pydantic.main.BaseModel"
Raises ValidationError if the input data cannot be
validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
-
API Reference
cli
Methods:
| Name | Description |
|---|---|
__class_getitem__ |
|
__copy__ |
Returns a shallow copy of the model. |
__deepcopy__ |
Returns a deep copy of the model. |
__delattr__ |
|
__eq__ |
|
__get_pydantic_core_schema__ |
|
__get_pydantic_json_schema__ |
Hook into generating the model's JSON schema. |
__getattr__ |
|
__getstate__ |
|
__init_subclass__ |
This signature is included purely to help type-checkers check arguments to class declaration, which |
__iter__ |
So |
__pydantic_init_subclass__ |
This is intended to behave just like |
__pydantic_on_complete__ |
This is called once the class and its fields are fully initialized and ready to be used. |
__replace__ |
|
__repr__ |
|
__repr_args__ |
|
__setattr__ |
|
__setstate__ |
|
__str__ |
|
construct |
|
copy |
Returns a copy of the model. |
dict |
|
from_orm |
|
json |
|
model_computed_fields |
A mapping of computed field names to their respective |
model_construct |
Creates a new instance of the |
model_copy |
Usage Documentation |
model_dump |
Usage Documentation |
model_dump_json |
Usage Documentation |
model_fields |
A mapping of field names to their respective |
model_json_schema |
Generates a JSON schema for a model class. |
model_parametrized_name |
Compute the class name for parametrizations of generic classes. |
model_post_init |
Override this method to perform additional initialization after |
model_rebuild |
Try to rebuild the pydantic-core schema for the model. |
model_validate |
Validate a pydantic model instance. |
model_validate_json |
Usage Documentation |
model_validate_strings |
Validate the given object with string data against the Pydantic model. |
parse_file |
|
parse_obj |
|
parse_raw |
|
schema |
|
schema_json |
|
update_forward_refs |
|
validate |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__class_vars__ |
set[str]
|
The names of the class variables defined on the model. |
__fields__ |
dict[str, FieldInfo]
|
|
__fields_set__ |
set[str]
|
|
__pretty__ |
|
|
__private_attributes__ |
Dict[str, ModelPrivateAttr]
|
Metadata about the private attributes of the model. |
__pydantic_complete__ |
bool
|
Whether model building is completed, or if there are still undefined fields. |
__pydantic_computed_fields__ |
Dict[str, ComputedFieldInfo]
|
A dictionary of computed field names and their corresponding |
__pydantic_core_schema__ |
CoreSchema
|
The core schema of the model. |
__pydantic_custom_init__ |
bool
|
Whether the model has a custom |
__pydantic_decorators__ |
_decorators.DecoratorInfos
|
Metadata containing the decorators defined on the model. |
__pydantic_extra__ |
Dict[str, Any] | None
|
A dictionary containing extra values, if |
__pydantic_fields__ |
Dict[str, FieldInfo]
|
A dictionary of field names and their corresponding |
__pydantic_fields_set__ |
set[str]
|
The names of fields explicitly set during instantiation. |
__pydantic_generic_metadata__ |
_generics.PydanticGenericMetadata
|
Metadata for generic models; contains data used for a similar purpose to |
__pydantic_parent_namespace__ |
Dict[str, Any] | None
|
Parent namespace of the model, used for automatic rebuilding of models. |
__pydantic_post_init__ |
None | Literal['model_post_init']
|
The name of the post-init method for the model, if defined. |
__pydantic_private__ |
Dict[str, Any] | None
|
Values of private attributes set on the model instance. |
__pydantic_root_model__ |
bool
|
Whether the model is a |
__pydantic_serializer__ |
SchemaSerializer
|
The |
__pydantic_setattr_handlers__ |
Dict[str, Callable[[BaseModel, str, Any], None]]
|
|
__pydantic_validator__ |
SchemaValidator | PluggableSchemaValidator
|
The |
__repr_name__ |
|
|
__repr_recursion__ |
|
|
__repr_str__ |
|
|
__rich_repr__ |
|
|
__signature__ |
Signature
|
The synthesized |
__slots__ |
|
|
model_config |
ConfigDict
|
Configuration for the model, should be a dictionary conforming to |
model_extra |
dict[str, Any] | None
|
Get extra fields set during validation. |
model_fields_set |
set[str]
|
Returns the set of fields that have been explicitly set on this model instance. |
Source code in pydantic/main.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__class_vars__
class-attribute
¤
__class_vars__: set[str]
The names of the class variables defined on the model.
__private_attributes__
class-attribute
¤
__private_attributes__: Dict[str, ModelPrivateAttr]
Metadata about the private attributes of the model.
__pydantic_complete__
class-attribute
¤
__pydantic_complete__: bool = False
Whether model building is completed, or if there are still undefined fields.
__pydantic_computed_fields__
class-attribute
¤
__pydantic_computed_fields__: Dict[str, ComputedFieldInfo]
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
__pydantic_core_schema__
class-attribute
¤
__pydantic_core_schema__: CoreSchema
The core schema of the model.
__pydantic_custom_init__
class-attribute
¤
__pydantic_custom_init__: bool
Whether the model has a custom __init__ method.
__pydantic_decorators__
class-attribute
¤
__pydantic_decorators__: _decorators.DecoratorInfos = _decorators.DecoratorInfos()
Metadata containing the decorators defined on the model.
This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
__pydantic_extra__
pydantic-field
¤
__pydantic_extra__: Dict[str, Any] | None
A dictionary containing extra values, if extra is set to 'allow'.
__pydantic_fields__
class-attribute
¤
__pydantic_fields__: Dict[str, FieldInfo]
A dictionary of field names and their corresponding FieldInfo objects.
This replaces Model.__fields__ from Pydantic V1.
__pydantic_fields_set__
pydantic-field
¤
__pydantic_fields_set__: set[str]
The names of fields explicitly set during instantiation.
__pydantic_generic_metadata__
class-attribute
¤
__pydantic_generic_metadata__: _generics.PydanticGenericMetadata
Metadata for generic models; contains data used for a similar purpose to args, origin, parameters in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__
class-attribute
¤
__pydantic_parent_namespace__: Dict[str, Any] | None = None
Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__
class-attribute
¤
__pydantic_post_init__: None | Literal['model_post_init']
The name of the post-init method for the model, if defined.
__pydantic_private__
pydantic-field
¤
__pydantic_private__: Dict[str, Any] | None
Values of private attributes set on the model instance.
__pydantic_root_model__
class-attribute
¤
__pydantic_root_model__: bool = False
Whether the model is a RootModel.
__pydantic_serializer__
class-attribute
¤
__pydantic_serializer__: SchemaSerializer
The pydantic-core SchemaSerializer used to dump instances of the model.
__pydantic_setattr_handlers__
class-attribute
¤
__pydantic_setattr_handlers__: Dict[str, Callable[[BaseModel, str, Any], None]]
__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__
__pydantic_validator__
class-attribute
¤
__pydantic_validator__: SchemaValidator | PluggableSchemaValidator
The pydantic-core SchemaValidator used to validate instances of the model.
__signature__
class-attribute
¤
__signature__: Signature
The synthesized __init__ [Signature][inspect.Signature] of the model.
__slots__
pydantic-field
¤
__slots__ = ('__dict__', '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__')
model_config
class-attribute
¤
model_config: ConfigDict = ConfigDict()
Configuration for the model, should be a dictionary conforming to ConfigDict.
model_extra
property
¤
model_extra: dict[str, Any] | None
Get extra fields set during validation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dictionary of extra fields, or |
model_fields_set
property
¤
model_fields_set: set[str]
Returns the set of fields that have been explicitly set on this model instance.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of strings representing the fields that have been set, i.e. that were not filled from defaults. |
__class_getitem__
¤
__class_getitem__(typevar_values: type[Any] | tuple[type[Any], ...]) -> type[BaseModel] | _forward_ref.PydanticRecursiveRef
Source code in pydantic/main.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
__copy__
¤
__copy__() -> Self
Returns a shallow copy of the model.
Source code in pydantic/main.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
__deepcopy__
¤
__deepcopy__(memo: dict[int, Any] | None = None) -> Self
Returns a deep copy of the model.
Source code in pydantic/main.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
__delattr__
¤
__delattr__(item: str) -> Any
Source code in pydantic/main.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
__eq__
¤
__eq__(other: Any) -> bool
Source code in pydantic/main.py
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
__get_pydantic_core_schema__
classmethod
¤
__get_pydantic_core_schema__(source: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema
Source code in pydantic/main.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
__get_pydantic_json_schema__
classmethod
¤
__get_pydantic_json_schema__(core_schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue
Hook into generating the model's JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CoreSchema
|
A |
required |
|
GetJsonSchemaHandler
|
Call into Pydantic's internal JSON schema generation.
This will raise a |
required |
Returns:
| Type | Description |
|---|---|
JsonSchemaValue
|
A JSON schema, as a Python object. |
Source code in pydantic/main.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
__getattr__
¤
__getattr__(item: str) -> Any
Source code in pydantic/main.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
__getstate__
¤
__getstate__() -> dict[Any, Any]
Source code in pydantic/main.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
__init_subclass__
¤
__init_subclass__(**kwargs: Unpack[ConfigDict])
This signature is included purely to help type-checkers check arguments to class declaration, which provides a way to conveniently set model_config key/value pairs.
from pydantic import BaseModel
class MyModel(BaseModel, extra='allow'): ...
However, this may be deceiving, since the actual calls to __init_subclass__ will not receive any
of the config arguments, and will only receive any keyword arguments passed during class initialization
that are not expected keys in ConfigDict. (This is due to the way ModelMetaclass.__new__ works.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Unpack[ConfigDict]
|
Keyword arguments passed to the class definition, which set model_config |
{}
|
Note
You may want to override __pydantic_init_subclass__ instead, which behaves similarly but is called
after the class is fully initialized.
Source code in pydantic/main.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
__iter__
¤
__iter__() -> TupleGenerator
So dict(model) works.
Source code in pydantic/main.py
1229 1230 1231 1232 1233 1234 | |
__pydantic_init_subclass__
classmethod
¤
__pydantic_init_subclass__(**kwargs: Any) -> None
This is intended to behave just like __init_subclass__, but is called by ModelMetaclass
only after basic class initialization is complete. In particular, attributes like model_fields will
be present when this is called, but forward annotations are not guaranteed to be resolved yet,
meaning that creating an instance of the class may fail.
This is necessary because __init_subclass__ will always be called by type.__new__,
and it would require a prohibitively large refactor to the ModelMetaclass to ensure that
type.__new__ was called in such a manner that the class would already be sufficiently initialized.
This will receive the same kwargs that would be passed to the standard __init_subclass__, namely,
any kwargs passed to the class definition that aren't used internally by Pydantic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Any keyword arguments passed to the class definition that aren't used internally by Pydantic. |
{}
|
Note
You may want to override __pydantic_on_complete__()
instead, which is called once the class and its fields are fully initialized and ready for validation.
Source code in pydantic/main.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
__pydantic_on_complete__
classmethod
¤
__pydantic_on_complete__() -> None
This is called once the class and its fields are fully initialized and ready to be used.
This typically happens when the class is created (just before
__pydantic_init_subclass__() is called on the superclass),
except when forward annotations are used that could not immediately be resolved.
In that case, it will be called later, when the model is rebuilt automatically or explicitly using
model_rebuild().
Source code in pydantic/main.py
877 878 879 880 881 882 883 884 885 886 | |
__replace__
¤
__replace__(**changes: Any) -> Self
Source code in pydantic/main.py
1125 1126 | |
__repr__
¤
__repr__() -> str
Source code in pydantic/main.py
1236 1237 | |
__repr_args__
¤
__repr_args__() -> _repr.ReprArgs
Source code in pydantic/main.py
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
__setattr__
¤
__setattr__(name: str, value: Any) -> None
Source code in pydantic/main.py
1028 1029 1030 1031 1032 1033 1034 | |
__setstate__
¤
__setstate__(state: dict[Any, Any]) -> None
Source code in pydantic/main.py
1139 1140 1141 1142 1143 | |
__str__
¤
__str__() -> str
Source code in pydantic/main.py
1274 1275 | |
construct
classmethod
¤
construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Source code in pydantic/main.py
1477 1478 1479 1480 1481 1482 1483 1484 1485 | |
copy
¤
copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) -> Self
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in pydantic/main.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | |
dict
¤
dict(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> Dict[str, Any]
Source code in pydantic/main.py
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | |
from_orm
classmethod
¤
from_orm(obj: Any) -> Self
Source code in pydantic/main.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
json
¤
json(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
model_computed_fields
classmethod
¤
model_computed_fields() -> dict[str, ComputedFieldInfo]
A mapping of computed field names to their respective ComputedFieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
273 274 275 276 277 278 279 280 281 282 | |
model_construct
classmethod
¤
model_construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Note
model_construct() generally respects the model_config.extra setting on the provided model.
That is, if model_config.extra == 'allow', then all extra passed values are added to the model instance's __dict__
and __pydantic_extra__ fields. If model_config.extra == 'ignore' (the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct(), having model_config.extra == 'forbid' does not result in
an error if extra values are passed, but they will be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
set[str] | None
|
A set of field names that were originally explicitly set during instantiation. If provided,
this is directly used for the |
None
|
|
Any
|
Trusted or pre-validated data dictionary. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
A new instance of the |
Source code in pydantic/main.py
303 304 305 306 307 308 309 310 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
model_copy
¤
Usage Documentation
Returns a copy of the model.
Note
The underlying instance's [__dict__][object.__dict__] attribute is copied. This
might have unexpected side effects if you store anything in it, on top of the model
fields (e.g. the value of [cached properties][functools.cached_property]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, Any] | None
|
Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data. |
None
|
|
bool
|
Set to |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
New model instance. |
Source code in pydantic/main.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
model_dump
¤
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> dict[str, Any]
Usage Documentation
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Literal['json', 'python'] | str
|
The mode in which |
'python'
|
|
IncEx | None
|
A set of fields to include in the output. |
None
|
|
IncEx | None
|
A set of fields to exclude from the output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to use the field's alias in the dictionary key if defined. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representation of the model. |
Source code in pydantic/main.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
model_dump_json
¤
model_dump_json(*, indent: int | None = None, ensure_ascii: bool = False, include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> str
Usage Documentation
Generates a JSON representation of the model using Pydantic's to_json method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
|
bool
|
If |
False
|
|
IncEx | None
|
Field(s) to include in the JSON output. |
None
|
|
IncEx | None
|
Field(s) to exclude from the JSON output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to serialize using field aliases. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representation of the model. |
Source code in pydantic/main.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
model_fields
classmethod
¤
A mapping of field names to their respective FieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
262 263 264 265 266 267 268 269 270 271 | |
model_json_schema
classmethod
¤
model_json_schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema, mode: JsonSchemaMode = 'validation', *, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of') -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to use attribute aliases or not. |
True
|
|
str
|
The reference template. |
DEFAULT_REF_TEMPLATE
|
|
Literal['any_of', 'primitive_type_array']
|
The format to use when combining schemas from unions together. Can be one of:
|
'any_of'
|
|
type[GenerateJsonSchema]
|
To override the logic used to generate the JSON schema, as a subclass of
|
GenerateJsonSchema
|
|
JsonSchemaMode
|
The mode in which to generate the schema. |
'validation'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON schema for the given model class. |
Source code in pydantic/main.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
model_parametrized_name
classmethod
¤
model_parametrized_name(params: tuple[type[Any], ...]) -> str
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
| Type | Description |
|---|---|
str
|
String representing the new class where |
Raises:
| Type | Description |
|---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in pydantic/main.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
model_post_init
¤
model_post_init(context: Any) -> None
Override this method to perform additional initialization after __init__ and model_construct.
This is useful if you want to do some validation that requires the entire model to be initialized.
Source code in pydantic/main.py
612 613 614 615 | |
model_rebuild
classmethod
¤
model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to force the rebuilding of the model schema, defaults to |
False
|
|
bool
|
Whether to raise errors, defaults to |
True
|
|
int
|
The depth level of the parent namespace, defaults to 2. |
2
|
|
MappingNamespace | None
|
The types namespace, defaults to |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
Returns |
Source code in pydantic/main.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
model_validate
classmethod
¤
model_validate(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, from_attributes: bool | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate a pydantic model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
bool | None
|
Whether to extract data from object attributes. |
None
|
|
Any | None
|
Additional context to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the object could not be validated. |
Returns:
| Type | Description |
|---|---|
Self
|
The validated model instance. |
Source code in pydantic/main.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
model_validate_json
classmethod
¤
model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Usage Documentation
Validate the given JSON data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in pydantic/main.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
model_validate_strings
classmethod
¤
model_validate_strings(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate the given object with string data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object containing string data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Source code in pydantic/main.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
parse_file
classmethod
¤
parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
parse_obj
classmethod
¤
parse_obj(obj: Any) -> Self
Source code in pydantic/main.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 | |
parse_raw
classmethod
¤
parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
schema
classmethod
¤
schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE) -> Dict[str, Any]
Source code in pydantic/main.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 | |
schema_json
classmethod
¤
schema_json(*, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
update_forward_refs
classmethod
¤
update_forward_refs(**localns: Any) -> None
Source code in pydantic/main.py
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
validate
classmethod
¤
validate(value: Any) -> Self
Source code in pydantic/main.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 | |
Bioimageio
¤
Bases: BaseSettings
flowchart TD
bioimageio.core.cli.Bioimageio[Bioimageio]
click bioimageio.core.cli.Bioimageio href "" "bioimageio.core.cli.Bioimageio"
bioimageio - CLI for bioimage.io resources 🦒
Methods:
| Name | Description |
|---|---|
cli_cmd |
|
settings_customise_sources |
|
Attributes:
| Name | Type | Description |
|---|---|---|
add_weights |
CliSubCommand[AddWeightsCmd]
|
Add additional weights to a model description by converting from available formats. |
empty_cache |
CliSubCommand[EmptyCache]
|
Empty the bioimageio cache directory. |
model_config |
|
|
package |
CliSubCommand[PackageCmd]
|
Package a resource |
predict |
CliSubCommand[PredictCmd]
|
Predict with a model resource |
test |
CliSubCommand[TestCmd]
|
Test a bioimageio resource (beyond meta data formatting) |
update_format |
CliSubCommand[UpdateFormatCmd]
|
Update the metadata format |
update_hashes |
CliSubCommand[UpdateHashesCmd]
|
Create a bioimageio.yaml description with updated file hashes. |
validate_format |
CliSubCommand[ValidateFormatCmd]
|
Check a resource's metadata format |
add_weights
class-attribute
instance-attribute
¤
add_weights: CliSubCommand[AddWeightsCmd] = Field(alias='add-weights')
Add additional weights to a model description by converting from available formats.
empty_cache
class-attribute
instance-attribute
¤
empty_cache: CliSubCommand[EmptyCache] = Field(alias='empty-cache')
Empty the bioimageio cache directory.
model_config
class-attribute
instance-attribute
¤
model_config = SettingsConfigDict(json_file=JSON_FILE, yaml_file=YAML_FILE)
test
instance-attribute
¤
test: CliSubCommand[TestCmd]
Test a bioimageio resource (beyond meta data formatting)
update_format
class-attribute
instance-attribute
¤
update_format: CliSubCommand[UpdateFormatCmd] = Field(alias='update-format')
Update the metadata format
update_hashes
class-attribute
instance-attribute
¤
update_hashes: CliSubCommand[UpdateHashesCmd] = Field(alias='update-hashes')
Create a bioimageio.yaml description with updated file hashes.
validate_format
class-attribute
instance-attribute
¤
validate_format: CliSubCommand[ValidateFormatCmd] = Field(alias='validate-format')
Check a resource's metadata format
cli_cmd
¤
cli_cmd() -> None
Source code in src/bioimageio/core/cli.py
893 894 895 896 897 898 | |
settings_customise_sources
classmethod
¤
settings_customise_sources(settings_cls: Type[BaseSettings], init_settings: PydanticBaseSettingsSource, env_settings: PydanticBaseSettingsSource, dotenv_settings: PydanticBaseSettingsSource, file_secret_settings: PydanticBaseSettingsSource) -> Tuple[PydanticBaseSettingsSource, ...]
Source code in src/bioimageio/core/cli.py
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 | |
CmdBase
¤
CmdBase(**data: Any)
Bases: BaseModel
flowchart TD
bioimageio.core.cli.CmdBase[CmdBase]
pydantic.main.BaseModel[BaseModel]
pydantic.main.BaseModel --> bioimageio.core.cli.CmdBase
click bioimageio.core.cli.CmdBase href "" "bioimageio.core.cli.CmdBase"
click pydantic.main.BaseModel href "" "pydantic.main.BaseModel"
Raises ValidationError if the input data cannot be
validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
-
API Reference
cli
Methods:
| Name | Description |
|---|---|
__class_getitem__ |
|
__copy__ |
Returns a shallow copy of the model. |
__deepcopy__ |
Returns a deep copy of the model. |
__delattr__ |
|
__eq__ |
|
__get_pydantic_core_schema__ |
|
__get_pydantic_json_schema__ |
Hook into generating the model's JSON schema. |
__getattr__ |
|
__getstate__ |
|
__init_subclass__ |
This signature is included purely to help type-checkers check arguments to class declaration, which |
__iter__ |
So |
__pydantic_init_subclass__ |
This is intended to behave just like |
__pydantic_on_complete__ |
This is called once the class and its fields are fully initialized and ready to be used. |
__replace__ |
|
__repr__ |
|
__repr_args__ |
|
__setattr__ |
|
__setstate__ |
|
__str__ |
|
construct |
|
copy |
Returns a copy of the model. |
dict |
|
from_orm |
|
json |
|
model_computed_fields |
A mapping of computed field names to their respective |
model_construct |
Creates a new instance of the |
model_copy |
Usage Documentation |
model_dump |
Usage Documentation |
model_dump_json |
Usage Documentation |
model_fields |
A mapping of field names to their respective |
model_json_schema |
Generates a JSON schema for a model class. |
model_parametrized_name |
Compute the class name for parametrizations of generic classes. |
model_post_init |
Override this method to perform additional initialization after |
model_rebuild |
Try to rebuild the pydantic-core schema for the model. |
model_validate |
Validate a pydantic model instance. |
model_validate_json |
Usage Documentation |
model_validate_strings |
Validate the given object with string data against the Pydantic model. |
parse_file |
|
parse_obj |
|
parse_raw |
|
schema |
|
schema_json |
|
update_forward_refs |
|
validate |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__class_vars__ |
set[str]
|
The names of the class variables defined on the model. |
__fields__ |
dict[str, FieldInfo]
|
|
__fields_set__ |
set[str]
|
|
__pretty__ |
|
|
__private_attributes__ |
Dict[str, ModelPrivateAttr]
|
Metadata about the private attributes of the model. |
__pydantic_complete__ |
bool
|
Whether model building is completed, or if there are still undefined fields. |
__pydantic_computed_fields__ |
Dict[str, ComputedFieldInfo]
|
A dictionary of computed field names and their corresponding |
__pydantic_core_schema__ |
CoreSchema
|
The core schema of the model. |
__pydantic_custom_init__ |
bool
|
Whether the model has a custom |
__pydantic_decorators__ |
_decorators.DecoratorInfos
|
Metadata containing the decorators defined on the model. |
__pydantic_extra__ |
Dict[str, Any] | None
|
A dictionary containing extra values, if |
__pydantic_fields__ |
Dict[str, FieldInfo]
|
A dictionary of field names and their corresponding |
__pydantic_fields_set__ |
set[str]
|
The names of fields explicitly set during instantiation. |
__pydantic_generic_metadata__ |
_generics.PydanticGenericMetadata
|
Metadata for generic models; contains data used for a similar purpose to |
__pydantic_parent_namespace__ |
Dict[str, Any] | None
|
Parent namespace of the model, used for automatic rebuilding of models. |
__pydantic_post_init__ |
None | Literal['model_post_init']
|
The name of the post-init method for the model, if defined. |
__pydantic_private__ |
Dict[str, Any] | None
|
Values of private attributes set on the model instance. |
__pydantic_root_model__ |
bool
|
Whether the model is a |
__pydantic_serializer__ |
SchemaSerializer
|
The |
__pydantic_setattr_handlers__ |
Dict[str, Callable[[BaseModel, str, Any], None]]
|
|
__pydantic_validator__ |
SchemaValidator | PluggableSchemaValidator
|
The |
__repr_name__ |
|
|
__repr_recursion__ |
|
|
__repr_str__ |
|
|
__rich_repr__ |
|
|
__signature__ |
Signature
|
The synthesized |
__slots__ |
|
|
model_config |
ConfigDict
|
Configuration for the model, should be a dictionary conforming to |
model_extra |
dict[str, Any] | None
|
Get extra fields set during validation. |
model_fields_set |
set[str]
|
Returns the set of fields that have been explicitly set on this model instance. |
Source code in pydantic/main.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__class_vars__
class-attribute
¤
__class_vars__: set[str]
The names of the class variables defined on the model.
__private_attributes__
class-attribute
¤
__private_attributes__: Dict[str, ModelPrivateAttr]
Metadata about the private attributes of the model.
__pydantic_complete__
class-attribute
¤
__pydantic_complete__: bool = False
Whether model building is completed, or if there are still undefined fields.
__pydantic_computed_fields__
class-attribute
¤
__pydantic_computed_fields__: Dict[str, ComputedFieldInfo]
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
__pydantic_core_schema__
class-attribute
¤
__pydantic_core_schema__: CoreSchema
The core schema of the model.
__pydantic_custom_init__
class-attribute
¤
__pydantic_custom_init__: bool
Whether the model has a custom __init__ method.
__pydantic_decorators__
class-attribute
¤
__pydantic_decorators__: _decorators.DecoratorInfos = _decorators.DecoratorInfos()
Metadata containing the decorators defined on the model.
This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
__pydantic_extra__
pydantic-field
¤
__pydantic_extra__: Dict[str, Any] | None
A dictionary containing extra values, if extra is set to 'allow'.
__pydantic_fields__
class-attribute
¤
__pydantic_fields__: Dict[str, FieldInfo]
A dictionary of field names and their corresponding FieldInfo objects.
This replaces Model.__fields__ from Pydantic V1.
__pydantic_fields_set__
pydantic-field
¤
__pydantic_fields_set__: set[str]
The names of fields explicitly set during instantiation.
__pydantic_generic_metadata__
class-attribute
¤
__pydantic_generic_metadata__: _generics.PydanticGenericMetadata
Metadata for generic models; contains data used for a similar purpose to args, origin, parameters in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__
class-attribute
¤
__pydantic_parent_namespace__: Dict[str, Any] | None = None
Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__
class-attribute
¤
__pydantic_post_init__: None | Literal['model_post_init']
The name of the post-init method for the model, if defined.
__pydantic_private__
pydantic-field
¤
__pydantic_private__: Dict[str, Any] | None
Values of private attributes set on the model instance.
__pydantic_root_model__
class-attribute
¤
__pydantic_root_model__: bool = False
Whether the model is a RootModel.
__pydantic_serializer__
class-attribute
¤
__pydantic_serializer__: SchemaSerializer
The pydantic-core SchemaSerializer used to dump instances of the model.
__pydantic_setattr_handlers__
class-attribute
¤
__pydantic_setattr_handlers__: Dict[str, Callable[[BaseModel, str, Any], None]]
__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__
__pydantic_validator__
class-attribute
¤
__pydantic_validator__: SchemaValidator | PluggableSchemaValidator
The pydantic-core SchemaValidator used to validate instances of the model.
__signature__
class-attribute
¤
__signature__: Signature
The synthesized __init__ [Signature][inspect.Signature] of the model.
__slots__
pydantic-field
¤
__slots__ = ('__dict__', '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__')
model_config
class-attribute
¤
model_config: ConfigDict = ConfigDict()
Configuration for the model, should be a dictionary conforming to ConfigDict.
model_extra
property
¤
model_extra: dict[str, Any] | None
Get extra fields set during validation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dictionary of extra fields, or |
model_fields_set
property
¤
model_fields_set: set[str]
Returns the set of fields that have been explicitly set on this model instance.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of strings representing the fields that have been set, i.e. that were not filled from defaults. |
__class_getitem__
¤
__class_getitem__(typevar_values: type[Any] | tuple[type[Any], ...]) -> type[BaseModel] | _forward_ref.PydanticRecursiveRef
Source code in pydantic/main.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
__copy__
¤
__copy__() -> Self
Returns a shallow copy of the model.
Source code in pydantic/main.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
__deepcopy__
¤
__deepcopy__(memo: dict[int, Any] | None = None) -> Self
Returns a deep copy of the model.
Source code in pydantic/main.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
__delattr__
¤
__delattr__(item: str) -> Any
Source code in pydantic/main.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
__eq__
¤
__eq__(other: Any) -> bool
Source code in pydantic/main.py
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
__get_pydantic_core_schema__
classmethod
¤
__get_pydantic_core_schema__(source: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema
Source code in pydantic/main.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
__get_pydantic_json_schema__
classmethod
¤
__get_pydantic_json_schema__(core_schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue
Hook into generating the model's JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CoreSchema
|
A |
required |
|
GetJsonSchemaHandler
|
Call into Pydantic's internal JSON schema generation.
This will raise a |
required |
Returns:
| Type | Description |
|---|---|
JsonSchemaValue
|
A JSON schema, as a Python object. |
Source code in pydantic/main.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
__getattr__
¤
__getattr__(item: str) -> Any
Source code in pydantic/main.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
__getstate__
¤
__getstate__() -> dict[Any, Any]
Source code in pydantic/main.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
__init_subclass__
¤
__init_subclass__(**kwargs: Unpack[ConfigDict])
This signature is included purely to help type-checkers check arguments to class declaration, which provides a way to conveniently set model_config key/value pairs.
from pydantic import BaseModel
class MyModel(BaseModel, extra='allow'): ...
However, this may be deceiving, since the actual calls to __init_subclass__ will not receive any
of the config arguments, and will only receive any keyword arguments passed during class initialization
that are not expected keys in ConfigDict. (This is due to the way ModelMetaclass.__new__ works.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Unpack[ConfigDict]
|
Keyword arguments passed to the class definition, which set model_config |
{}
|
Note
You may want to override __pydantic_init_subclass__ instead, which behaves similarly but is called
after the class is fully initialized.
Source code in pydantic/main.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
__iter__
¤
__iter__() -> TupleGenerator
So dict(model) works.
Source code in pydantic/main.py
1229 1230 1231 1232 1233 1234 | |
__pydantic_init_subclass__
classmethod
¤
__pydantic_init_subclass__(**kwargs: Any) -> None
This is intended to behave just like __init_subclass__, but is called by ModelMetaclass
only after basic class initialization is complete. In particular, attributes like model_fields will
be present when this is called, but forward annotations are not guaranteed to be resolved yet,
meaning that creating an instance of the class may fail.
This is necessary because __init_subclass__ will always be called by type.__new__,
and it would require a prohibitively large refactor to the ModelMetaclass to ensure that
type.__new__ was called in such a manner that the class would already be sufficiently initialized.
This will receive the same kwargs that would be passed to the standard __init_subclass__, namely,
any kwargs passed to the class definition that aren't used internally by Pydantic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Any keyword arguments passed to the class definition that aren't used internally by Pydantic. |
{}
|
Note
You may want to override __pydantic_on_complete__()
instead, which is called once the class and its fields are fully initialized and ready for validation.
Source code in pydantic/main.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
__pydantic_on_complete__
classmethod
¤
__pydantic_on_complete__() -> None
This is called once the class and its fields are fully initialized and ready to be used.
This typically happens when the class is created (just before
__pydantic_init_subclass__() is called on the superclass),
except when forward annotations are used that could not immediately be resolved.
In that case, it will be called later, when the model is rebuilt automatically or explicitly using
model_rebuild().
Source code in pydantic/main.py
877 878 879 880 881 882 883 884 885 886 | |
__replace__
¤
__replace__(**changes: Any) -> Self
Source code in pydantic/main.py
1125 1126 | |
__repr__
¤
__repr__() -> str
Source code in pydantic/main.py
1236 1237 | |
__repr_args__
¤
__repr_args__() -> _repr.ReprArgs
Source code in pydantic/main.py
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
__setattr__
¤
__setattr__(name: str, value: Any) -> None
Source code in pydantic/main.py
1028 1029 1030 1031 1032 1033 1034 | |
__setstate__
¤
__setstate__(state: dict[Any, Any]) -> None
Source code in pydantic/main.py
1139 1140 1141 1142 1143 | |
__str__
¤
__str__() -> str
Source code in pydantic/main.py
1274 1275 | |
construct
classmethod
¤
construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Source code in pydantic/main.py
1477 1478 1479 1480 1481 1482 1483 1484 1485 | |
copy
¤
copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) -> Self
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in pydantic/main.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | |
dict
¤
dict(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> Dict[str, Any]
Source code in pydantic/main.py
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | |
from_orm
classmethod
¤
from_orm(obj: Any) -> Self
Source code in pydantic/main.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
json
¤
json(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
model_computed_fields
classmethod
¤
model_computed_fields() -> dict[str, ComputedFieldInfo]
A mapping of computed field names to their respective ComputedFieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
273 274 275 276 277 278 279 280 281 282 | |
model_construct
classmethod
¤
model_construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Note
model_construct() generally respects the model_config.extra setting on the provided model.
That is, if model_config.extra == 'allow', then all extra passed values are added to the model instance's __dict__
and __pydantic_extra__ fields. If model_config.extra == 'ignore' (the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct(), having model_config.extra == 'forbid' does not result in
an error if extra values are passed, but they will be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
set[str] | None
|
A set of field names that were originally explicitly set during instantiation. If provided,
this is directly used for the |
None
|
|
Any
|
Trusted or pre-validated data dictionary. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
A new instance of the |
Source code in pydantic/main.py
303 304 305 306 307 308 309 310 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
model_copy
¤
Usage Documentation
Returns a copy of the model.
Note
The underlying instance's [__dict__][object.__dict__] attribute is copied. This
might have unexpected side effects if you store anything in it, on top of the model
fields (e.g. the value of [cached properties][functools.cached_property]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, Any] | None
|
Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data. |
None
|
|
bool
|
Set to |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
New model instance. |
Source code in pydantic/main.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
model_dump
¤
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> dict[str, Any]
Usage Documentation
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Literal['json', 'python'] | str
|
The mode in which |
'python'
|
|
IncEx | None
|
A set of fields to include in the output. |
None
|
|
IncEx | None
|
A set of fields to exclude from the output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to use the field's alias in the dictionary key if defined. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representation of the model. |
Source code in pydantic/main.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
model_dump_json
¤
model_dump_json(*, indent: int | None = None, ensure_ascii: bool = False, include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> str
Usage Documentation
Generates a JSON representation of the model using Pydantic's to_json method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
|
bool
|
If |
False
|
|
IncEx | None
|
Field(s) to include in the JSON output. |
None
|
|
IncEx | None
|
Field(s) to exclude from the JSON output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to serialize using field aliases. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representation of the model. |
Source code in pydantic/main.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
model_fields
classmethod
¤
A mapping of field names to their respective FieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
262 263 264 265 266 267 268 269 270 271 | |
model_json_schema
classmethod
¤
model_json_schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema, mode: JsonSchemaMode = 'validation', *, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of') -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to use attribute aliases or not. |
True
|
|
str
|
The reference template. |
DEFAULT_REF_TEMPLATE
|
|
Literal['any_of', 'primitive_type_array']
|
The format to use when combining schemas from unions together. Can be one of:
|
'any_of'
|
|
type[GenerateJsonSchema]
|
To override the logic used to generate the JSON schema, as a subclass of
|
GenerateJsonSchema
|
|
JsonSchemaMode
|
The mode in which to generate the schema. |
'validation'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON schema for the given model class. |
Source code in pydantic/main.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
model_parametrized_name
classmethod
¤
model_parametrized_name(params: tuple[type[Any], ...]) -> str
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
| Type | Description |
|---|---|
str
|
String representing the new class where |
Raises:
| Type | Description |
|---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in pydantic/main.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
model_post_init
¤
model_post_init(context: Any) -> None
Override this method to perform additional initialization after __init__ and model_construct.
This is useful if you want to do some validation that requires the entire model to be initialized.
Source code in pydantic/main.py
612 613 614 615 | |
model_rebuild
classmethod
¤
model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to force the rebuilding of the model schema, defaults to |
False
|
|
bool
|
Whether to raise errors, defaults to |
True
|
|
int
|
The depth level of the parent namespace, defaults to 2. |
2
|
|
MappingNamespace | None
|
The types namespace, defaults to |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
Returns |
Source code in pydantic/main.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
model_validate
classmethod
¤
model_validate(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, from_attributes: bool | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate a pydantic model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
bool | None
|
Whether to extract data from object attributes. |
None
|
|
Any | None
|
Additional context to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the object could not be validated. |
Returns:
| Type | Description |
|---|---|
Self
|
The validated model instance. |
Source code in pydantic/main.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
model_validate_json
classmethod
¤
model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Usage Documentation
Validate the given JSON data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in pydantic/main.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
model_validate_strings
classmethod
¤
model_validate_strings(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate the given object with string data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object containing string data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Source code in pydantic/main.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
parse_file
classmethod
¤
parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
parse_obj
classmethod
¤
parse_obj(obj: Any) -> Self
Source code in pydantic/main.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 | |
parse_raw
classmethod
¤
parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
schema
classmethod
¤
schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE) -> Dict[str, Any]
Source code in pydantic/main.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 | |
schema_json
classmethod
¤
schema_json(*, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
update_forward_refs
classmethod
¤
update_forward_refs(**localns: Any) -> None
Source code in pydantic/main.py
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
validate
classmethod
¤
validate(value: Any) -> Self
Source code in pydantic/main.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 | |
EmptyCache
¤
EmptyCache(**data: Any)
Bases: CmdBase
flowchart TD
bioimageio.core.cli.EmptyCache[EmptyCache]
bioimageio.core.cli.CmdBase[CmdBase]
pydantic.main.BaseModel[BaseModel]
bioimageio.core.cli.CmdBase --> bioimageio.core.cli.EmptyCache
pydantic.main.BaseModel --> bioimageio.core.cli.CmdBase
click bioimageio.core.cli.EmptyCache href "" "bioimageio.core.cli.EmptyCache"
click bioimageio.core.cli.CmdBase href "" "bioimageio.core.cli.CmdBase"
click pydantic.main.BaseModel href "" "pydantic.main.BaseModel"
Empty the bioimageio cache directory.
Raises ValidationError if the input data cannot be
validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Methods:
| Name | Description |
|---|---|
__class_getitem__ |
|
__copy__ |
Returns a shallow copy of the model. |
__deepcopy__ |
Returns a deep copy of the model. |
__delattr__ |
|
__eq__ |
|
__get_pydantic_core_schema__ |
|
__get_pydantic_json_schema__ |
Hook into generating the model's JSON schema. |
__getattr__ |
|
__getstate__ |
|
__init_subclass__ |
This signature is included purely to help type-checkers check arguments to class declaration, which |
__iter__ |
So |
__pydantic_init_subclass__ |
This is intended to behave just like |
__pydantic_on_complete__ |
This is called once the class and its fields are fully initialized and ready to be used. |
__replace__ |
|
__repr__ |
|
__repr_args__ |
|
__setattr__ |
|
__setstate__ |
|
__str__ |
|
cli_cmd |
|
construct |
|
copy |
Returns a copy of the model. |
dict |
|
from_orm |
|
json |
|
model_computed_fields |
A mapping of computed field names to their respective |
model_construct |
Creates a new instance of the |
model_copy |
Usage Documentation |
model_dump |
Usage Documentation |
model_dump_json |
Usage Documentation |
model_fields |
A mapping of field names to their respective |
model_json_schema |
Generates a JSON schema for a model class. |
model_parametrized_name |
Compute the class name for parametrizations of generic classes. |
model_post_init |
Override this method to perform additional initialization after |
model_rebuild |
Try to rebuild the pydantic-core schema for the model. |
model_validate |
Validate a pydantic model instance. |
model_validate_json |
Usage Documentation |
model_validate_strings |
Validate the given object with string data against the Pydantic model. |
parse_file |
|
parse_obj |
|
parse_raw |
|
schema |
|
schema_json |
|
update_forward_refs |
|
validate |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__class_vars__ |
set[str]
|
The names of the class variables defined on the model. |
__fields__ |
dict[str, FieldInfo]
|
|
__fields_set__ |
set[str]
|
|
__pretty__ |
|
|
__private_attributes__ |
Dict[str, ModelPrivateAttr]
|
Metadata about the private attributes of the model. |
__pydantic_complete__ |
bool
|
Whether model building is completed, or if there are still undefined fields. |
__pydantic_computed_fields__ |
Dict[str, ComputedFieldInfo]
|
A dictionary of computed field names and their corresponding |
__pydantic_core_schema__ |
CoreSchema
|
The core schema of the model. |
__pydantic_custom_init__ |
bool
|
Whether the model has a custom |
__pydantic_decorators__ |
_decorators.DecoratorInfos
|
Metadata containing the decorators defined on the model. |
__pydantic_extra__ |
Dict[str, Any] | None
|
A dictionary containing extra values, if |
__pydantic_fields__ |
Dict[str, FieldInfo]
|
A dictionary of field names and their corresponding |
__pydantic_fields_set__ |
set[str]
|
The names of fields explicitly set during instantiation. |
__pydantic_generic_metadata__ |
_generics.PydanticGenericMetadata
|
Metadata for generic models; contains data used for a similar purpose to |
__pydantic_parent_namespace__ |
Dict[str, Any] | None
|
Parent namespace of the model, used for automatic rebuilding of models. |
__pydantic_post_init__ |
None | Literal['model_post_init']
|
The name of the post-init method for the model, if defined. |
__pydantic_private__ |
Dict[str, Any] | None
|
Values of private attributes set on the model instance. |
__pydantic_root_model__ |
bool
|
Whether the model is a |
__pydantic_serializer__ |
SchemaSerializer
|
The |
__pydantic_setattr_handlers__ |
Dict[str, Callable[[BaseModel, str, Any], None]]
|
|
__pydantic_validator__ |
SchemaValidator | PluggableSchemaValidator
|
The |
__repr_name__ |
|
|
__repr_recursion__ |
|
|
__repr_str__ |
|
|
__rich_repr__ |
|
|
__signature__ |
Signature
|
The synthesized |
__slots__ |
|
|
model_config |
ConfigDict
|
Configuration for the model, should be a dictionary conforming to |
model_extra |
dict[str, Any] | None
|
Get extra fields set during validation. |
model_fields_set |
set[str]
|
Returns the set of fields that have been explicitly set on this model instance. |
Source code in pydantic/main.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__class_vars__
class-attribute
¤
__class_vars__: set[str]
The names of the class variables defined on the model.
__private_attributes__
class-attribute
¤
__private_attributes__: Dict[str, ModelPrivateAttr]
Metadata about the private attributes of the model.
__pydantic_complete__
class-attribute
¤
__pydantic_complete__: bool = False
Whether model building is completed, or if there are still undefined fields.
__pydantic_computed_fields__
class-attribute
¤
__pydantic_computed_fields__: Dict[str, ComputedFieldInfo]
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
__pydantic_core_schema__
class-attribute
¤
__pydantic_core_schema__: CoreSchema
The core schema of the model.
__pydantic_custom_init__
class-attribute
¤
__pydantic_custom_init__: bool
Whether the model has a custom __init__ method.
__pydantic_decorators__
class-attribute
¤
__pydantic_decorators__: _decorators.DecoratorInfos = _decorators.DecoratorInfos()
Metadata containing the decorators defined on the model.
This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
__pydantic_extra__
pydantic-field
¤
__pydantic_extra__: Dict[str, Any] | None
A dictionary containing extra values, if extra is set to 'allow'.
__pydantic_fields__
class-attribute
¤
__pydantic_fields__: Dict[str, FieldInfo]
A dictionary of field names and their corresponding FieldInfo objects.
This replaces Model.__fields__ from Pydantic V1.
__pydantic_fields_set__
pydantic-field
¤
__pydantic_fields_set__: set[str]
The names of fields explicitly set during instantiation.
__pydantic_generic_metadata__
class-attribute
¤
__pydantic_generic_metadata__: _generics.PydanticGenericMetadata
Metadata for generic models; contains data used for a similar purpose to args, origin, parameters in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__
class-attribute
¤
__pydantic_parent_namespace__: Dict[str, Any] | None = None
Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__
class-attribute
¤
__pydantic_post_init__: None | Literal['model_post_init']
The name of the post-init method for the model, if defined.
__pydantic_private__
pydantic-field
¤
__pydantic_private__: Dict[str, Any] | None
Values of private attributes set on the model instance.
__pydantic_root_model__
class-attribute
¤
__pydantic_root_model__: bool = False
Whether the model is a RootModel.
__pydantic_serializer__
class-attribute
¤
__pydantic_serializer__: SchemaSerializer
The pydantic-core SchemaSerializer used to dump instances of the model.
__pydantic_setattr_handlers__
class-attribute
¤
__pydantic_setattr_handlers__: Dict[str, Callable[[BaseModel, str, Any], None]]
__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__
__pydantic_validator__
class-attribute
¤
__pydantic_validator__: SchemaValidator | PluggableSchemaValidator
The pydantic-core SchemaValidator used to validate instances of the model.
__signature__
class-attribute
¤
__signature__: Signature
The synthesized __init__ [Signature][inspect.Signature] of the model.
__slots__
pydantic-field
¤
__slots__ = ('__dict__', '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__')
model_config
class-attribute
¤
model_config: ConfigDict = ConfigDict()
Configuration for the model, should be a dictionary conforming to ConfigDict.
model_extra
property
¤
model_extra: dict[str, Any] | None
Get extra fields set during validation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dictionary of extra fields, or |
model_fields_set
property
¤
model_fields_set: set[str]
Returns the set of fields that have been explicitly set on this model instance.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of strings representing the fields that have been set, i.e. that were not filled from defaults. |
__class_getitem__
¤
__class_getitem__(typevar_values: type[Any] | tuple[type[Any], ...]) -> type[BaseModel] | _forward_ref.PydanticRecursiveRef
Source code in pydantic/main.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
__copy__
¤
__copy__() -> Self
Returns a shallow copy of the model.
Source code in pydantic/main.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
__deepcopy__
¤
__deepcopy__(memo: dict[int, Any] | None = None) -> Self
Returns a deep copy of the model.
Source code in pydantic/main.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
__delattr__
¤
__delattr__(item: str) -> Any
Source code in pydantic/main.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
__eq__
¤
__eq__(other: Any) -> bool
Source code in pydantic/main.py
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
__get_pydantic_core_schema__
classmethod
¤
__get_pydantic_core_schema__(source: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema
Source code in pydantic/main.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
__get_pydantic_json_schema__
classmethod
¤
__get_pydantic_json_schema__(core_schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue
Hook into generating the model's JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CoreSchema
|
A |
required |
|
GetJsonSchemaHandler
|
Call into Pydantic's internal JSON schema generation.
This will raise a |
required |
Returns:
| Type | Description |
|---|---|
JsonSchemaValue
|
A JSON schema, as a Python object. |
Source code in pydantic/main.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
__getattr__
¤
__getattr__(item: str) -> Any
Source code in pydantic/main.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
__getstate__
¤
__getstate__() -> dict[Any, Any]
Source code in pydantic/main.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
__init_subclass__
¤
__init_subclass__(**kwargs: Unpack[ConfigDict])
This signature is included purely to help type-checkers check arguments to class declaration, which provides a way to conveniently set model_config key/value pairs.
from pydantic import BaseModel
class MyModel(BaseModel, extra='allow'): ...
However, this may be deceiving, since the actual calls to __init_subclass__ will not receive any
of the config arguments, and will only receive any keyword arguments passed during class initialization
that are not expected keys in ConfigDict. (This is due to the way ModelMetaclass.__new__ works.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Unpack[ConfigDict]
|
Keyword arguments passed to the class definition, which set model_config |
{}
|
Note
You may want to override __pydantic_init_subclass__ instead, which behaves similarly but is called
after the class is fully initialized.
Source code in pydantic/main.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
__iter__
¤
__iter__() -> TupleGenerator
So dict(model) works.
Source code in pydantic/main.py
1229 1230 1231 1232 1233 1234 | |
__pydantic_init_subclass__
classmethod
¤
__pydantic_init_subclass__(**kwargs: Any) -> None
This is intended to behave just like __init_subclass__, but is called by ModelMetaclass
only after basic class initialization is complete. In particular, attributes like model_fields will
be present when this is called, but forward annotations are not guaranteed to be resolved yet,
meaning that creating an instance of the class may fail.
This is necessary because __init_subclass__ will always be called by type.__new__,
and it would require a prohibitively large refactor to the ModelMetaclass to ensure that
type.__new__ was called in such a manner that the class would already be sufficiently initialized.
This will receive the same kwargs that would be passed to the standard __init_subclass__, namely,
any kwargs passed to the class definition that aren't used internally by Pydantic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Any keyword arguments passed to the class definition that aren't used internally by Pydantic. |
{}
|
Note
You may want to override __pydantic_on_complete__()
instead, which is called once the class and its fields are fully initialized and ready for validation.
Source code in pydantic/main.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
__pydantic_on_complete__
classmethod
¤
__pydantic_on_complete__() -> None
This is called once the class and its fields are fully initialized and ready to be used.
This typically happens when the class is created (just before
__pydantic_init_subclass__() is called on the superclass),
except when forward annotations are used that could not immediately be resolved.
In that case, it will be called later, when the model is rebuilt automatically or explicitly using
model_rebuild().
Source code in pydantic/main.py
877 878 879 880 881 882 883 884 885 886 | |
__replace__
¤
__replace__(**changes: Any) -> Self
Source code in pydantic/main.py
1125 1126 | |
__repr__
¤
__repr__() -> str
Source code in pydantic/main.py
1236 1237 | |
__repr_args__
¤
__repr_args__() -> _repr.ReprArgs
Source code in pydantic/main.py
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
__setattr__
¤
__setattr__(name: str, value: Any) -> None
Source code in pydantic/main.py
1028 1029 1030 1031 1032 1033 1034 | |
__setstate__
¤
__setstate__(state: dict[Any, Any]) -> None
Source code in pydantic/main.py
1139 1140 1141 1142 1143 | |
__str__
¤
__str__() -> str
Source code in pydantic/main.py
1274 1275 | |
cli_cmd
¤
cli_cmd()
Source code in src/bioimageio/core/cli.py
814 815 | |
construct
classmethod
¤
construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Source code in pydantic/main.py
1477 1478 1479 1480 1481 1482 1483 1484 1485 | |
copy
¤
copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) -> Self
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in pydantic/main.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | |
dict
¤
dict(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> Dict[str, Any]
Source code in pydantic/main.py
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | |
from_orm
classmethod
¤
from_orm(obj: Any) -> Self
Source code in pydantic/main.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
json
¤
json(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
model_computed_fields
classmethod
¤
model_computed_fields() -> dict[str, ComputedFieldInfo]
A mapping of computed field names to their respective ComputedFieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
273 274 275 276 277 278 279 280 281 282 | |
model_construct
classmethod
¤
model_construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Note
model_construct() generally respects the model_config.extra setting on the provided model.
That is, if model_config.extra == 'allow', then all extra passed values are added to the model instance's __dict__
and __pydantic_extra__ fields. If model_config.extra == 'ignore' (the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct(), having model_config.extra == 'forbid' does not result in
an error if extra values are passed, but they will be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
set[str] | None
|
A set of field names that were originally explicitly set during instantiation. If provided,
this is directly used for the |
None
|
|
Any
|
Trusted or pre-validated data dictionary. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
A new instance of the |
Source code in pydantic/main.py
303 304 305 306 307 308 309 310 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
model_copy
¤
Usage Documentation
Returns a copy of the model.
Note
The underlying instance's [__dict__][object.__dict__] attribute is copied. This
might have unexpected side effects if you store anything in it, on top of the model
fields (e.g. the value of [cached properties][functools.cached_property]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, Any] | None
|
Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data. |
None
|
|
bool
|
Set to |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
New model instance. |
Source code in pydantic/main.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
model_dump
¤
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> dict[str, Any]
Usage Documentation
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Literal['json', 'python'] | str
|
The mode in which |
'python'
|
|
IncEx | None
|
A set of fields to include in the output. |
None
|
|
IncEx | None
|
A set of fields to exclude from the output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to use the field's alias in the dictionary key if defined. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representation of the model. |
Source code in pydantic/main.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
model_dump_json
¤
model_dump_json(*, indent: int | None = None, ensure_ascii: bool = False, include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> str
Usage Documentation
Generates a JSON representation of the model using Pydantic's to_json method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
|
bool
|
If |
False
|
|
IncEx | None
|
Field(s) to include in the JSON output. |
None
|
|
IncEx | None
|
Field(s) to exclude from the JSON output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to serialize using field aliases. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representation of the model. |
Source code in pydantic/main.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
model_fields
classmethod
¤
A mapping of field names to their respective FieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
262 263 264 265 266 267 268 269 270 271 | |
model_json_schema
classmethod
¤
model_json_schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema, mode: JsonSchemaMode = 'validation', *, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of') -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to use attribute aliases or not. |
True
|
|
str
|
The reference template. |
DEFAULT_REF_TEMPLATE
|
|
Literal['any_of', 'primitive_type_array']
|
The format to use when combining schemas from unions together. Can be one of:
|
'any_of'
|
|
type[GenerateJsonSchema]
|
To override the logic used to generate the JSON schema, as a subclass of
|
GenerateJsonSchema
|
|
JsonSchemaMode
|
The mode in which to generate the schema. |
'validation'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON schema for the given model class. |
Source code in pydantic/main.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
model_parametrized_name
classmethod
¤
model_parametrized_name(params: tuple[type[Any], ...]) -> str
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
| Type | Description |
|---|---|
str
|
String representing the new class where |
Raises:
| Type | Description |
|---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in pydantic/main.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
model_post_init
¤
model_post_init(context: Any) -> None
Override this method to perform additional initialization after __init__ and model_construct.
This is useful if you want to do some validation that requires the entire model to be initialized.
Source code in pydantic/main.py
612 613 614 615 | |
model_rebuild
classmethod
¤
model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to force the rebuilding of the model schema, defaults to |
False
|
|
bool
|
Whether to raise errors, defaults to |
True
|
|
int
|
The depth level of the parent namespace, defaults to 2. |
2
|
|
MappingNamespace | None
|
The types namespace, defaults to |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
Returns |
Source code in pydantic/main.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
model_validate
classmethod
¤
model_validate(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, from_attributes: bool | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate a pydantic model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
bool | None
|
Whether to extract data from object attributes. |
None
|
|
Any | None
|
Additional context to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the object could not be validated. |
Returns:
| Type | Description |
|---|---|
Self
|
The validated model instance. |
Source code in pydantic/main.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
model_validate_json
classmethod
¤
model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Usage Documentation
Validate the given JSON data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in pydantic/main.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
model_validate_strings
classmethod
¤
model_validate_strings(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate the given object with string data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object containing string data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Source code in pydantic/main.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
parse_file
classmethod
¤
parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
parse_obj
classmethod
¤
parse_obj(obj: Any) -> Self
Source code in pydantic/main.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 | |
parse_raw
classmethod
¤
parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
schema
classmethod
¤
schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE) -> Dict[str, Any]
Source code in pydantic/main.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 | |
schema_json
classmethod
¤
schema_json(*, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
update_forward_refs
classmethod
¤
update_forward_refs(**localns: Any) -> None
Source code in pydantic/main.py
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
validate
classmethod
¤
validate(value: Any) -> Self
Source code in pydantic/main.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 | |
PackageCmd
¤
PackageCmd(**data: Any)
Bases: CmdBase, WithSource, WithSummaryLogging
flowchart TD
bioimageio.core.cli.PackageCmd[PackageCmd]
bioimageio.core.cli.CmdBase[CmdBase]
bioimageio.core.cli.WithSource[WithSource]
bioimageio.core.cli.WithSummaryLogging[WithSummaryLogging]
bioimageio.core.cli.ArgMixin[ArgMixin]
pydantic.main.BaseModel[BaseModel]
bioimageio.core.cli.CmdBase --> bioimageio.core.cli.PackageCmd
pydantic.main.BaseModel --> bioimageio.core.cli.CmdBase
bioimageio.core.cli.WithSource --> bioimageio.core.cli.PackageCmd
bioimageio.core.cli.ArgMixin --> bioimageio.core.cli.WithSource
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
bioimageio.core.cli.WithSummaryLogging --> bioimageio.core.cli.PackageCmd
bioimageio.core.cli.ArgMixin --> bioimageio.core.cli.WithSummaryLogging
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
click bioimageio.core.cli.PackageCmd href "" "bioimageio.core.cli.PackageCmd"
click bioimageio.core.cli.CmdBase href "" "bioimageio.core.cli.CmdBase"
click bioimageio.core.cli.WithSource href "" "bioimageio.core.cli.WithSource"
click bioimageio.core.cli.WithSummaryLogging href "" "bioimageio.core.cli.WithSummaryLogging"
click bioimageio.core.cli.ArgMixin href "" "bioimageio.core.cli.ArgMixin"
click pydantic.main.BaseModel href "" "pydantic.main.BaseModel"
Save a resource's metadata with its associated files.
Raises ValidationError if the input data cannot be
validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Methods:
| Name | Description |
|---|---|
__class_getitem__ |
|
__copy__ |
Returns a shallow copy of the model. |
__deepcopy__ |
Returns a deep copy of the model. |
__delattr__ |
|
__eq__ |
|
__get_pydantic_core_schema__ |
|
__get_pydantic_json_schema__ |
Hook into generating the model's JSON schema. |
__getattr__ |
|
__getstate__ |
|
__init_subclass__ |
This signature is included purely to help type-checkers check arguments to class declaration, which |
__iter__ |
So |
__pydantic_init_subclass__ |
This is intended to behave just like |
__pydantic_on_complete__ |
This is called once the class and its fields are fully initialized and ready to be used. |
__replace__ |
|
__repr__ |
|
__repr_args__ |
|
__setattr__ |
|
__setstate__ |
|
__str__ |
|
cli_cmd |
|
construct |
|
copy |
Returns a copy of the model. |
dict |
|
from_orm |
|
json |
|
log |
|
model_computed_fields |
A mapping of computed field names to their respective |
model_construct |
Creates a new instance of the |
model_copy |
Usage Documentation |
model_dump |
Usage Documentation |
model_dump_json |
Usage Documentation |
model_fields |
A mapping of field names to their respective |
model_json_schema |
Generates a JSON schema for a model class. |
model_parametrized_name |
Compute the class name for parametrizations of generic classes. |
model_post_init |
Override this method to perform additional initialization after |
model_rebuild |
Try to rebuild the pydantic-core schema for the model. |
model_validate |
Validate a pydantic model instance. |
model_validate_json |
Usage Documentation |
model_validate_strings |
Validate the given object with string data against the Pydantic model. |
parse_file |
|
parse_obj |
|
parse_raw |
|
schema |
|
schema_json |
|
update_forward_refs |
|
validate |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__class_vars__ |
set[str]
|
The names of the class variables defined on the model. |
__fields__ |
dict[str, FieldInfo]
|
|
__fields_set__ |
set[str]
|
|
__pretty__ |
|
|
__private_attributes__ |
Dict[str, ModelPrivateAttr]
|
Metadata about the private attributes of the model. |
__pydantic_complete__ |
bool
|
Whether model building is completed, or if there are still undefined fields. |
__pydantic_computed_fields__ |
Dict[str, ComputedFieldInfo]
|
A dictionary of computed field names and their corresponding |
__pydantic_core_schema__ |
CoreSchema
|
The core schema of the model. |
__pydantic_custom_init__ |
bool
|
Whether the model has a custom |
__pydantic_decorators__ |
_decorators.DecoratorInfos
|
Metadata containing the decorators defined on the model. |
__pydantic_extra__ |
Dict[str, Any] | None
|
A dictionary containing extra values, if |
__pydantic_fields__ |
Dict[str, FieldInfo]
|
A dictionary of field names and their corresponding |
__pydantic_fields_set__ |
set[str]
|
The names of fields explicitly set during instantiation. |
__pydantic_generic_metadata__ |
_generics.PydanticGenericMetadata
|
Metadata for generic models; contains data used for a similar purpose to |
__pydantic_parent_namespace__ |
Dict[str, Any] | None
|
Parent namespace of the model, used for automatic rebuilding of models. |
__pydantic_post_init__ |
None | Literal['model_post_init']
|
The name of the post-init method for the model, if defined. |
__pydantic_private__ |
Dict[str, Any] | None
|
Values of private attributes set on the model instance. |
__pydantic_root_model__ |
bool
|
Whether the model is a |
__pydantic_serializer__ |
SchemaSerializer
|
The |
__pydantic_setattr_handlers__ |
Dict[str, Callable[[BaseModel, str, Any], None]]
|
|
__pydantic_validator__ |
SchemaValidator | PluggableSchemaValidator
|
The |
__repr_name__ |
|
|
__repr_recursion__ |
|
|
__repr_str__ |
|
|
__rich_repr__ |
|
|
__signature__ |
Signature
|
The synthesized |
__slots__ |
|
|
descr |
|
|
descr_id |
str
|
a more user-friendly description id |
model_config |
ConfigDict
|
Configuration for the model, should be a dictionary conforming to |
model_extra |
dict[str, Any] | None
|
Get extra fields set during validation. |
model_fields_set |
set[str]
|
Returns the set of fields that have been explicitly set on this model instance. |
path |
CliPositionalArg[Path]
|
The path to write the (zipped) package to. |
source |
CliPositionalArg[str]
|
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file |
summary |
List[Union[Literal['display'], Path]]
|
Display the validation summary or save it as JSON, Markdown or HTML. |
weight_format |
WeightFormatArgAll
|
The weight format to include in the package (for model descriptions only). |
Source code in pydantic/main.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__class_vars__
class-attribute
¤
__class_vars__: set[str]
The names of the class variables defined on the model.
__private_attributes__
class-attribute
¤
__private_attributes__: Dict[str, ModelPrivateAttr]
Metadata about the private attributes of the model.
__pydantic_complete__
class-attribute
¤
__pydantic_complete__: bool = False
Whether model building is completed, or if there are still undefined fields.
__pydantic_computed_fields__
class-attribute
¤
__pydantic_computed_fields__: Dict[str, ComputedFieldInfo]
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
__pydantic_core_schema__
class-attribute
¤
__pydantic_core_schema__: CoreSchema
The core schema of the model.
__pydantic_custom_init__
class-attribute
¤
__pydantic_custom_init__: bool
Whether the model has a custom __init__ method.
__pydantic_decorators__
class-attribute
¤
__pydantic_decorators__: _decorators.DecoratorInfos = _decorators.DecoratorInfos()
Metadata containing the decorators defined on the model.
This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
__pydantic_extra__
pydantic-field
¤
__pydantic_extra__: Dict[str, Any] | None
A dictionary containing extra values, if extra is set to 'allow'.
__pydantic_fields__
class-attribute
¤
__pydantic_fields__: Dict[str, FieldInfo]
A dictionary of field names and their corresponding FieldInfo objects.
This replaces Model.__fields__ from Pydantic V1.
__pydantic_fields_set__
pydantic-field
¤
__pydantic_fields_set__: set[str]
The names of fields explicitly set during instantiation.
__pydantic_generic_metadata__
class-attribute
¤
__pydantic_generic_metadata__: _generics.PydanticGenericMetadata
Metadata for generic models; contains data used for a similar purpose to args, origin, parameters in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__
class-attribute
¤
__pydantic_parent_namespace__: Dict[str, Any] | None = None
Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__
class-attribute
¤
__pydantic_post_init__: None | Literal['model_post_init']
The name of the post-init method for the model, if defined.
__pydantic_private__
pydantic-field
¤
__pydantic_private__: Dict[str, Any] | None
Values of private attributes set on the model instance.
__pydantic_root_model__
class-attribute
¤
__pydantic_root_model__: bool = False
Whether the model is a RootModel.
__pydantic_serializer__
class-attribute
¤
__pydantic_serializer__: SchemaSerializer
The pydantic-core SchemaSerializer used to dump instances of the model.
__pydantic_setattr_handlers__
class-attribute
¤
__pydantic_setattr_handlers__: Dict[str, Callable[[BaseModel, str, Any], None]]
__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__
__pydantic_validator__
class-attribute
¤
__pydantic_validator__: SchemaValidator | PluggableSchemaValidator
The pydantic-core SchemaValidator used to validate instances of the model.
__signature__
class-attribute
¤
__signature__: Signature
The synthesized __init__ [Signature][inspect.Signature] of the model.
__slots__
pydantic-field
¤
__slots__ = ('__dict__', '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__')
descr_id
property
¤
descr_id: str
a more user-friendly description id (replacing legacy ids with their nicknames)
model_config
class-attribute
¤
model_config: ConfigDict = ConfigDict()
Configuration for the model, should be a dictionary conforming to ConfigDict.
model_extra
property
¤
model_extra: dict[str, Any] | None
Get extra fields set during validation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dictionary of extra fields, or |
model_fields_set
property
¤
model_fields_set: set[str]
Returns the set of fields that have been explicitly set on this model instance.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of strings representing the fields that have been set, i.e. that were not filled from defaults. |
path
instance-attribute
¤
path: CliPositionalArg[Path]
The path to write the (zipped) package to.
If it does not have a .zip suffix
this command will save the package as an unzipped folder instead.
source
instance-attribute
¤
source: CliPositionalArg[str]
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file or a bioimage.io resource identifier, e.g. 'affable-shark'
summary
class-attribute
instance-attribute
¤
summary: List[Union[Literal['display'], Path]] = Field(default_factory=lambda: ['display'], examples=[Path('summary.md'), Path('bioimageio_summaries/'), ['display', Path('summary.md')]])
Display the validation summary or save it as JSON, Markdown or HTML.
The format is chosen based on the suffix: .json, .md, .html.
If a folder is given (path w/o suffix) the summary is saved in all formats.
Choose/add "display" to render the validation summary to the terminal.
weight_format
class-attribute
instance-attribute
¤
weight_format: WeightFormatArgAll = Field('all', alias='weight-format', validation_alias=WEIGHT_FORMAT_ALIASES)
The weight format to include in the package (for model descriptions only).
__class_getitem__
¤
__class_getitem__(typevar_values: type[Any] | tuple[type[Any], ...]) -> type[BaseModel] | _forward_ref.PydanticRecursiveRef
Source code in pydantic/main.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
__copy__
¤
__copy__() -> Self
Returns a shallow copy of the model.
Source code in pydantic/main.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
__deepcopy__
¤
__deepcopy__(memo: dict[int, Any] | None = None) -> Self
Returns a deep copy of the model.
Source code in pydantic/main.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
__delattr__
¤
__delattr__(item: str) -> Any
Source code in pydantic/main.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
__eq__
¤
__eq__(other: Any) -> bool
Source code in pydantic/main.py
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
__get_pydantic_core_schema__
classmethod
¤
__get_pydantic_core_schema__(source: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema
Source code in pydantic/main.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
__get_pydantic_json_schema__
classmethod
¤
__get_pydantic_json_schema__(core_schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue
Hook into generating the model's JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CoreSchema
|
A |
required |
|
GetJsonSchemaHandler
|
Call into Pydantic's internal JSON schema generation.
This will raise a |
required |
Returns:
| Type | Description |
|---|---|
JsonSchemaValue
|
A JSON schema, as a Python object. |
Source code in pydantic/main.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
__getattr__
¤
__getattr__(item: str) -> Any
Source code in pydantic/main.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
__getstate__
¤
__getstate__() -> dict[Any, Any]
Source code in pydantic/main.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
__init_subclass__
¤
__init_subclass__(**kwargs: Unpack[ConfigDict])
This signature is included purely to help type-checkers check arguments to class declaration, which provides a way to conveniently set model_config key/value pairs.
from pydantic import BaseModel
class MyModel(BaseModel, extra='allow'): ...
However, this may be deceiving, since the actual calls to __init_subclass__ will not receive any
of the config arguments, and will only receive any keyword arguments passed during class initialization
that are not expected keys in ConfigDict. (This is due to the way ModelMetaclass.__new__ works.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Unpack[ConfigDict]
|
Keyword arguments passed to the class definition, which set model_config |
{}
|
Note
You may want to override __pydantic_init_subclass__ instead, which behaves similarly but is called
after the class is fully initialized.
Source code in pydantic/main.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
__iter__
¤
__iter__() -> TupleGenerator
So dict(model) works.
Source code in pydantic/main.py
1229 1230 1231 1232 1233 1234 | |
__pydantic_init_subclass__
classmethod
¤
__pydantic_init_subclass__(**kwargs: Any) -> None
This is intended to behave just like __init_subclass__, but is called by ModelMetaclass
only after basic class initialization is complete. In particular, attributes like model_fields will
be present when this is called, but forward annotations are not guaranteed to be resolved yet,
meaning that creating an instance of the class may fail.
This is necessary because __init_subclass__ will always be called by type.__new__,
and it would require a prohibitively large refactor to the ModelMetaclass to ensure that
type.__new__ was called in such a manner that the class would already be sufficiently initialized.
This will receive the same kwargs that would be passed to the standard __init_subclass__, namely,
any kwargs passed to the class definition that aren't used internally by Pydantic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Any keyword arguments passed to the class definition that aren't used internally by Pydantic. |
{}
|
Note
You may want to override __pydantic_on_complete__()
instead, which is called once the class and its fields are fully initialized and ready for validation.
Source code in pydantic/main.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
__pydantic_on_complete__
classmethod
¤
__pydantic_on_complete__() -> None
This is called once the class and its fields are fully initialized and ready to be used.
This typically happens when the class is created (just before
__pydantic_init_subclass__() is called on the superclass),
except when forward annotations are used that could not immediately be resolved.
In that case, it will be called later, when the model is rebuilt automatically or explicitly using
model_rebuild().
Source code in pydantic/main.py
877 878 879 880 881 882 883 884 885 886 | |
__replace__
¤
__replace__(**changes: Any) -> Self
Source code in pydantic/main.py
1125 1126 | |
__repr__
¤
__repr__() -> str
Source code in pydantic/main.py
1236 1237 | |
__repr_args__
¤
__repr_args__() -> _repr.ReprArgs
Source code in pydantic/main.py
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
__setattr__
¤
__setattr__(name: str, value: Any) -> None
Source code in pydantic/main.py
1028 1029 1030 1031 1032 1033 1034 | |
__setstate__
¤
__setstate__(state: dict[Any, Any]) -> None
Source code in pydantic/main.py
1139 1140 1141 1142 1143 | |
__str__
¤
__str__() -> str
Source code in pydantic/main.py
1274 1275 | |
cli_cmd
¤
cli_cmd()
Source code in src/bioimageio/core/cli.py
262 263 264 265 266 267 268 269 270 271 272 273 | |
construct
classmethod
¤
construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Source code in pydantic/main.py
1477 1478 1479 1480 1481 1482 1483 1484 1485 | |
copy
¤
copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) -> Self
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in pydantic/main.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | |
dict
¤
dict(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> Dict[str, Any]
Source code in pydantic/main.py
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | |
from_orm
classmethod
¤
from_orm(obj: Any) -> Self
Source code in pydantic/main.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
json
¤
json(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
log
¤
log(descr: Union[ResourceDescr, InvalidDescr])
Source code in src/bioimageio/core/cli.py
131 132 | |
model_computed_fields
classmethod
¤
model_computed_fields() -> dict[str, ComputedFieldInfo]
A mapping of computed field names to their respective ComputedFieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
273 274 275 276 277 278 279 280 281 282 | |
model_construct
classmethod
¤
model_construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Note
model_construct() generally respects the model_config.extra setting on the provided model.
That is, if model_config.extra == 'allow', then all extra passed values are added to the model instance's __dict__
and __pydantic_extra__ fields. If model_config.extra == 'ignore' (the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct(), having model_config.extra == 'forbid' does not result in
an error if extra values are passed, but they will be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
set[str] | None
|
A set of field names that were originally explicitly set during instantiation. If provided,
this is directly used for the |
None
|
|
Any
|
Trusted or pre-validated data dictionary. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
A new instance of the |
Source code in pydantic/main.py
303 304 305 306 307 308 309 310 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
model_copy
¤
Usage Documentation
Returns a copy of the model.
Note
The underlying instance's [__dict__][object.__dict__] attribute is copied. This
might have unexpected side effects if you store anything in it, on top of the model
fields (e.g. the value of [cached properties][functools.cached_property]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, Any] | None
|
Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data. |
None
|
|
bool
|
Set to |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
New model instance. |
Source code in pydantic/main.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
model_dump
¤
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> dict[str, Any]
Usage Documentation
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Literal['json', 'python'] | str
|
The mode in which |
'python'
|
|
IncEx | None
|
A set of fields to include in the output. |
None
|
|
IncEx | None
|
A set of fields to exclude from the output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to use the field's alias in the dictionary key if defined. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representation of the model. |
Source code in pydantic/main.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
model_dump_json
¤
model_dump_json(*, indent: int | None = None, ensure_ascii: bool = False, include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> str
Usage Documentation
Generates a JSON representation of the model using Pydantic's to_json method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
|
bool
|
If |
False
|
|
IncEx | None
|
Field(s) to include in the JSON output. |
None
|
|
IncEx | None
|
Field(s) to exclude from the JSON output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to serialize using field aliases. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representation of the model. |
Source code in pydantic/main.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
model_fields
classmethod
¤
A mapping of field names to their respective FieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
262 263 264 265 266 267 268 269 270 271 | |
model_json_schema
classmethod
¤
model_json_schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema, mode: JsonSchemaMode = 'validation', *, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of') -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to use attribute aliases or not. |
True
|
|
str
|
The reference template. |
DEFAULT_REF_TEMPLATE
|
|
Literal['any_of', 'primitive_type_array']
|
The format to use when combining schemas from unions together. Can be one of:
|
'any_of'
|
|
type[GenerateJsonSchema]
|
To override the logic used to generate the JSON schema, as a subclass of
|
GenerateJsonSchema
|
|
JsonSchemaMode
|
The mode in which to generate the schema. |
'validation'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON schema for the given model class. |
Source code in pydantic/main.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
model_parametrized_name
classmethod
¤
model_parametrized_name(params: tuple[type[Any], ...]) -> str
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
| Type | Description |
|---|---|
str
|
String representing the new class where |
Raises:
| Type | Description |
|---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in pydantic/main.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
model_post_init
¤
model_post_init(context: Any) -> None
Override this method to perform additional initialization after __init__ and model_construct.
This is useful if you want to do some validation that requires the entire model to be initialized.
Source code in pydantic/main.py
612 613 614 615 | |
model_rebuild
classmethod
¤
model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to force the rebuilding of the model schema, defaults to |
False
|
|
bool
|
Whether to raise errors, defaults to |
True
|
|
int
|
The depth level of the parent namespace, defaults to 2. |
2
|
|
MappingNamespace | None
|
The types namespace, defaults to |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
Returns |
Source code in pydantic/main.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
model_validate
classmethod
¤
model_validate(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, from_attributes: bool | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate a pydantic model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
bool | None
|
Whether to extract data from object attributes. |
None
|
|
Any | None
|
Additional context to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the object could not be validated. |
Returns:
| Type | Description |
|---|---|
Self
|
The validated model instance. |
Source code in pydantic/main.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
model_validate_json
classmethod
¤
model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Usage Documentation
Validate the given JSON data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in pydantic/main.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
model_validate_strings
classmethod
¤
model_validate_strings(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate the given object with string data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object containing string data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Source code in pydantic/main.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
parse_file
classmethod
¤
parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
parse_obj
classmethod
¤
parse_obj(obj: Any) -> Self
Source code in pydantic/main.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 | |
parse_raw
classmethod
¤
parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
schema
classmethod
¤
schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE) -> Dict[str, Any]
Source code in pydantic/main.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 | |
schema_json
classmethod
¤
schema_json(*, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
update_forward_refs
classmethod
¤
update_forward_refs(**localns: Any) -> None
Source code in pydantic/main.py
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
validate
classmethod
¤
validate(value: Any) -> Self
Source code in pydantic/main.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 | |
PredictCmd
¤
PredictCmd(**data: Any)
Bases: CmdBase, WithSource
flowchart TD
bioimageio.core.cli.PredictCmd[PredictCmd]
bioimageio.core.cli.CmdBase[CmdBase]
bioimageio.core.cli.WithSource[WithSource]
bioimageio.core.cli.ArgMixin[ArgMixin]
pydantic.main.BaseModel[BaseModel]
bioimageio.core.cli.CmdBase --> bioimageio.core.cli.PredictCmd
pydantic.main.BaseModel --> bioimageio.core.cli.CmdBase
bioimageio.core.cli.WithSource --> bioimageio.core.cli.PredictCmd
bioimageio.core.cli.ArgMixin --> bioimageio.core.cli.WithSource
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
click bioimageio.core.cli.PredictCmd href "" "bioimageio.core.cli.PredictCmd"
click bioimageio.core.cli.CmdBase href "" "bioimageio.core.cli.CmdBase"
click bioimageio.core.cli.WithSource href "" "bioimageio.core.cli.WithSource"
click bioimageio.core.cli.ArgMixin href "" "bioimageio.core.cli.ArgMixin"
click pydantic.main.BaseModel href "" "pydantic.main.BaseModel"
Run inference on your data with a bioimage.io model.
Raises ValidationError if the input data cannot be
validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Methods:
| Name | Description |
|---|---|
__class_getitem__ |
|
__copy__ |
Returns a shallow copy of the model. |
__deepcopy__ |
Returns a deep copy of the model. |
__delattr__ |
|
__eq__ |
|
__get_pydantic_core_schema__ |
|
__get_pydantic_json_schema__ |
Hook into generating the model's JSON schema. |
__getattr__ |
|
__getstate__ |
|
__init_subclass__ |
This signature is included purely to help type-checkers check arguments to class declaration, which |
__iter__ |
So |
__pydantic_init_subclass__ |
This is intended to behave just like |
__pydantic_on_complete__ |
This is called once the class and its fields are fully initialized and ready to be used. |
__replace__ |
|
__repr__ |
|
__repr_args__ |
|
__setattr__ |
|
__setstate__ |
|
__str__ |
|
cli_cmd |
|
construct |
|
copy |
Returns a copy of the model. |
dict |
|
from_orm |
|
json |
|
model_computed_fields |
A mapping of computed field names to their respective |
model_construct |
Creates a new instance of the |
model_copy |
Usage Documentation |
model_dump |
Usage Documentation |
model_dump_json |
Usage Documentation |
model_fields |
A mapping of field names to their respective |
model_json_schema |
Generates a JSON schema for a model class. |
model_parametrized_name |
Compute the class name for parametrizations of generic classes. |
model_post_init |
Override this method to perform additional initialization after |
model_rebuild |
Try to rebuild the pydantic-core schema for the model. |
model_validate |
Validate a pydantic model instance. |
model_validate_json |
Usage Documentation |
model_validate_strings |
Validate the given object with string data against the Pydantic model. |
parse_file |
|
parse_obj |
|
parse_raw |
|
schema |
|
schema_json |
|
update_forward_refs |
|
validate |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__class_vars__ |
set[str]
|
The names of the class variables defined on the model. |
__fields__ |
dict[str, FieldInfo]
|
|
__fields_set__ |
set[str]
|
|
__pretty__ |
|
|
__private_attributes__ |
Dict[str, ModelPrivateAttr]
|
Metadata about the private attributes of the model. |
__pydantic_complete__ |
bool
|
Whether model building is completed, or if there are still undefined fields. |
__pydantic_computed_fields__ |
Dict[str, ComputedFieldInfo]
|
A dictionary of computed field names and their corresponding |
__pydantic_core_schema__ |
CoreSchema
|
The core schema of the model. |
__pydantic_custom_init__ |
bool
|
Whether the model has a custom |
__pydantic_decorators__ |
_decorators.DecoratorInfos
|
Metadata containing the decorators defined on the model. |
__pydantic_extra__ |
Dict[str, Any] | None
|
A dictionary containing extra values, if |
__pydantic_fields__ |
Dict[str, FieldInfo]
|
A dictionary of field names and their corresponding |
__pydantic_fields_set__ |
set[str]
|
The names of fields explicitly set during instantiation. |
__pydantic_generic_metadata__ |
_generics.PydanticGenericMetadata
|
Metadata for generic models; contains data used for a similar purpose to |
__pydantic_parent_namespace__ |
Dict[str, Any] | None
|
Parent namespace of the model, used for automatic rebuilding of models. |
__pydantic_post_init__ |
None | Literal['model_post_init']
|
The name of the post-init method for the model, if defined. |
__pydantic_private__ |
Dict[str, Any] | None
|
Values of private attributes set on the model instance. |
__pydantic_root_model__ |
bool
|
Whether the model is a |
__pydantic_serializer__ |
SchemaSerializer
|
The |
__pydantic_setattr_handlers__ |
Dict[str, Callable[[BaseModel, str, Any], None]]
|
|
__pydantic_validator__ |
SchemaValidator | PluggableSchemaValidator
|
The |
__repr_name__ |
|
|
__repr_recursion__ |
|
|
__repr_str__ |
|
|
__rich_repr__ |
|
|
__signature__ |
Signature
|
The synthesized |
__slots__ |
|
|
blockwise |
bool
|
process inputs blockwise |
descr |
|
|
descr_id |
str
|
a more user-friendly description id |
example |
bool
|
generate and run an example |
inputs |
NotEmpty[List[Union[str, NotEmpty[List[str]]]]]
|
Model input sample paths (for each input tensor) |
model_config |
ConfigDict
|
Configuration for the model, should be a dictionary conforming to |
model_extra |
dict[str, Any] | None
|
Get extra fields set during validation. |
model_fields_set |
set[str]
|
Returns the set of fields that have been explicitly set on this model instance. |
outputs |
Union[str, NotEmpty[Tuple[str, ...]]]
|
Model output path pattern (per output tensor) |
overwrite |
bool
|
allow overwriting existing output files |
preview |
bool
|
preview which files would be processed |
source |
CliPositionalArg[str]
|
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file |
stats |
Annotated[Path, WithJsonSchema({type: string}), PlainSerializer(lambda p: p.as_posix(), return_type=str)]
|
path to dataset statistics |
weight_format |
WeightFormatArgAny
|
The weight format to use. |
Source code in pydantic/main.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__class_vars__
class-attribute
¤
__class_vars__: set[str]
The names of the class variables defined on the model.
__private_attributes__
class-attribute
¤
__private_attributes__: Dict[str, ModelPrivateAttr]
Metadata about the private attributes of the model.
__pydantic_complete__
class-attribute
¤
__pydantic_complete__: bool = False
Whether model building is completed, or if there are still undefined fields.
__pydantic_computed_fields__
class-attribute
¤
__pydantic_computed_fields__: Dict[str, ComputedFieldInfo]
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
__pydantic_core_schema__
class-attribute
¤
__pydantic_core_schema__: CoreSchema
The core schema of the model.
__pydantic_custom_init__
class-attribute
¤
__pydantic_custom_init__: bool
Whether the model has a custom __init__ method.
__pydantic_decorators__
class-attribute
¤
__pydantic_decorators__: _decorators.DecoratorInfos = _decorators.DecoratorInfos()
Metadata containing the decorators defined on the model.
This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
__pydantic_extra__
pydantic-field
¤
__pydantic_extra__: Dict[str, Any] | None
A dictionary containing extra values, if extra is set to 'allow'.
__pydantic_fields__
class-attribute
¤
__pydantic_fields__: Dict[str, FieldInfo]
A dictionary of field names and their corresponding FieldInfo objects.
This replaces Model.__fields__ from Pydantic V1.
__pydantic_fields_set__
pydantic-field
¤
__pydantic_fields_set__: set[str]
The names of fields explicitly set during instantiation.
__pydantic_generic_metadata__
class-attribute
¤
__pydantic_generic_metadata__: _generics.PydanticGenericMetadata
Metadata for generic models; contains data used for a similar purpose to args, origin, parameters in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__
class-attribute
¤
__pydantic_parent_namespace__: Dict[str, Any] | None = None
Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__
class-attribute
¤
__pydantic_post_init__: None | Literal['model_post_init']
The name of the post-init method for the model, if defined.
__pydantic_private__
pydantic-field
¤
__pydantic_private__: Dict[str, Any] | None
Values of private attributes set on the model instance.
__pydantic_root_model__
class-attribute
¤
__pydantic_root_model__: bool = False
Whether the model is a RootModel.
__pydantic_serializer__
class-attribute
¤
__pydantic_serializer__: SchemaSerializer
The pydantic-core SchemaSerializer used to dump instances of the model.
__pydantic_setattr_handlers__
class-attribute
¤
__pydantic_setattr_handlers__: Dict[str, Callable[[BaseModel, str, Any], None]]
__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__
__pydantic_validator__
class-attribute
¤
__pydantic_validator__: SchemaValidator | PluggableSchemaValidator
The pydantic-core SchemaValidator used to validate instances of the model.
__signature__
class-attribute
¤
__signature__: Signature
The synthesized __init__ [Signature][inspect.Signature] of the model.
__slots__
pydantic-field
¤
__slots__ = ('__dict__', '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__')
descr_id
property
¤
descr_id: str
a more user-friendly description id (replacing legacy ids with their nicknames)
example
class-attribute
instance-attribute
¤
example: bool = False
generate and run an example
- downloads example model inputs
- creates a
{model_id}_examplefolder - writes input arguments to
{model_id}_example/bioimageio-cli.yaml - executes a preview dry-run
- executes prediction with example input
inputs
class-attribute
instance-attribute
¤
inputs: NotEmpty[List[Union[str, NotEmpty[List[str]]]]] = Field(default_factory=lambda: ['{input_id}/001.tif'])
Model input sample paths (for each input tensor)
The input paths are expected to have shape... - (n_samples,) or (n_samples,1) for models expecting a single input tensor - (n_samples,) containing the substring '{input_id}', or - (n_samples, n_model_inputs) to provide each input tensor path explicitly.
All substrings that are replaced by metadata from the model description: - '{model_id}' - '{input_id}'
Example inputs to process sample 'a' and 'b' for a model expecting a 'raw' and a 'mask' input tensor: --inputs="[[\"a_raw.tif\",\"a_mask.tif\"],[\"b_raw.tif\",\"b_mask.tif\"]]" (Note that JSON double quotes need to be escaped.)
Alternatively a bioimageio-cli.yaml (or bioimageio-cli.json) file
may provide the arguments, e.g.:
inputs:
- [a_raw.tif, a_mask.tif]
- [b_raw.tif, b_mask.tif]
.npy and any file extension supported by imageio are supported.
Aavailable formats are listed at
https://imageio.readthedocs.io/en/stable/formats/index.html#all-formats.
Some formats have additional dependencies.
model_config
class-attribute
¤
model_config: ConfigDict = ConfigDict()
Configuration for the model, should be a dictionary conforming to ConfigDict.
model_extra
property
¤
model_extra: dict[str, Any] | None
Get extra fields set during validation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dictionary of extra fields, or |
model_fields_set
property
¤
model_fields_set: set[str]
Returns the set of fields that have been explicitly set on this model instance.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of strings representing the fields that have been set, i.e. that were not filled from defaults. |
outputs
class-attribute
instance-attribute
¤
outputs: Union[str, NotEmpty[Tuple[str, ...]]] = 'outputs_{model_id}/{output_id}/{sample_id}.tif'
Model output path pattern (per output tensor)
All substrings that are replaced: - '{model_id}' (from model description) - '{output_id}' (from model description) - '{sample_id}' (extracted from input paths)
overwrite
class-attribute
instance-attribute
¤
overwrite: bool = False
allow overwriting existing output files
preview
class-attribute
instance-attribute
¤
preview: bool = False
preview which files would be processed and what outputs would be generated.
source
instance-attribute
¤
source: CliPositionalArg[str]
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file or a bioimage.io resource identifier, e.g. 'affable-shark'
stats
class-attribute
instance-attribute
¤
stats: Annotated[Path, WithJsonSchema({type: string}), PlainSerializer(lambda p: p.as_posix(), return_type=str)] = Path('dataset_statistics.json')
path to dataset statistics (will be written if it does not exist, but the model requires statistical dataset measures)
weight_format
class-attribute
instance-attribute
¤
weight_format: WeightFormatArgAny = Field('any', alias='weight-format', validation_alias=WEIGHT_FORMAT_ALIASES)
The weight format to use.
__class_getitem__
¤
__class_getitem__(typevar_values: type[Any] | tuple[type[Any], ...]) -> type[BaseModel] | _forward_ref.PydanticRecursiveRef
Source code in pydantic/main.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
__copy__
¤
__copy__() -> Self
Returns a shallow copy of the model.
Source code in pydantic/main.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
__deepcopy__
¤
__deepcopy__(memo: dict[int, Any] | None = None) -> Self
Returns a deep copy of the model.
Source code in pydantic/main.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
__delattr__
¤
__delattr__(item: str) -> Any
Source code in pydantic/main.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
__eq__
¤
__eq__(other: Any) -> bool
Source code in pydantic/main.py
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
__get_pydantic_core_schema__
classmethod
¤
__get_pydantic_core_schema__(source: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema
Source code in pydantic/main.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
__get_pydantic_json_schema__
classmethod
¤
__get_pydantic_json_schema__(core_schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue
Hook into generating the model's JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CoreSchema
|
A |
required |
|
GetJsonSchemaHandler
|
Call into Pydantic's internal JSON schema generation.
This will raise a |
required |
Returns:
| Type | Description |
|---|---|
JsonSchemaValue
|
A JSON schema, as a Python object. |
Source code in pydantic/main.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
__getattr__
¤
__getattr__(item: str) -> Any
Source code in pydantic/main.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
__getstate__
¤
__getstate__() -> dict[Any, Any]
Source code in pydantic/main.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
__init_subclass__
¤
__init_subclass__(**kwargs: Unpack[ConfigDict])
This signature is included purely to help type-checkers check arguments to class declaration, which provides a way to conveniently set model_config key/value pairs.
from pydantic import BaseModel
class MyModel(BaseModel, extra='allow'): ...
However, this may be deceiving, since the actual calls to __init_subclass__ will not receive any
of the config arguments, and will only receive any keyword arguments passed during class initialization
that are not expected keys in ConfigDict. (This is due to the way ModelMetaclass.__new__ works.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Unpack[ConfigDict]
|
Keyword arguments passed to the class definition, which set model_config |
{}
|
Note
You may want to override __pydantic_init_subclass__ instead, which behaves similarly but is called
after the class is fully initialized.
Source code in pydantic/main.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
__iter__
¤
__iter__() -> TupleGenerator
So dict(model) works.
Source code in pydantic/main.py
1229 1230 1231 1232 1233 1234 | |
__pydantic_init_subclass__
classmethod
¤
__pydantic_init_subclass__(**kwargs: Any) -> None
This is intended to behave just like __init_subclass__, but is called by ModelMetaclass
only after basic class initialization is complete. In particular, attributes like model_fields will
be present when this is called, but forward annotations are not guaranteed to be resolved yet,
meaning that creating an instance of the class may fail.
This is necessary because __init_subclass__ will always be called by type.__new__,
and it would require a prohibitively large refactor to the ModelMetaclass to ensure that
type.__new__ was called in such a manner that the class would already be sufficiently initialized.
This will receive the same kwargs that would be passed to the standard __init_subclass__, namely,
any kwargs passed to the class definition that aren't used internally by Pydantic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Any keyword arguments passed to the class definition that aren't used internally by Pydantic. |
{}
|
Note
You may want to override __pydantic_on_complete__()
instead, which is called once the class and its fields are fully initialized and ready for validation.
Source code in pydantic/main.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
__pydantic_on_complete__
classmethod
¤
__pydantic_on_complete__() -> None
This is called once the class and its fields are fully initialized and ready to be used.
This typically happens when the class is created (just before
__pydantic_init_subclass__() is called on the superclass),
except when forward annotations are used that could not immediately be resolved.
In that case, it will be called later, when the model is rebuilt automatically or explicitly using
model_rebuild().
Source code in pydantic/main.py
877 878 879 880 881 882 883 884 885 886 | |
__replace__
¤
__replace__(**changes: Any) -> Self
Source code in pydantic/main.py
1125 1126 | |
__repr__
¤
__repr__() -> str
Source code in pydantic/main.py
1236 1237 | |
__repr_args__
¤
__repr_args__() -> _repr.ReprArgs
Source code in pydantic/main.py
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
__setattr__
¤
__setattr__(name: str, value: Any) -> None
Source code in pydantic/main.py
1028 1029 1030 1031 1032 1033 1034 | |
__setstate__
¤
__setstate__(state: dict[Any, Any]) -> None
Source code in pydantic/main.py
1139 1140 1141 1142 1143 | |
__str__
¤
__str__() -> str
Source code in pydantic/main.py
1274 1275 | |
cli_cmd
¤
cli_cmd()
Source code in src/bioimageio/core/cli.py
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 | |
construct
classmethod
¤
construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Source code in pydantic/main.py
1477 1478 1479 1480 1481 1482 1483 1484 1485 | |
copy
¤
copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) -> Self
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in pydantic/main.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | |
dict
¤
dict(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> Dict[str, Any]
Source code in pydantic/main.py
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | |
from_orm
classmethod
¤
from_orm(obj: Any) -> Self
Source code in pydantic/main.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
json
¤
json(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
model_computed_fields
classmethod
¤
model_computed_fields() -> dict[str, ComputedFieldInfo]
A mapping of computed field names to their respective ComputedFieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
273 274 275 276 277 278 279 280 281 282 | |
model_construct
classmethod
¤
model_construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Note
model_construct() generally respects the model_config.extra setting on the provided model.
That is, if model_config.extra == 'allow', then all extra passed values are added to the model instance's __dict__
and __pydantic_extra__ fields. If model_config.extra == 'ignore' (the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct(), having model_config.extra == 'forbid' does not result in
an error if extra values are passed, but they will be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
set[str] | None
|
A set of field names that were originally explicitly set during instantiation. If provided,
this is directly used for the |
None
|
|
Any
|
Trusted or pre-validated data dictionary. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
A new instance of the |
Source code in pydantic/main.py
303 304 305 306 307 308 309 310 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
model_copy
¤
Usage Documentation
Returns a copy of the model.
Note
The underlying instance's [__dict__][object.__dict__] attribute is copied. This
might have unexpected side effects if you store anything in it, on top of the model
fields (e.g. the value of [cached properties][functools.cached_property]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, Any] | None
|
Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data. |
None
|
|
bool
|
Set to |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
New model instance. |
Source code in pydantic/main.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
model_dump
¤
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> dict[str, Any]
Usage Documentation
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Literal['json', 'python'] | str
|
The mode in which |
'python'
|
|
IncEx | None
|
A set of fields to include in the output. |
None
|
|
IncEx | None
|
A set of fields to exclude from the output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to use the field's alias in the dictionary key if defined. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representation of the model. |
Source code in pydantic/main.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
model_dump_json
¤
model_dump_json(*, indent: int | None = None, ensure_ascii: bool = False, include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> str
Usage Documentation
Generates a JSON representation of the model using Pydantic's to_json method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
|
bool
|
If |
False
|
|
IncEx | None
|
Field(s) to include in the JSON output. |
None
|
|
IncEx | None
|
Field(s) to exclude from the JSON output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to serialize using field aliases. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representation of the model. |
Source code in pydantic/main.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
model_fields
classmethod
¤
A mapping of field names to their respective FieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
262 263 264 265 266 267 268 269 270 271 | |
model_json_schema
classmethod
¤
model_json_schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema, mode: JsonSchemaMode = 'validation', *, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of') -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to use attribute aliases or not. |
True
|
|
str
|
The reference template. |
DEFAULT_REF_TEMPLATE
|
|
Literal['any_of', 'primitive_type_array']
|
The format to use when combining schemas from unions together. Can be one of:
|
'any_of'
|
|
type[GenerateJsonSchema]
|
To override the logic used to generate the JSON schema, as a subclass of
|
GenerateJsonSchema
|
|
JsonSchemaMode
|
The mode in which to generate the schema. |
'validation'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON schema for the given model class. |
Source code in pydantic/main.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
model_parametrized_name
classmethod
¤
model_parametrized_name(params: tuple[type[Any], ...]) -> str
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
| Type | Description |
|---|---|
str
|
String representing the new class where |
Raises:
| Type | Description |
|---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in pydantic/main.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
model_post_init
¤
model_post_init(context: Any) -> None
Override this method to perform additional initialization after __init__ and model_construct.
This is useful if you want to do some validation that requires the entire model to be initialized.
Source code in pydantic/main.py
612 613 614 615 | |
model_rebuild
classmethod
¤
model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to force the rebuilding of the model schema, defaults to |
False
|
|
bool
|
Whether to raise errors, defaults to |
True
|
|
int
|
The depth level of the parent namespace, defaults to 2. |
2
|
|
MappingNamespace | None
|
The types namespace, defaults to |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
Returns |
Source code in pydantic/main.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
model_validate
classmethod
¤
model_validate(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, from_attributes: bool | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate a pydantic model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
bool | None
|
Whether to extract data from object attributes. |
None
|
|
Any | None
|
Additional context to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the object could not be validated. |
Returns:
| Type | Description |
|---|---|
Self
|
The validated model instance. |
Source code in pydantic/main.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
model_validate_json
classmethod
¤
model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Usage Documentation
Validate the given JSON data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in pydantic/main.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
model_validate_strings
classmethod
¤
model_validate_strings(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate the given object with string data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object containing string data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Source code in pydantic/main.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
parse_file
classmethod
¤
parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
parse_obj
classmethod
¤
parse_obj(obj: Any) -> Self
Source code in pydantic/main.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 | |
parse_raw
classmethod
¤
parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
schema
classmethod
¤
schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE) -> Dict[str, Any]
Source code in pydantic/main.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 | |
schema_json
classmethod
¤
schema_json(*, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
update_forward_refs
classmethod
¤
update_forward_refs(**localns: Any) -> None
Source code in pydantic/main.py
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
validate
classmethod
¤
validate(value: Any) -> Self
Source code in pydantic/main.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 | |
TestCmd
¤
TestCmd(**data: Any)
Bases: CmdBase, WithSource, WithSummaryLogging
flowchart TD
bioimageio.core.cli.TestCmd[TestCmd]
bioimageio.core.cli.CmdBase[CmdBase]
bioimageio.core.cli.WithSource[WithSource]
bioimageio.core.cli.WithSummaryLogging[WithSummaryLogging]
bioimageio.core.cli.ArgMixin[ArgMixin]
pydantic.main.BaseModel[BaseModel]
bioimageio.core.cli.CmdBase --> bioimageio.core.cli.TestCmd
pydantic.main.BaseModel --> bioimageio.core.cli.CmdBase
bioimageio.core.cli.WithSource --> bioimageio.core.cli.TestCmd
bioimageio.core.cli.ArgMixin --> bioimageio.core.cli.WithSource
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
bioimageio.core.cli.WithSummaryLogging --> bioimageio.core.cli.TestCmd
bioimageio.core.cli.ArgMixin --> bioimageio.core.cli.WithSummaryLogging
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
click bioimageio.core.cli.TestCmd href "" "bioimageio.core.cli.TestCmd"
click bioimageio.core.cli.CmdBase href "" "bioimageio.core.cli.CmdBase"
click bioimageio.core.cli.WithSource href "" "bioimageio.core.cli.WithSource"
click bioimageio.core.cli.WithSummaryLogging href "" "bioimageio.core.cli.WithSummaryLogging"
click bioimageio.core.cli.ArgMixin href "" "bioimageio.core.cli.ArgMixin"
click pydantic.main.BaseModel href "" "pydantic.main.BaseModel"
Test a bioimageio resource (beyond meta data formatting).
Raises ValidationError if the input data cannot be
validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Methods:
| Name | Description |
|---|---|
__class_getitem__ |
|
__copy__ |
Returns a shallow copy of the model. |
__deepcopy__ |
Returns a deep copy of the model. |
__delattr__ |
|
__eq__ |
|
__get_pydantic_core_schema__ |
|
__get_pydantic_json_schema__ |
Hook into generating the model's JSON schema. |
__getattr__ |
|
__getstate__ |
|
__init_subclass__ |
This signature is included purely to help type-checkers check arguments to class declaration, which |
__iter__ |
So |
__pydantic_init_subclass__ |
This is intended to behave just like |
__pydantic_on_complete__ |
This is called once the class and its fields are fully initialized and ready to be used. |
__replace__ |
|
__repr__ |
|
__repr_args__ |
|
__setattr__ |
|
__setstate__ |
|
__str__ |
|
cli_cmd |
|
construct |
|
copy |
Returns a copy of the model. |
dict |
|
from_orm |
|
json |
|
log |
|
model_computed_fields |
A mapping of computed field names to their respective |
model_construct |
Creates a new instance of the |
model_copy |
Usage Documentation |
model_dump |
Usage Documentation |
model_dump_json |
Usage Documentation |
model_fields |
A mapping of field names to their respective |
model_json_schema |
Generates a JSON schema for a model class. |
model_parametrized_name |
Compute the class name for parametrizations of generic classes. |
model_post_init |
Override this method to perform additional initialization after |
model_rebuild |
Try to rebuild the pydantic-core schema for the model. |
model_validate |
Validate a pydantic model instance. |
model_validate_json |
Usage Documentation |
model_validate_strings |
Validate the given object with string data against the Pydantic model. |
parse_file |
|
parse_obj |
|
parse_raw |
|
schema |
|
schema_json |
|
update_forward_refs |
|
validate |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__class_vars__ |
set[str]
|
The names of the class variables defined on the model. |
__fields__ |
dict[str, FieldInfo]
|
|
__fields_set__ |
set[str]
|
|
__pretty__ |
|
|
__private_attributes__ |
Dict[str, ModelPrivateAttr]
|
Metadata about the private attributes of the model. |
__pydantic_complete__ |
bool
|
Whether model building is completed, or if there are still undefined fields. |
__pydantic_computed_fields__ |
Dict[str, ComputedFieldInfo]
|
A dictionary of computed field names and their corresponding |
__pydantic_core_schema__ |
CoreSchema
|
The core schema of the model. |
__pydantic_custom_init__ |
bool
|
Whether the model has a custom |
__pydantic_decorators__ |
_decorators.DecoratorInfos
|
Metadata containing the decorators defined on the model. |
__pydantic_extra__ |
Dict[str, Any] | None
|
A dictionary containing extra values, if |
__pydantic_fields__ |
Dict[str, FieldInfo]
|
A dictionary of field names and their corresponding |
__pydantic_fields_set__ |
set[str]
|
The names of fields explicitly set during instantiation. |
__pydantic_generic_metadata__ |
_generics.PydanticGenericMetadata
|
Metadata for generic models; contains data used for a similar purpose to |
__pydantic_parent_namespace__ |
Dict[str, Any] | None
|
Parent namespace of the model, used for automatic rebuilding of models. |
__pydantic_post_init__ |
None | Literal['model_post_init']
|
The name of the post-init method for the model, if defined. |
__pydantic_private__ |
Dict[str, Any] | None
|
Values of private attributes set on the model instance. |
__pydantic_root_model__ |
bool
|
Whether the model is a |
__pydantic_serializer__ |
SchemaSerializer
|
The |
__pydantic_setattr_handlers__ |
Dict[str, Callable[[BaseModel, str, Any], None]]
|
|
__pydantic_validator__ |
SchemaValidator | PluggableSchemaValidator
|
The |
__repr_name__ |
|
|
__repr_recursion__ |
|
|
__repr_str__ |
|
|
__rich_repr__ |
|
|
__signature__ |
Signature
|
The synthesized |
__slots__ |
|
|
descr |
|
|
descr_id |
str
|
a more user-friendly description id |
determinism |
Literal['seed_only', 'full']
|
Modes to improve reproducibility of test outputs. |
devices |
Optional[List[str]]
|
Device(s) to use for testing |
format_version |
Union[FormatVersionPlaceholder, str]
|
The format version to use for testing. |
model_config |
ConfigDict
|
Configuration for the model, should be a dictionary conforming to |
model_extra |
dict[str, Any] | None
|
Get extra fields set during validation. |
model_fields_set |
set[str]
|
Returns the set of fields that have been explicitly set on this model instance. |
runtime_env |
Union[Literal['currently-active', 'as-described'], Path]
|
The python environment to run the tests in |
source |
CliPositionalArg[str]
|
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file |
stop_early |
bool
|
Do not run further subtests after a failed one. |
summary |
List[Union[Literal['display'], Path]]
|
Display the validation summary or save it as JSON, Markdown or HTML. |
weight_format |
WeightFormatArgAll
|
The weight format to limit testing to. |
working_dir |
Optional[Path]
|
(for debugging) Directory to save any temporary files. |
Source code in pydantic/main.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__class_vars__
class-attribute
¤
__class_vars__: set[str]
The names of the class variables defined on the model.
__private_attributes__
class-attribute
¤
__private_attributes__: Dict[str, ModelPrivateAttr]
Metadata about the private attributes of the model.
__pydantic_complete__
class-attribute
¤
__pydantic_complete__: bool = False
Whether model building is completed, or if there are still undefined fields.
__pydantic_computed_fields__
class-attribute
¤
__pydantic_computed_fields__: Dict[str, ComputedFieldInfo]
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
__pydantic_core_schema__
class-attribute
¤
__pydantic_core_schema__: CoreSchema
The core schema of the model.
__pydantic_custom_init__
class-attribute
¤
__pydantic_custom_init__: bool
Whether the model has a custom __init__ method.
__pydantic_decorators__
class-attribute
¤
__pydantic_decorators__: _decorators.DecoratorInfos = _decorators.DecoratorInfos()
Metadata containing the decorators defined on the model.
This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
__pydantic_extra__
pydantic-field
¤
__pydantic_extra__: Dict[str, Any] | None
A dictionary containing extra values, if extra is set to 'allow'.
__pydantic_fields__
class-attribute
¤
__pydantic_fields__: Dict[str, FieldInfo]
A dictionary of field names and their corresponding FieldInfo objects.
This replaces Model.__fields__ from Pydantic V1.
__pydantic_fields_set__
pydantic-field
¤
__pydantic_fields_set__: set[str]
The names of fields explicitly set during instantiation.
__pydantic_generic_metadata__
class-attribute
¤
__pydantic_generic_metadata__: _generics.PydanticGenericMetadata
Metadata for generic models; contains data used for a similar purpose to args, origin, parameters in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__
class-attribute
¤
__pydantic_parent_namespace__: Dict[str, Any] | None = None
Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__
class-attribute
¤
__pydantic_post_init__: None | Literal['model_post_init']
The name of the post-init method for the model, if defined.
__pydantic_private__
pydantic-field
¤
__pydantic_private__: Dict[str, Any] | None
Values of private attributes set on the model instance.
__pydantic_root_model__
class-attribute
¤
__pydantic_root_model__: bool = False
Whether the model is a RootModel.
__pydantic_serializer__
class-attribute
¤
__pydantic_serializer__: SchemaSerializer
The pydantic-core SchemaSerializer used to dump instances of the model.
__pydantic_setattr_handlers__
class-attribute
¤
__pydantic_setattr_handlers__: Dict[str, Callable[[BaseModel, str, Any], None]]
__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__
__pydantic_validator__
class-attribute
¤
__pydantic_validator__: SchemaValidator | PluggableSchemaValidator
The pydantic-core SchemaValidator used to validate instances of the model.
__signature__
class-attribute
¤
__signature__: Signature
The synthesized __init__ [Signature][inspect.Signature] of the model.
__slots__
pydantic-field
¤
__slots__ = ('__dict__', '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__')
descr_id
property
¤
descr_id: str
a more user-friendly description id (replacing legacy ids with their nicknames)
determinism
class-attribute
instance-attribute
¤
determinism: Literal['seed_only', 'full'] = 'seed_only'
Modes to improve reproducibility of test outputs.
devices
class-attribute
instance-attribute
¤
devices: Optional[List[str]] = None
Device(s) to use for testing
format_version
class-attribute
instance-attribute
¤
format_version: Union[FormatVersionPlaceholder, str] = Field('discover', alias='format-version')
The format version to use for testing. - 'latest': Use the latest implemented format version for the given resource type (may trigger auto updating) - 'discover': Use the format version as described in the resource description - '0.4', '0.5', ...: Use the specified format version (may trigger auto updating)
model_config
class-attribute
¤
model_config: ConfigDict = ConfigDict()
Configuration for the model, should be a dictionary conforming to ConfigDict.
model_extra
property
¤
model_extra: dict[str, Any] | None
Get extra fields set during validation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dictionary of extra fields, or |
model_fields_set
property
¤
model_fields_set: set[str]
Returns the set of fields that have been explicitly set on this model instance.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of strings representing the fields that have been set, i.e. that were not filled from defaults. |
runtime_env
class-attribute
instance-attribute
¤
runtime_env: Union[Literal['currently-active', 'as-described'], Path] = Field('currently-active', alias='runtime-env')
The python environment to run the tests in
- "currently-active": use active Python interpreter
- "as-described": generate a conda environment YAML file based on the model
weights description.
- A path to a conda environment YAML.
Note: The bioimageio.core dependency will be added automatically if not present.
source
instance-attribute
¤
source: CliPositionalArg[str]
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file or a bioimage.io resource identifier, e.g. 'affable-shark'
stop_early
class-attribute
instance-attribute
¤
stop_early: bool = Field(False, alias='stop-early', validation_alias=AliasChoices('stop-early', 'x'))
Do not run further subtests after a failed one.
summary
class-attribute
instance-attribute
¤
summary: List[Union[Literal['display'], Path]] = Field(default_factory=lambda: ['display'], examples=[Path('summary.md'), Path('bioimageio_summaries/'), ['display', Path('summary.md')]])
Display the validation summary or save it as JSON, Markdown or HTML.
The format is chosen based on the suffix: .json, .md, .html.
If a folder is given (path w/o suffix) the summary is saved in all formats.
Choose/add "display" to render the validation summary to the terminal.
weight_format
class-attribute
instance-attribute
¤
weight_format: WeightFormatArgAll = Field('all', alias='weight-format', validation_alias=WEIGHT_FORMAT_ALIASES)
The weight format to limit testing to.
(only relevant for model resources)
working_dir
class-attribute
instance-attribute
¤
working_dir: Optional[Path] = Field(None, alias='working-dir')
(for debugging) Directory to save any temporary files.
__class_getitem__
¤
__class_getitem__(typevar_values: type[Any] | tuple[type[Any], ...]) -> type[BaseModel] | _forward_ref.PydanticRecursiveRef
Source code in pydantic/main.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
__copy__
¤
__copy__() -> Self
Returns a shallow copy of the model.
Source code in pydantic/main.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
__deepcopy__
¤
__deepcopy__(memo: dict[int, Any] | None = None) -> Self
Returns a deep copy of the model.
Source code in pydantic/main.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
__delattr__
¤
__delattr__(item: str) -> Any
Source code in pydantic/main.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
__eq__
¤
__eq__(other: Any) -> bool
Source code in pydantic/main.py
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
__get_pydantic_core_schema__
classmethod
¤
__get_pydantic_core_schema__(source: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema
Source code in pydantic/main.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
__get_pydantic_json_schema__
classmethod
¤
__get_pydantic_json_schema__(core_schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue
Hook into generating the model's JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CoreSchema
|
A |
required |
|
GetJsonSchemaHandler
|
Call into Pydantic's internal JSON schema generation.
This will raise a |
required |
Returns:
| Type | Description |
|---|---|
JsonSchemaValue
|
A JSON schema, as a Python object. |
Source code in pydantic/main.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
__getattr__
¤
__getattr__(item: str) -> Any
Source code in pydantic/main.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
__getstate__
¤
__getstate__() -> dict[Any, Any]
Source code in pydantic/main.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
__init_subclass__
¤
__init_subclass__(**kwargs: Unpack[ConfigDict])
This signature is included purely to help type-checkers check arguments to class declaration, which provides a way to conveniently set model_config key/value pairs.
from pydantic import BaseModel
class MyModel(BaseModel, extra='allow'): ...
However, this may be deceiving, since the actual calls to __init_subclass__ will not receive any
of the config arguments, and will only receive any keyword arguments passed during class initialization
that are not expected keys in ConfigDict. (This is due to the way ModelMetaclass.__new__ works.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Unpack[ConfigDict]
|
Keyword arguments passed to the class definition, which set model_config |
{}
|
Note
You may want to override __pydantic_init_subclass__ instead, which behaves similarly but is called
after the class is fully initialized.
Source code in pydantic/main.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
__iter__
¤
__iter__() -> TupleGenerator
So dict(model) works.
Source code in pydantic/main.py
1229 1230 1231 1232 1233 1234 | |
__pydantic_init_subclass__
classmethod
¤
__pydantic_init_subclass__(**kwargs: Any) -> None
This is intended to behave just like __init_subclass__, but is called by ModelMetaclass
only after basic class initialization is complete. In particular, attributes like model_fields will
be present when this is called, but forward annotations are not guaranteed to be resolved yet,
meaning that creating an instance of the class may fail.
This is necessary because __init_subclass__ will always be called by type.__new__,
and it would require a prohibitively large refactor to the ModelMetaclass to ensure that
type.__new__ was called in such a manner that the class would already be sufficiently initialized.
This will receive the same kwargs that would be passed to the standard __init_subclass__, namely,
any kwargs passed to the class definition that aren't used internally by Pydantic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Any keyword arguments passed to the class definition that aren't used internally by Pydantic. |
{}
|
Note
You may want to override __pydantic_on_complete__()
instead, which is called once the class and its fields are fully initialized and ready for validation.
Source code in pydantic/main.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
__pydantic_on_complete__
classmethod
¤
__pydantic_on_complete__() -> None
This is called once the class and its fields are fully initialized and ready to be used.
This typically happens when the class is created (just before
__pydantic_init_subclass__() is called on the superclass),
except when forward annotations are used that could not immediately be resolved.
In that case, it will be called later, when the model is rebuilt automatically or explicitly using
model_rebuild().
Source code in pydantic/main.py
877 878 879 880 881 882 883 884 885 886 | |
__replace__
¤
__replace__(**changes: Any) -> Self
Source code in pydantic/main.py
1125 1126 | |
__repr__
¤
__repr__() -> str
Source code in pydantic/main.py
1236 1237 | |
__repr_args__
¤
__repr_args__() -> _repr.ReprArgs
Source code in pydantic/main.py
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
__setattr__
¤
__setattr__(name: str, value: Any) -> None
Source code in pydantic/main.py
1028 1029 1030 1031 1032 1033 1034 | |
__setstate__
¤
__setstate__(state: dict[Any, Any]) -> None
Source code in pydantic/main.py
1139 1140 1141 1142 1143 | |
__str__
¤
__str__() -> str
Source code in pydantic/main.py
1274 1275 | |
cli_cmd
¤
cli_cmd()
Source code in src/bioimageio/core/cli.py
232 233 234 235 236 237 238 239 240 241 242 243 244 | |
construct
classmethod
¤
construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Source code in pydantic/main.py
1477 1478 1479 1480 1481 1482 1483 1484 1485 | |
copy
¤
copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) -> Self
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in pydantic/main.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | |
dict
¤
dict(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> Dict[str, Any]
Source code in pydantic/main.py
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | |
from_orm
classmethod
¤
from_orm(obj: Any) -> Self
Source code in pydantic/main.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
json
¤
json(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
log
¤
log(descr: Union[ResourceDescr, InvalidDescr])
Source code in src/bioimageio/core/cli.py
131 132 | |
model_computed_fields
classmethod
¤
model_computed_fields() -> dict[str, ComputedFieldInfo]
A mapping of computed field names to their respective ComputedFieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
273 274 275 276 277 278 279 280 281 282 | |
model_construct
classmethod
¤
model_construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Note
model_construct() generally respects the model_config.extra setting on the provided model.
That is, if model_config.extra == 'allow', then all extra passed values are added to the model instance's __dict__
and __pydantic_extra__ fields. If model_config.extra == 'ignore' (the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct(), having model_config.extra == 'forbid' does not result in
an error if extra values are passed, but they will be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
set[str] | None
|
A set of field names that were originally explicitly set during instantiation. If provided,
this is directly used for the |
None
|
|
Any
|
Trusted or pre-validated data dictionary. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
A new instance of the |
Source code in pydantic/main.py
303 304 305 306 307 308 309 310 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
model_copy
¤
Usage Documentation
Returns a copy of the model.
Note
The underlying instance's [__dict__][object.__dict__] attribute is copied. This
might have unexpected side effects if you store anything in it, on top of the model
fields (e.g. the value of [cached properties][functools.cached_property]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, Any] | None
|
Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data. |
None
|
|
bool
|
Set to |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
New model instance. |
Source code in pydantic/main.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
model_dump
¤
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> dict[str, Any]
Usage Documentation
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Literal['json', 'python'] | str
|
The mode in which |
'python'
|
|
IncEx | None
|
A set of fields to include in the output. |
None
|
|
IncEx | None
|
A set of fields to exclude from the output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to use the field's alias in the dictionary key if defined. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representation of the model. |
Source code in pydantic/main.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
model_dump_json
¤
model_dump_json(*, indent: int | None = None, ensure_ascii: bool = False, include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> str
Usage Documentation
Generates a JSON representation of the model using Pydantic's to_json method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
|
bool
|
If |
False
|
|
IncEx | None
|
Field(s) to include in the JSON output. |
None
|
|
IncEx | None
|
Field(s) to exclude from the JSON output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to serialize using field aliases. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representation of the model. |
Source code in pydantic/main.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
model_fields
classmethod
¤
A mapping of field names to their respective FieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
262 263 264 265 266 267 268 269 270 271 | |
model_json_schema
classmethod
¤
model_json_schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema, mode: JsonSchemaMode = 'validation', *, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of') -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to use attribute aliases or not. |
True
|
|
str
|
The reference template. |
DEFAULT_REF_TEMPLATE
|
|
Literal['any_of', 'primitive_type_array']
|
The format to use when combining schemas from unions together. Can be one of:
|
'any_of'
|
|
type[GenerateJsonSchema]
|
To override the logic used to generate the JSON schema, as a subclass of
|
GenerateJsonSchema
|
|
JsonSchemaMode
|
The mode in which to generate the schema. |
'validation'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON schema for the given model class. |
Source code in pydantic/main.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
model_parametrized_name
classmethod
¤
model_parametrized_name(params: tuple[type[Any], ...]) -> str
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
| Type | Description |
|---|---|
str
|
String representing the new class where |
Raises:
| Type | Description |
|---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in pydantic/main.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
model_post_init
¤
model_post_init(context: Any) -> None
Override this method to perform additional initialization after __init__ and model_construct.
This is useful if you want to do some validation that requires the entire model to be initialized.
Source code in pydantic/main.py
612 613 614 615 | |
model_rebuild
classmethod
¤
model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to force the rebuilding of the model schema, defaults to |
False
|
|
bool
|
Whether to raise errors, defaults to |
True
|
|
int
|
The depth level of the parent namespace, defaults to 2. |
2
|
|
MappingNamespace | None
|
The types namespace, defaults to |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
Returns |
Source code in pydantic/main.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
model_validate
classmethod
¤
model_validate(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, from_attributes: bool | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate a pydantic model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
bool | None
|
Whether to extract data from object attributes. |
None
|
|
Any | None
|
Additional context to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the object could not be validated. |
Returns:
| Type | Description |
|---|---|
Self
|
The validated model instance. |
Source code in pydantic/main.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
model_validate_json
classmethod
¤
model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Usage Documentation
Validate the given JSON data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in pydantic/main.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
model_validate_strings
classmethod
¤
model_validate_strings(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate the given object with string data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object containing string data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Source code in pydantic/main.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
parse_file
classmethod
¤
parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
parse_obj
classmethod
¤
parse_obj(obj: Any) -> Self
Source code in pydantic/main.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 | |
parse_raw
classmethod
¤
parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
schema
classmethod
¤
schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE) -> Dict[str, Any]
Source code in pydantic/main.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 | |
schema_json
classmethod
¤
schema_json(*, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
update_forward_refs
classmethod
¤
update_forward_refs(**localns: Any) -> None
Source code in pydantic/main.py
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
validate
classmethod
¤
validate(value: Any) -> Self
Source code in pydantic/main.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 | |
UpdateCmdBase
¤
UpdateCmdBase(**data: Any)
Bases: CmdBase, WithSource, ABC
flowchart TD
bioimageio.core.cli.UpdateCmdBase[UpdateCmdBase]
bioimageio.core.cli.CmdBase[CmdBase]
bioimageio.core.cli.WithSource[WithSource]
bioimageio.core.cli.ArgMixin[ArgMixin]
pydantic.main.BaseModel[BaseModel]
bioimageio.core.cli.CmdBase --> bioimageio.core.cli.UpdateCmdBase
pydantic.main.BaseModel --> bioimageio.core.cli.CmdBase
bioimageio.core.cli.WithSource --> bioimageio.core.cli.UpdateCmdBase
bioimageio.core.cli.ArgMixin --> bioimageio.core.cli.WithSource
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
click bioimageio.core.cli.UpdateCmdBase href "" "bioimageio.core.cli.UpdateCmdBase"
click bioimageio.core.cli.CmdBase href "" "bioimageio.core.cli.CmdBase"
click bioimageio.core.cli.WithSource href "" "bioimageio.core.cli.WithSource"
click bioimageio.core.cli.ArgMixin href "" "bioimageio.core.cli.ArgMixin"
click pydantic.main.BaseModel href "" "pydantic.main.BaseModel"
Raises ValidationError if the input data cannot be
validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
-
API Reference
cli
Methods:
| Name | Description |
|---|---|
__class_getitem__ |
|
__copy__ |
Returns a shallow copy of the model. |
__deepcopy__ |
Returns a deep copy of the model. |
__delattr__ |
|
__eq__ |
|
__get_pydantic_core_schema__ |
|
__get_pydantic_json_schema__ |
Hook into generating the model's JSON schema. |
__getattr__ |
|
__getstate__ |
|
__init_subclass__ |
This signature is included purely to help type-checkers check arguments to class declaration, which |
__iter__ |
So |
__pydantic_init_subclass__ |
This is intended to behave just like |
__pydantic_on_complete__ |
This is called once the class and its fields are fully initialized and ready to be used. |
__replace__ |
|
__repr__ |
|
__repr_args__ |
|
__setattr__ |
|
__setstate__ |
|
__str__ |
|
cli_cmd |
|
construct |
|
copy |
Returns a copy of the model. |
dict |
|
from_orm |
|
json |
|
model_computed_fields |
A mapping of computed field names to their respective |
model_construct |
Creates a new instance of the |
model_copy |
Usage Documentation |
model_dump |
Usage Documentation |
model_dump_json |
Usage Documentation |
model_fields |
A mapping of field names to their respective |
model_json_schema |
Generates a JSON schema for a model class. |
model_parametrized_name |
Compute the class name for parametrizations of generic classes. |
model_post_init |
Override this method to perform additional initialization after |
model_rebuild |
Try to rebuild the pydantic-core schema for the model. |
model_validate |
Validate a pydantic model instance. |
model_validate_json |
Usage Documentation |
model_validate_strings |
Validate the given object with string data against the Pydantic model. |
parse_file |
|
parse_obj |
|
parse_raw |
|
schema |
|
schema_json |
|
update_forward_refs |
|
validate |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__class_vars__ |
set[str]
|
The names of the class variables defined on the model. |
__fields__ |
dict[str, FieldInfo]
|
|
__fields_set__ |
set[str]
|
|
__pretty__ |
|
|
__private_attributes__ |
Dict[str, ModelPrivateAttr]
|
Metadata about the private attributes of the model. |
__pydantic_complete__ |
bool
|
Whether model building is completed, or if there are still undefined fields. |
__pydantic_computed_fields__ |
Dict[str, ComputedFieldInfo]
|
A dictionary of computed field names and their corresponding |
__pydantic_core_schema__ |
CoreSchema
|
The core schema of the model. |
__pydantic_custom_init__ |
bool
|
Whether the model has a custom |
__pydantic_decorators__ |
_decorators.DecoratorInfos
|
Metadata containing the decorators defined on the model. |
__pydantic_extra__ |
Dict[str, Any] | None
|
A dictionary containing extra values, if |
__pydantic_fields__ |
Dict[str, FieldInfo]
|
A dictionary of field names and their corresponding |
__pydantic_fields_set__ |
set[str]
|
The names of fields explicitly set during instantiation. |
__pydantic_generic_metadata__ |
_generics.PydanticGenericMetadata
|
Metadata for generic models; contains data used for a similar purpose to |
__pydantic_parent_namespace__ |
Dict[str, Any] | None
|
Parent namespace of the model, used for automatic rebuilding of models. |
__pydantic_post_init__ |
None | Literal['model_post_init']
|
The name of the post-init method for the model, if defined. |
__pydantic_private__ |
Dict[str, Any] | None
|
Values of private attributes set on the model instance. |
__pydantic_root_model__ |
bool
|
Whether the model is a |
__pydantic_serializer__ |
SchemaSerializer
|
The |
__pydantic_setattr_handlers__ |
Dict[str, Callable[[BaseModel, str, Any], None]]
|
|
__pydantic_validator__ |
SchemaValidator | PluggableSchemaValidator
|
The |
__repr_name__ |
|
|
__repr_recursion__ |
|
|
__repr_str__ |
|
|
__rich_repr__ |
|
|
__signature__ |
Signature
|
The synthesized |
__slots__ |
|
|
descr |
|
|
descr_id |
str
|
a more user-friendly description id |
diff |
Union[bool, Path]
|
Output a diff of original and updated bioimageio.yaml. |
exclude_defaults |
bool
|
Exclude fields that have the default value (even if set explicitly). |
exclude_unset |
bool
|
Exclude fields that have not explicitly be set. |
model_config |
ConfigDict
|
Configuration for the model, should be a dictionary conforming to |
model_extra |
dict[str, Any] | None
|
Get extra fields set during validation. |
model_fields_set |
set[str]
|
Returns the set of fields that have been explicitly set on this model instance. |
output |
Union[Literal['display', 'stdout'], Path]
|
Output updated bioimageio.yaml to the terminal or write to a file. |
source |
CliPositionalArg[str]
|
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file |
updated |
Union[ResourceDescr, InvalidDescr]
|
|
Source code in pydantic/main.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__class_vars__
class-attribute
¤
__class_vars__: set[str]
The names of the class variables defined on the model.
__private_attributes__
class-attribute
¤
__private_attributes__: Dict[str, ModelPrivateAttr]
Metadata about the private attributes of the model.
__pydantic_complete__
class-attribute
¤
__pydantic_complete__: bool = False
Whether model building is completed, or if there are still undefined fields.
__pydantic_computed_fields__
class-attribute
¤
__pydantic_computed_fields__: Dict[str, ComputedFieldInfo]
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
__pydantic_core_schema__
class-attribute
¤
__pydantic_core_schema__: CoreSchema
The core schema of the model.
__pydantic_custom_init__
class-attribute
¤
__pydantic_custom_init__: bool
Whether the model has a custom __init__ method.
__pydantic_decorators__
class-attribute
¤
__pydantic_decorators__: _decorators.DecoratorInfos = _decorators.DecoratorInfos()
Metadata containing the decorators defined on the model.
This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
__pydantic_extra__
pydantic-field
¤
__pydantic_extra__: Dict[str, Any] | None
A dictionary containing extra values, if extra is set to 'allow'.
__pydantic_fields__
class-attribute
¤
__pydantic_fields__: Dict[str, FieldInfo]
A dictionary of field names and their corresponding FieldInfo objects.
This replaces Model.__fields__ from Pydantic V1.
__pydantic_fields_set__
pydantic-field
¤
__pydantic_fields_set__: set[str]
The names of fields explicitly set during instantiation.
__pydantic_generic_metadata__
class-attribute
¤
__pydantic_generic_metadata__: _generics.PydanticGenericMetadata
Metadata for generic models; contains data used for a similar purpose to args, origin, parameters in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__
class-attribute
¤
__pydantic_parent_namespace__: Dict[str, Any] | None = None
Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__
class-attribute
¤
__pydantic_post_init__: None | Literal['model_post_init']
The name of the post-init method for the model, if defined.
__pydantic_private__
pydantic-field
¤
__pydantic_private__: Dict[str, Any] | None
Values of private attributes set on the model instance.
__pydantic_root_model__
class-attribute
¤
__pydantic_root_model__: bool = False
Whether the model is a RootModel.
__pydantic_serializer__
class-attribute
¤
__pydantic_serializer__: SchemaSerializer
The pydantic-core SchemaSerializer used to dump instances of the model.
__pydantic_setattr_handlers__
class-attribute
¤
__pydantic_setattr_handlers__: Dict[str, Callable[[BaseModel, str, Any], None]]
__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__
__pydantic_validator__
class-attribute
¤
__pydantic_validator__: SchemaValidator | PluggableSchemaValidator
The pydantic-core SchemaValidator used to validate instances of the model.
__signature__
class-attribute
¤
__signature__: Signature
The synthesized __init__ [Signature][inspect.Signature] of the model.
__slots__
pydantic-field
¤
__slots__ = ('__dict__', '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__')
descr_id
property
¤
descr_id: str
a more user-friendly description id (replacing legacy ids with their nicknames)
diff
class-attribute
instance-attribute
¤
diff: Union[bool, Path] = Field(True, alias='diff')
Output a diff of original and updated bioimageio.yaml.
If a given path has an .html extension, a standalone HTML file is written,
otherwise the diff is saved in unified diff format (pure text).
exclude_defaults
class-attribute
instance-attribute
¤
exclude_defaults: bool = Field(False, alias='exclude-defaults')
Exclude fields that have the default value (even if set explicitly).
exclude_unset
class-attribute
instance-attribute
¤
exclude_unset: bool = Field(True, alias='exclude-unset')
Exclude fields that have not explicitly be set.
model_config
class-attribute
¤
model_config: ConfigDict = ConfigDict()
Configuration for the model, should be a dictionary conforming to ConfigDict.
model_extra
property
¤
model_extra: dict[str, Any] | None
Get extra fields set during validation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dictionary of extra fields, or |
model_fields_set
property
¤
model_fields_set: set[str]
Returns the set of fields that have been explicitly set on this model instance.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of strings representing the fields that have been set, i.e. that were not filled from defaults. |
output
class-attribute
instance-attribute
¤
output: Union[Literal['display', 'stdout'], Path] = 'display'
Output updated bioimageio.yaml to the terminal or write to a file.
Notes:
- "display": Render to the terminal with syntax highlighting.
- "stdout": Write to sys.stdout without syntax highligthing.
(More convenient for copying the updated bioimageio.yaml from the terminal.)
source
instance-attribute
¤
source: CliPositionalArg[str]
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file or a bioimage.io resource identifier, e.g. 'affable-shark'
__class_getitem__
¤
__class_getitem__(typevar_values: type[Any] | tuple[type[Any], ...]) -> type[BaseModel] | _forward_ref.PydanticRecursiveRef
Source code in pydantic/main.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
__copy__
¤
__copy__() -> Self
Returns a shallow copy of the model.
Source code in pydantic/main.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
__deepcopy__
¤
__deepcopy__(memo: dict[int, Any] | None = None) -> Self
Returns a deep copy of the model.
Source code in pydantic/main.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
__delattr__
¤
__delattr__(item: str) -> Any
Source code in pydantic/main.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
__eq__
¤
__eq__(other: Any) -> bool
Source code in pydantic/main.py
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
__get_pydantic_core_schema__
classmethod
¤
__get_pydantic_core_schema__(source: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema
Source code in pydantic/main.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
__get_pydantic_json_schema__
classmethod
¤
__get_pydantic_json_schema__(core_schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue
Hook into generating the model's JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CoreSchema
|
A |
required |
|
GetJsonSchemaHandler
|
Call into Pydantic's internal JSON schema generation.
This will raise a |
required |
Returns:
| Type | Description |
|---|---|
JsonSchemaValue
|
A JSON schema, as a Python object. |
Source code in pydantic/main.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
__getattr__
¤
__getattr__(item: str) -> Any
Source code in pydantic/main.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
__getstate__
¤
__getstate__() -> dict[Any, Any]
Source code in pydantic/main.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
__init_subclass__
¤
__init_subclass__(**kwargs: Unpack[ConfigDict])
This signature is included purely to help type-checkers check arguments to class declaration, which provides a way to conveniently set model_config key/value pairs.
from pydantic import BaseModel
class MyModel(BaseModel, extra='allow'): ...
However, this may be deceiving, since the actual calls to __init_subclass__ will not receive any
of the config arguments, and will only receive any keyword arguments passed during class initialization
that are not expected keys in ConfigDict. (This is due to the way ModelMetaclass.__new__ works.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Unpack[ConfigDict]
|
Keyword arguments passed to the class definition, which set model_config |
{}
|
Note
You may want to override __pydantic_init_subclass__ instead, which behaves similarly but is called
after the class is fully initialized.
Source code in pydantic/main.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
__iter__
¤
__iter__() -> TupleGenerator
So dict(model) works.
Source code in pydantic/main.py
1229 1230 1231 1232 1233 1234 | |
__pydantic_init_subclass__
classmethod
¤
__pydantic_init_subclass__(**kwargs: Any) -> None
This is intended to behave just like __init_subclass__, but is called by ModelMetaclass
only after basic class initialization is complete. In particular, attributes like model_fields will
be present when this is called, but forward annotations are not guaranteed to be resolved yet,
meaning that creating an instance of the class may fail.
This is necessary because __init_subclass__ will always be called by type.__new__,
and it would require a prohibitively large refactor to the ModelMetaclass to ensure that
type.__new__ was called in such a manner that the class would already be sufficiently initialized.
This will receive the same kwargs that would be passed to the standard __init_subclass__, namely,
any kwargs passed to the class definition that aren't used internally by Pydantic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Any keyword arguments passed to the class definition that aren't used internally by Pydantic. |
{}
|
Note
You may want to override __pydantic_on_complete__()
instead, which is called once the class and its fields are fully initialized and ready for validation.
Source code in pydantic/main.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
__pydantic_on_complete__
classmethod
¤
__pydantic_on_complete__() -> None
This is called once the class and its fields are fully initialized and ready to be used.
This typically happens when the class is created (just before
__pydantic_init_subclass__() is called on the superclass),
except when forward annotations are used that could not immediately be resolved.
In that case, it will be called later, when the model is rebuilt automatically or explicitly using
model_rebuild().
Source code in pydantic/main.py
877 878 879 880 881 882 883 884 885 886 | |
__replace__
¤
__replace__(**changes: Any) -> Self
Source code in pydantic/main.py
1125 1126 | |
__repr__
¤
__repr__() -> str
Source code in pydantic/main.py
1236 1237 | |
__repr_args__
¤
__repr_args__() -> _repr.ReprArgs
Source code in pydantic/main.py
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
__setattr__
¤
__setattr__(name: str, value: Any) -> None
Source code in pydantic/main.py
1028 1029 1030 1031 1032 1033 1034 | |
__setstate__
¤
__setstate__(state: dict[Any, Any]) -> None
Source code in pydantic/main.py
1139 1140 1141 1142 1143 | |
__str__
¤
__str__() -> str
Source code in pydantic/main.py
1274 1275 | |
cli_cmd
¤
cli_cmd()
Source code in src/bioimageio/core/cli.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
construct
classmethod
¤
construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Source code in pydantic/main.py
1477 1478 1479 1480 1481 1482 1483 1484 1485 | |
copy
¤
copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) -> Self
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in pydantic/main.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | |
dict
¤
dict(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> Dict[str, Any]
Source code in pydantic/main.py
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | |
from_orm
classmethod
¤
from_orm(obj: Any) -> Self
Source code in pydantic/main.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
json
¤
json(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
model_computed_fields
classmethod
¤
model_computed_fields() -> dict[str, ComputedFieldInfo]
A mapping of computed field names to their respective ComputedFieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
273 274 275 276 277 278 279 280 281 282 | |
model_construct
classmethod
¤
model_construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Note
model_construct() generally respects the model_config.extra setting on the provided model.
That is, if model_config.extra == 'allow', then all extra passed values are added to the model instance's __dict__
and __pydantic_extra__ fields. If model_config.extra == 'ignore' (the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct(), having model_config.extra == 'forbid' does not result in
an error if extra values are passed, but they will be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
set[str] | None
|
A set of field names that were originally explicitly set during instantiation. If provided,
this is directly used for the |
None
|
|
Any
|
Trusted or pre-validated data dictionary. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
A new instance of the |
Source code in pydantic/main.py
303 304 305 306 307 308 309 310 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
model_copy
¤
Usage Documentation
Returns a copy of the model.
Note
The underlying instance's [__dict__][object.__dict__] attribute is copied. This
might have unexpected side effects if you store anything in it, on top of the model
fields (e.g. the value of [cached properties][functools.cached_property]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, Any] | None
|
Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data. |
None
|
|
bool
|
Set to |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
New model instance. |
Source code in pydantic/main.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
model_dump
¤
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> dict[str, Any]
Usage Documentation
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Literal['json', 'python'] | str
|
The mode in which |
'python'
|
|
IncEx | None
|
A set of fields to include in the output. |
None
|
|
IncEx | None
|
A set of fields to exclude from the output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to use the field's alias in the dictionary key if defined. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representation of the model. |
Source code in pydantic/main.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
model_dump_json
¤
model_dump_json(*, indent: int | None = None, ensure_ascii: bool = False, include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> str
Usage Documentation
Generates a JSON representation of the model using Pydantic's to_json method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
|
bool
|
If |
False
|
|
IncEx | None
|
Field(s) to include in the JSON output. |
None
|
|
IncEx | None
|
Field(s) to exclude from the JSON output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to serialize using field aliases. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representation of the model. |
Source code in pydantic/main.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
model_fields
classmethod
¤
A mapping of field names to their respective FieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
262 263 264 265 266 267 268 269 270 271 | |
model_json_schema
classmethod
¤
model_json_schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema, mode: JsonSchemaMode = 'validation', *, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of') -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to use attribute aliases or not. |
True
|
|
str
|
The reference template. |
DEFAULT_REF_TEMPLATE
|
|
Literal['any_of', 'primitive_type_array']
|
The format to use when combining schemas from unions together. Can be one of:
|
'any_of'
|
|
type[GenerateJsonSchema]
|
To override the logic used to generate the JSON schema, as a subclass of
|
GenerateJsonSchema
|
|
JsonSchemaMode
|
The mode in which to generate the schema. |
'validation'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON schema for the given model class. |
Source code in pydantic/main.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
model_parametrized_name
classmethod
¤
model_parametrized_name(params: tuple[type[Any], ...]) -> str
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
| Type | Description |
|---|---|
str
|
String representing the new class where |
Raises:
| Type | Description |
|---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in pydantic/main.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
model_post_init
¤
model_post_init(context: Any) -> None
Override this method to perform additional initialization after __init__ and model_construct.
This is useful if you want to do some validation that requires the entire model to be initialized.
Source code in pydantic/main.py
612 613 614 615 | |
model_rebuild
classmethod
¤
model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to force the rebuilding of the model schema, defaults to |
False
|
|
bool
|
Whether to raise errors, defaults to |
True
|
|
int
|
The depth level of the parent namespace, defaults to 2. |
2
|
|
MappingNamespace | None
|
The types namespace, defaults to |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
Returns |
Source code in pydantic/main.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
model_validate
classmethod
¤
model_validate(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, from_attributes: bool | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate a pydantic model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
bool | None
|
Whether to extract data from object attributes. |
None
|
|
Any | None
|
Additional context to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the object could not be validated. |
Returns:
| Type | Description |
|---|---|
Self
|
The validated model instance. |
Source code in pydantic/main.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
model_validate_json
classmethod
¤
model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Usage Documentation
Validate the given JSON data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in pydantic/main.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
model_validate_strings
classmethod
¤
model_validate_strings(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate the given object with string data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object containing string data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Source code in pydantic/main.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
parse_file
classmethod
¤
parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
parse_obj
classmethod
¤
parse_obj(obj: Any) -> Self
Source code in pydantic/main.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 | |
parse_raw
classmethod
¤
parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
schema
classmethod
¤
schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE) -> Dict[str, Any]
Source code in pydantic/main.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 | |
schema_json
classmethod
¤
schema_json(*, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
update_forward_refs
classmethod
¤
update_forward_refs(**localns: Any) -> None
Source code in pydantic/main.py
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
validate
classmethod
¤
validate(value: Any) -> Self
Source code in pydantic/main.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 | |
UpdateFormatCmd
¤
UpdateFormatCmd(**data: Any)
Bases: UpdateCmdBase
flowchart TD
bioimageio.core.cli.UpdateFormatCmd[UpdateFormatCmd]
bioimageio.core.cli.UpdateCmdBase[UpdateCmdBase]
bioimageio.core.cli.CmdBase[CmdBase]
bioimageio.core.cli.WithSource[WithSource]
bioimageio.core.cli.ArgMixin[ArgMixin]
pydantic.main.BaseModel[BaseModel]
bioimageio.core.cli.UpdateCmdBase --> bioimageio.core.cli.UpdateFormatCmd
bioimageio.core.cli.CmdBase --> bioimageio.core.cli.UpdateCmdBase
pydantic.main.BaseModel --> bioimageio.core.cli.CmdBase
bioimageio.core.cli.WithSource --> bioimageio.core.cli.UpdateCmdBase
bioimageio.core.cli.ArgMixin --> bioimageio.core.cli.WithSource
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
click bioimageio.core.cli.UpdateFormatCmd href "" "bioimageio.core.cli.UpdateFormatCmd"
click bioimageio.core.cli.UpdateCmdBase href "" "bioimageio.core.cli.UpdateCmdBase"
click bioimageio.core.cli.CmdBase href "" "bioimageio.core.cli.CmdBase"
click bioimageio.core.cli.WithSource href "" "bioimageio.core.cli.WithSource"
click bioimageio.core.cli.ArgMixin href "" "bioimageio.core.cli.ArgMixin"
click pydantic.main.BaseModel href "" "pydantic.main.BaseModel"
Update the metadata format to the latest format version.
Raises ValidationError if the input data cannot be
validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Methods:
| Name | Description |
|---|---|
__class_getitem__ |
|
__copy__ |
Returns a shallow copy of the model. |
__deepcopy__ |
Returns a deep copy of the model. |
__delattr__ |
|
__eq__ |
|
__get_pydantic_core_schema__ |
|
__get_pydantic_json_schema__ |
Hook into generating the model's JSON schema. |
__getattr__ |
|
__getstate__ |
|
__init_subclass__ |
This signature is included purely to help type-checkers check arguments to class declaration, which |
__iter__ |
So |
__pydantic_init_subclass__ |
This is intended to behave just like |
__pydantic_on_complete__ |
This is called once the class and its fields are fully initialized and ready to be used. |
__replace__ |
|
__repr__ |
|
__repr_args__ |
|
__setattr__ |
|
__setstate__ |
|
__str__ |
|
cli_cmd |
|
construct |
|
copy |
Returns a copy of the model. |
dict |
|
from_orm |
|
json |
|
model_computed_fields |
A mapping of computed field names to their respective |
model_construct |
Creates a new instance of the |
model_copy |
Usage Documentation |
model_dump |
Usage Documentation |
model_dump_json |
Usage Documentation |
model_fields |
A mapping of field names to their respective |
model_json_schema |
Generates a JSON schema for a model class. |
model_parametrized_name |
Compute the class name for parametrizations of generic classes. |
model_post_init |
Override this method to perform additional initialization after |
model_rebuild |
Try to rebuild the pydantic-core schema for the model. |
model_validate |
Validate a pydantic model instance. |
model_validate_json |
Usage Documentation |
model_validate_strings |
Validate the given object with string data against the Pydantic model. |
parse_file |
|
parse_obj |
|
parse_raw |
|
schema |
|
schema_json |
|
update_forward_refs |
|
validate |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__class_vars__ |
set[str]
|
The names of the class variables defined on the model. |
__fields__ |
dict[str, FieldInfo]
|
|
__fields_set__ |
set[str]
|
|
__pretty__ |
|
|
__private_attributes__ |
Dict[str, ModelPrivateAttr]
|
Metadata about the private attributes of the model. |
__pydantic_complete__ |
bool
|
Whether model building is completed, or if there are still undefined fields. |
__pydantic_computed_fields__ |
Dict[str, ComputedFieldInfo]
|
A dictionary of computed field names and their corresponding |
__pydantic_core_schema__ |
CoreSchema
|
The core schema of the model. |
__pydantic_custom_init__ |
bool
|
Whether the model has a custom |
__pydantic_decorators__ |
_decorators.DecoratorInfos
|
Metadata containing the decorators defined on the model. |
__pydantic_extra__ |
Dict[str, Any] | None
|
A dictionary containing extra values, if |
__pydantic_fields__ |
Dict[str, FieldInfo]
|
A dictionary of field names and their corresponding |
__pydantic_fields_set__ |
set[str]
|
The names of fields explicitly set during instantiation. |
__pydantic_generic_metadata__ |
_generics.PydanticGenericMetadata
|
Metadata for generic models; contains data used for a similar purpose to |
__pydantic_parent_namespace__ |
Dict[str, Any] | None
|
Parent namespace of the model, used for automatic rebuilding of models. |
__pydantic_post_init__ |
None | Literal['model_post_init']
|
The name of the post-init method for the model, if defined. |
__pydantic_private__ |
Dict[str, Any] | None
|
Values of private attributes set on the model instance. |
__pydantic_root_model__ |
bool
|
Whether the model is a |
__pydantic_serializer__ |
SchemaSerializer
|
The |
__pydantic_setattr_handlers__ |
Dict[str, Callable[[BaseModel, str, Any], None]]
|
|
__pydantic_validator__ |
SchemaValidator | PluggableSchemaValidator
|
The |
__repr_name__ |
|
|
__repr_recursion__ |
|
|
__repr_str__ |
|
|
__rich_repr__ |
|
|
__signature__ |
Signature
|
The synthesized |
__slots__ |
|
|
descr |
|
|
descr_id |
str
|
a more user-friendly description id |
diff |
Union[bool, Path]
|
Output a diff of original and updated bioimageio.yaml. |
exclude_defaults |
bool
|
Exclude fields that have the default value (even if set explicitly). |
exclude_unset |
bool
|
Exclude fields that have not explicitly be set. |
model_config |
ConfigDict
|
Configuration for the model, should be a dictionary conforming to |
model_extra |
dict[str, Any] | None
|
Get extra fields set during validation. |
model_fields_set |
set[str]
|
Returns the set of fields that have been explicitly set on this model instance. |
output |
Union[Literal['display', 'stdout'], Path]
|
Output updated bioimageio.yaml to the terminal or write to a file. |
perform_io_checks |
bool
|
Wether or not to attempt validation that may require file download. |
source |
CliPositionalArg[str]
|
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file |
updated |
|
Source code in pydantic/main.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__class_vars__
class-attribute
¤
__class_vars__: set[str]
The names of the class variables defined on the model.
__private_attributes__
class-attribute
¤
__private_attributes__: Dict[str, ModelPrivateAttr]
Metadata about the private attributes of the model.
__pydantic_complete__
class-attribute
¤
__pydantic_complete__: bool = False
Whether model building is completed, or if there are still undefined fields.
__pydantic_computed_fields__
class-attribute
¤
__pydantic_computed_fields__: Dict[str, ComputedFieldInfo]
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
__pydantic_core_schema__
class-attribute
¤
__pydantic_core_schema__: CoreSchema
The core schema of the model.
__pydantic_custom_init__
class-attribute
¤
__pydantic_custom_init__: bool
Whether the model has a custom __init__ method.
__pydantic_decorators__
class-attribute
¤
__pydantic_decorators__: _decorators.DecoratorInfos = _decorators.DecoratorInfos()
Metadata containing the decorators defined on the model.
This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
__pydantic_extra__
pydantic-field
¤
__pydantic_extra__: Dict[str, Any] | None
A dictionary containing extra values, if extra is set to 'allow'.
__pydantic_fields__
class-attribute
¤
__pydantic_fields__: Dict[str, FieldInfo]
A dictionary of field names and their corresponding FieldInfo objects.
This replaces Model.__fields__ from Pydantic V1.
__pydantic_fields_set__
pydantic-field
¤
__pydantic_fields_set__: set[str]
The names of fields explicitly set during instantiation.
__pydantic_generic_metadata__
class-attribute
¤
__pydantic_generic_metadata__: _generics.PydanticGenericMetadata
Metadata for generic models; contains data used for a similar purpose to args, origin, parameters in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__
class-attribute
¤
__pydantic_parent_namespace__: Dict[str, Any] | None = None
Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__
class-attribute
¤
__pydantic_post_init__: None | Literal['model_post_init']
The name of the post-init method for the model, if defined.
__pydantic_private__
pydantic-field
¤
__pydantic_private__: Dict[str, Any] | None
Values of private attributes set on the model instance.
__pydantic_root_model__
class-attribute
¤
__pydantic_root_model__: bool = False
Whether the model is a RootModel.
__pydantic_serializer__
class-attribute
¤
__pydantic_serializer__: SchemaSerializer
The pydantic-core SchemaSerializer used to dump instances of the model.
__pydantic_setattr_handlers__
class-attribute
¤
__pydantic_setattr_handlers__: Dict[str, Callable[[BaseModel, str, Any], None]]
__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__
__pydantic_validator__
class-attribute
¤
__pydantic_validator__: SchemaValidator | PluggableSchemaValidator
The pydantic-core SchemaValidator used to validate instances of the model.
__signature__
class-attribute
¤
__signature__: Signature
The synthesized __init__ [Signature][inspect.Signature] of the model.
__slots__
pydantic-field
¤
__slots__ = ('__dict__', '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__')
descr_id
property
¤
descr_id: str
a more user-friendly description id (replacing legacy ids with their nicknames)
diff
class-attribute
instance-attribute
¤
diff: Union[bool, Path] = Field(True, alias='diff')
Output a diff of original and updated bioimageio.yaml.
If a given path has an .html extension, a standalone HTML file is written,
otherwise the diff is saved in unified diff format (pure text).
exclude_defaults
class-attribute
instance-attribute
¤
exclude_defaults: bool = Field(True, alias='exclude-defaults')
Exclude fields that have the default value (even if set explicitly).
Note
The update process sets most unset fields explicitly with their default value.
exclude_unset
class-attribute
instance-attribute
¤
exclude_unset: bool = Field(True, alias='exclude-unset')
Exclude fields that have not explicitly be set.
model_config
class-attribute
¤
model_config: ConfigDict = ConfigDict()
Configuration for the model, should be a dictionary conforming to ConfigDict.
model_extra
property
¤
model_extra: dict[str, Any] | None
Get extra fields set during validation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dictionary of extra fields, or |
model_fields_set
property
¤
model_fields_set: set[str]
Returns the set of fields that have been explicitly set on this model instance.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of strings representing the fields that have been set, i.e. that were not filled from defaults. |
output
class-attribute
instance-attribute
¤
output: Union[Literal['display', 'stdout'], Path] = 'display'
Output updated bioimageio.yaml to the terminal or write to a file.
Notes:
- "display": Render to the terminal with syntax highlighting.
- "stdout": Write to sys.stdout without syntax highligthing.
(More convenient for copying the updated bioimageio.yaml from the terminal.)
perform_io_checks
class-attribute
instance-attribute
¤
Wether or not to attempt validation that may require file download.
If True file hash values are added if not present.
source
instance-attribute
¤
source: CliPositionalArg[str]
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file or a bioimage.io resource identifier, e.g. 'affable-shark'
__class_getitem__
¤
__class_getitem__(typevar_values: type[Any] | tuple[type[Any], ...]) -> type[BaseModel] | _forward_ref.PydanticRecursiveRef
Source code in pydantic/main.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
__copy__
¤
__copy__() -> Self
Returns a shallow copy of the model.
Source code in pydantic/main.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
__deepcopy__
¤
__deepcopy__(memo: dict[int, Any] | None = None) -> Self
Returns a deep copy of the model.
Source code in pydantic/main.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
__delattr__
¤
__delattr__(item: str) -> Any
Source code in pydantic/main.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
__eq__
¤
__eq__(other: Any) -> bool
Source code in pydantic/main.py
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
__get_pydantic_core_schema__
classmethod
¤
__get_pydantic_core_schema__(source: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema
Source code in pydantic/main.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
__get_pydantic_json_schema__
classmethod
¤
__get_pydantic_json_schema__(core_schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue
Hook into generating the model's JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CoreSchema
|
A |
required |
|
GetJsonSchemaHandler
|
Call into Pydantic's internal JSON schema generation.
This will raise a |
required |
Returns:
| Type | Description |
|---|---|
JsonSchemaValue
|
A JSON schema, as a Python object. |
Source code in pydantic/main.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
__getattr__
¤
__getattr__(item: str) -> Any
Source code in pydantic/main.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
__getstate__
¤
__getstate__() -> dict[Any, Any]
Source code in pydantic/main.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
__init_subclass__
¤
__init_subclass__(**kwargs: Unpack[ConfigDict])
This signature is included purely to help type-checkers check arguments to class declaration, which provides a way to conveniently set model_config key/value pairs.
from pydantic import BaseModel
class MyModel(BaseModel, extra='allow'): ...
However, this may be deceiving, since the actual calls to __init_subclass__ will not receive any
of the config arguments, and will only receive any keyword arguments passed during class initialization
that are not expected keys in ConfigDict. (This is due to the way ModelMetaclass.__new__ works.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Unpack[ConfigDict]
|
Keyword arguments passed to the class definition, which set model_config |
{}
|
Note
You may want to override __pydantic_init_subclass__ instead, which behaves similarly but is called
after the class is fully initialized.
Source code in pydantic/main.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
__iter__
¤
__iter__() -> TupleGenerator
So dict(model) works.
Source code in pydantic/main.py
1229 1230 1231 1232 1233 1234 | |
__pydantic_init_subclass__
classmethod
¤
__pydantic_init_subclass__(**kwargs: Any) -> None
This is intended to behave just like __init_subclass__, but is called by ModelMetaclass
only after basic class initialization is complete. In particular, attributes like model_fields will
be present when this is called, but forward annotations are not guaranteed to be resolved yet,
meaning that creating an instance of the class may fail.
This is necessary because __init_subclass__ will always be called by type.__new__,
and it would require a prohibitively large refactor to the ModelMetaclass to ensure that
type.__new__ was called in such a manner that the class would already be sufficiently initialized.
This will receive the same kwargs that would be passed to the standard __init_subclass__, namely,
any kwargs passed to the class definition that aren't used internally by Pydantic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Any keyword arguments passed to the class definition that aren't used internally by Pydantic. |
{}
|
Note
You may want to override __pydantic_on_complete__()
instead, which is called once the class and its fields are fully initialized and ready for validation.
Source code in pydantic/main.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
__pydantic_on_complete__
classmethod
¤
__pydantic_on_complete__() -> None
This is called once the class and its fields are fully initialized and ready to be used.
This typically happens when the class is created (just before
__pydantic_init_subclass__() is called on the superclass),
except when forward annotations are used that could not immediately be resolved.
In that case, it will be called later, when the model is rebuilt automatically or explicitly using
model_rebuild().
Source code in pydantic/main.py
877 878 879 880 881 882 883 884 885 886 | |
__replace__
¤
__replace__(**changes: Any) -> Self
Source code in pydantic/main.py
1125 1126 | |
__repr__
¤
__repr__() -> str
Source code in pydantic/main.py
1236 1237 | |
__repr_args__
¤
__repr_args__() -> _repr.ReprArgs
Source code in pydantic/main.py
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
__setattr__
¤
__setattr__(name: str, value: Any) -> None
Source code in pydantic/main.py
1028 1029 1030 1031 1032 1033 1034 | |
__setstate__
¤
__setstate__(state: dict[Any, Any]) -> None
Source code in pydantic/main.py
1139 1140 1141 1142 1143 | |
__str__
¤
__str__() -> str
Source code in pydantic/main.py
1274 1275 | |
cli_cmd
¤
cli_cmd()
Source code in src/bioimageio/core/cli.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
construct
classmethod
¤
construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Source code in pydantic/main.py
1477 1478 1479 1480 1481 1482 1483 1484 1485 | |
copy
¤
copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) -> Self
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in pydantic/main.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | |
dict
¤
dict(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> Dict[str, Any]
Source code in pydantic/main.py
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | |
from_orm
classmethod
¤
from_orm(obj: Any) -> Self
Source code in pydantic/main.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
json
¤
json(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
model_computed_fields
classmethod
¤
model_computed_fields() -> dict[str, ComputedFieldInfo]
A mapping of computed field names to their respective ComputedFieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
273 274 275 276 277 278 279 280 281 282 | |
model_construct
classmethod
¤
model_construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Note
model_construct() generally respects the model_config.extra setting on the provided model.
That is, if model_config.extra == 'allow', then all extra passed values are added to the model instance's __dict__
and __pydantic_extra__ fields. If model_config.extra == 'ignore' (the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct(), having model_config.extra == 'forbid' does not result in
an error if extra values are passed, but they will be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
set[str] | None
|
A set of field names that were originally explicitly set during instantiation. If provided,
this is directly used for the |
None
|
|
Any
|
Trusted or pre-validated data dictionary. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
A new instance of the |
Source code in pydantic/main.py
303 304 305 306 307 308 309 310 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
model_copy
¤
Usage Documentation
Returns a copy of the model.
Note
The underlying instance's [__dict__][object.__dict__] attribute is copied. This
might have unexpected side effects if you store anything in it, on top of the model
fields (e.g. the value of [cached properties][functools.cached_property]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, Any] | None
|
Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data. |
None
|
|
bool
|
Set to |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
New model instance. |
Source code in pydantic/main.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
model_dump
¤
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> dict[str, Any]
Usage Documentation
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Literal['json', 'python'] | str
|
The mode in which |
'python'
|
|
IncEx | None
|
A set of fields to include in the output. |
None
|
|
IncEx | None
|
A set of fields to exclude from the output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to use the field's alias in the dictionary key if defined. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representation of the model. |
Source code in pydantic/main.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
model_dump_json
¤
model_dump_json(*, indent: int | None = None, ensure_ascii: bool = False, include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> str
Usage Documentation
Generates a JSON representation of the model using Pydantic's to_json method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
|
bool
|
If |
False
|
|
IncEx | None
|
Field(s) to include in the JSON output. |
None
|
|
IncEx | None
|
Field(s) to exclude from the JSON output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to serialize using field aliases. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representation of the model. |
Source code in pydantic/main.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
model_fields
classmethod
¤
A mapping of field names to their respective FieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
262 263 264 265 266 267 268 269 270 271 | |
model_json_schema
classmethod
¤
model_json_schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema, mode: JsonSchemaMode = 'validation', *, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of') -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to use attribute aliases or not. |
True
|
|
str
|
The reference template. |
DEFAULT_REF_TEMPLATE
|
|
Literal['any_of', 'primitive_type_array']
|
The format to use when combining schemas from unions together. Can be one of:
|
'any_of'
|
|
type[GenerateJsonSchema]
|
To override the logic used to generate the JSON schema, as a subclass of
|
GenerateJsonSchema
|
|
JsonSchemaMode
|
The mode in which to generate the schema. |
'validation'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON schema for the given model class. |
Source code in pydantic/main.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
model_parametrized_name
classmethod
¤
model_parametrized_name(params: tuple[type[Any], ...]) -> str
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
| Type | Description |
|---|---|
str
|
String representing the new class where |
Raises:
| Type | Description |
|---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in pydantic/main.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
model_post_init
¤
model_post_init(context: Any) -> None
Override this method to perform additional initialization after __init__ and model_construct.
This is useful if you want to do some validation that requires the entire model to be initialized.
Source code in pydantic/main.py
612 613 614 615 | |
model_rebuild
classmethod
¤
model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to force the rebuilding of the model schema, defaults to |
False
|
|
bool
|
Whether to raise errors, defaults to |
True
|
|
int
|
The depth level of the parent namespace, defaults to 2. |
2
|
|
MappingNamespace | None
|
The types namespace, defaults to |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
Returns |
Source code in pydantic/main.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
model_validate
classmethod
¤
model_validate(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, from_attributes: bool | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate a pydantic model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
bool | None
|
Whether to extract data from object attributes. |
None
|
|
Any | None
|
Additional context to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the object could not be validated. |
Returns:
| Type | Description |
|---|---|
Self
|
The validated model instance. |
Source code in pydantic/main.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
model_validate_json
classmethod
¤
model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Usage Documentation
Validate the given JSON data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in pydantic/main.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
model_validate_strings
classmethod
¤
model_validate_strings(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate the given object with string data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object containing string data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Source code in pydantic/main.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
parse_file
classmethod
¤
parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
parse_obj
classmethod
¤
parse_obj(obj: Any) -> Self
Source code in pydantic/main.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 | |
parse_raw
classmethod
¤
parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
schema
classmethod
¤
schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE) -> Dict[str, Any]
Source code in pydantic/main.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 | |
schema_json
classmethod
¤
schema_json(*, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
update_forward_refs
classmethod
¤
update_forward_refs(**localns: Any) -> None
Source code in pydantic/main.py
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
validate
classmethod
¤
validate(value: Any) -> Self
Source code in pydantic/main.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 | |
UpdateHashesCmd
¤
UpdateHashesCmd(**data: Any)
Bases: UpdateCmdBase
flowchart TD
bioimageio.core.cli.UpdateHashesCmd[UpdateHashesCmd]
bioimageio.core.cli.UpdateCmdBase[UpdateCmdBase]
bioimageio.core.cli.CmdBase[CmdBase]
bioimageio.core.cli.WithSource[WithSource]
bioimageio.core.cli.ArgMixin[ArgMixin]
pydantic.main.BaseModel[BaseModel]
bioimageio.core.cli.UpdateCmdBase --> bioimageio.core.cli.UpdateHashesCmd
bioimageio.core.cli.CmdBase --> bioimageio.core.cli.UpdateCmdBase
pydantic.main.BaseModel --> bioimageio.core.cli.CmdBase
bioimageio.core.cli.WithSource --> bioimageio.core.cli.UpdateCmdBase
bioimageio.core.cli.ArgMixin --> bioimageio.core.cli.WithSource
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
click bioimageio.core.cli.UpdateHashesCmd href "" "bioimageio.core.cli.UpdateHashesCmd"
click bioimageio.core.cli.UpdateCmdBase href "" "bioimageio.core.cli.UpdateCmdBase"
click bioimageio.core.cli.CmdBase href "" "bioimageio.core.cli.CmdBase"
click bioimageio.core.cli.WithSource href "" "bioimageio.core.cli.WithSource"
click bioimageio.core.cli.ArgMixin href "" "bioimageio.core.cli.ArgMixin"
click pydantic.main.BaseModel href "" "pydantic.main.BaseModel"
Create a bioimageio.yaml description with updated file hashes.
Raises ValidationError if the input data cannot be
validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Methods:
| Name | Description |
|---|---|
__class_getitem__ |
|
__copy__ |
Returns a shallow copy of the model. |
__deepcopy__ |
Returns a deep copy of the model. |
__delattr__ |
|
__eq__ |
|
__get_pydantic_core_schema__ |
|
__get_pydantic_json_schema__ |
Hook into generating the model's JSON schema. |
__getattr__ |
|
__getstate__ |
|
__init_subclass__ |
This signature is included purely to help type-checkers check arguments to class declaration, which |
__iter__ |
So |
__pydantic_init_subclass__ |
This is intended to behave just like |
__pydantic_on_complete__ |
This is called once the class and its fields are fully initialized and ready to be used. |
__replace__ |
|
__repr__ |
|
__repr_args__ |
|
__setattr__ |
|
__setstate__ |
|
__str__ |
|
cli_cmd |
|
construct |
|
copy |
Returns a copy of the model. |
dict |
|
from_orm |
|
json |
|
model_computed_fields |
A mapping of computed field names to their respective |
model_construct |
Creates a new instance of the |
model_copy |
Usage Documentation |
model_dump |
Usage Documentation |
model_dump_json |
Usage Documentation |
model_fields |
A mapping of field names to their respective |
model_json_schema |
Generates a JSON schema for a model class. |
model_parametrized_name |
Compute the class name for parametrizations of generic classes. |
model_post_init |
Override this method to perform additional initialization after |
model_rebuild |
Try to rebuild the pydantic-core schema for the model. |
model_validate |
Validate a pydantic model instance. |
model_validate_json |
Usage Documentation |
model_validate_strings |
Validate the given object with string data against the Pydantic model. |
parse_file |
|
parse_obj |
|
parse_raw |
|
schema |
|
schema_json |
|
update_forward_refs |
|
validate |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__class_vars__ |
set[str]
|
The names of the class variables defined on the model. |
__fields__ |
dict[str, FieldInfo]
|
|
__fields_set__ |
set[str]
|
|
__pretty__ |
|
|
__private_attributes__ |
Dict[str, ModelPrivateAttr]
|
Metadata about the private attributes of the model. |
__pydantic_complete__ |
bool
|
Whether model building is completed, or if there are still undefined fields. |
__pydantic_computed_fields__ |
Dict[str, ComputedFieldInfo]
|
A dictionary of computed field names and their corresponding |
__pydantic_core_schema__ |
CoreSchema
|
The core schema of the model. |
__pydantic_custom_init__ |
bool
|
Whether the model has a custom |
__pydantic_decorators__ |
_decorators.DecoratorInfos
|
Metadata containing the decorators defined on the model. |
__pydantic_extra__ |
Dict[str, Any] | None
|
A dictionary containing extra values, if |
__pydantic_fields__ |
Dict[str, FieldInfo]
|
A dictionary of field names and their corresponding |
__pydantic_fields_set__ |
set[str]
|
The names of fields explicitly set during instantiation. |
__pydantic_generic_metadata__ |
_generics.PydanticGenericMetadata
|
Metadata for generic models; contains data used for a similar purpose to |
__pydantic_parent_namespace__ |
Dict[str, Any] | None
|
Parent namespace of the model, used for automatic rebuilding of models. |
__pydantic_post_init__ |
None | Literal['model_post_init']
|
The name of the post-init method for the model, if defined. |
__pydantic_private__ |
Dict[str, Any] | None
|
Values of private attributes set on the model instance. |
__pydantic_root_model__ |
bool
|
Whether the model is a |
__pydantic_serializer__ |
SchemaSerializer
|
The |
__pydantic_setattr_handlers__ |
Dict[str, Callable[[BaseModel, str, Any], None]]
|
|
__pydantic_validator__ |
SchemaValidator | PluggableSchemaValidator
|
The |
__repr_name__ |
|
|
__repr_recursion__ |
|
|
__repr_str__ |
|
|
__rich_repr__ |
|
|
__signature__ |
Signature
|
The synthesized |
__slots__ |
|
|
descr |
|
|
descr_id |
str
|
a more user-friendly description id |
diff |
Union[bool, Path]
|
Output a diff of original and updated bioimageio.yaml. |
exclude_defaults |
bool
|
Exclude fields that have the default value (even if set explicitly). |
exclude_unset |
bool
|
Exclude fields that have not explicitly be set. |
model_config |
ConfigDict
|
Configuration for the model, should be a dictionary conforming to |
model_extra |
dict[str, Any] | None
|
Get extra fields set during validation. |
model_fields_set |
set[str]
|
Returns the set of fields that have been explicitly set on this model instance. |
output |
Union[Literal['display', 'stdout'], Path]
|
Output updated bioimageio.yaml to the terminal or write to a file. |
source |
CliPositionalArg[str]
|
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file |
updated |
|
Source code in pydantic/main.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__class_vars__
class-attribute
¤
__class_vars__: set[str]
The names of the class variables defined on the model.
__private_attributes__
class-attribute
¤
__private_attributes__: Dict[str, ModelPrivateAttr]
Metadata about the private attributes of the model.
__pydantic_complete__
class-attribute
¤
__pydantic_complete__: bool = False
Whether model building is completed, or if there are still undefined fields.
__pydantic_computed_fields__
class-attribute
¤
__pydantic_computed_fields__: Dict[str, ComputedFieldInfo]
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
__pydantic_core_schema__
class-attribute
¤
__pydantic_core_schema__: CoreSchema
The core schema of the model.
__pydantic_custom_init__
class-attribute
¤
__pydantic_custom_init__: bool
Whether the model has a custom __init__ method.
__pydantic_decorators__
class-attribute
¤
__pydantic_decorators__: _decorators.DecoratorInfos = _decorators.DecoratorInfos()
Metadata containing the decorators defined on the model.
This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
__pydantic_extra__
pydantic-field
¤
__pydantic_extra__: Dict[str, Any] | None
A dictionary containing extra values, if extra is set to 'allow'.
__pydantic_fields__
class-attribute
¤
__pydantic_fields__: Dict[str, FieldInfo]
A dictionary of field names and their corresponding FieldInfo objects.
This replaces Model.__fields__ from Pydantic V1.
__pydantic_fields_set__
pydantic-field
¤
__pydantic_fields_set__: set[str]
The names of fields explicitly set during instantiation.
__pydantic_generic_metadata__
class-attribute
¤
__pydantic_generic_metadata__: _generics.PydanticGenericMetadata
Metadata for generic models; contains data used for a similar purpose to args, origin, parameters in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__
class-attribute
¤
__pydantic_parent_namespace__: Dict[str, Any] | None = None
Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__
class-attribute
¤
__pydantic_post_init__: None | Literal['model_post_init']
The name of the post-init method for the model, if defined.
__pydantic_private__
pydantic-field
¤
__pydantic_private__: Dict[str, Any] | None
Values of private attributes set on the model instance.
__pydantic_root_model__
class-attribute
¤
__pydantic_root_model__: bool = False
Whether the model is a RootModel.
__pydantic_serializer__
class-attribute
¤
__pydantic_serializer__: SchemaSerializer
The pydantic-core SchemaSerializer used to dump instances of the model.
__pydantic_setattr_handlers__
class-attribute
¤
__pydantic_setattr_handlers__: Dict[str, Callable[[BaseModel, str, Any], None]]
__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__
__pydantic_validator__
class-attribute
¤
__pydantic_validator__: SchemaValidator | PluggableSchemaValidator
The pydantic-core SchemaValidator used to validate instances of the model.
__signature__
class-attribute
¤
__signature__: Signature
The synthesized __init__ [Signature][inspect.Signature] of the model.
__slots__
pydantic-field
¤
__slots__ = ('__dict__', '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__')
descr_id
property
¤
descr_id: str
a more user-friendly description id (replacing legacy ids with their nicknames)
diff
class-attribute
instance-attribute
¤
diff: Union[bool, Path] = Field(True, alias='diff')
Output a diff of original and updated bioimageio.yaml.
If a given path has an .html extension, a standalone HTML file is written,
otherwise the diff is saved in unified diff format (pure text).
exclude_defaults
class-attribute
instance-attribute
¤
exclude_defaults: bool = Field(False, alias='exclude-defaults')
Exclude fields that have the default value (even if set explicitly).
exclude_unset
class-attribute
instance-attribute
¤
exclude_unset: bool = Field(True, alias='exclude-unset')
Exclude fields that have not explicitly be set.
model_config
class-attribute
¤
model_config: ConfigDict = ConfigDict()
Configuration for the model, should be a dictionary conforming to ConfigDict.
model_extra
property
¤
model_extra: dict[str, Any] | None
Get extra fields set during validation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dictionary of extra fields, or |
model_fields_set
property
¤
model_fields_set: set[str]
Returns the set of fields that have been explicitly set on this model instance.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of strings representing the fields that have been set, i.e. that were not filled from defaults. |
output
class-attribute
instance-attribute
¤
output: Union[Literal['display', 'stdout'], Path] = 'display'
Output updated bioimageio.yaml to the terminal or write to a file.
Notes:
- "display": Render to the terminal with syntax highlighting.
- "stdout": Write to sys.stdout without syntax highligthing.
(More convenient for copying the updated bioimageio.yaml from the terminal.)
source
instance-attribute
¤
source: CliPositionalArg[str]
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file or a bioimage.io resource identifier, e.g. 'affable-shark'
__class_getitem__
¤
__class_getitem__(typevar_values: type[Any] | tuple[type[Any], ...]) -> type[BaseModel] | _forward_ref.PydanticRecursiveRef
Source code in pydantic/main.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
__copy__
¤
__copy__() -> Self
Returns a shallow copy of the model.
Source code in pydantic/main.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
__deepcopy__
¤
__deepcopy__(memo: dict[int, Any] | None = None) -> Self
Returns a deep copy of the model.
Source code in pydantic/main.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
__delattr__
¤
__delattr__(item: str) -> Any
Source code in pydantic/main.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
__eq__
¤
__eq__(other: Any) -> bool
Source code in pydantic/main.py
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
__get_pydantic_core_schema__
classmethod
¤
__get_pydantic_core_schema__(source: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema
Source code in pydantic/main.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
__get_pydantic_json_schema__
classmethod
¤
__get_pydantic_json_schema__(core_schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue
Hook into generating the model's JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CoreSchema
|
A |
required |
|
GetJsonSchemaHandler
|
Call into Pydantic's internal JSON schema generation.
This will raise a |
required |
Returns:
| Type | Description |
|---|---|
JsonSchemaValue
|
A JSON schema, as a Python object. |
Source code in pydantic/main.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
__getattr__
¤
__getattr__(item: str) -> Any
Source code in pydantic/main.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
__getstate__
¤
__getstate__() -> dict[Any, Any]
Source code in pydantic/main.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
__init_subclass__
¤
__init_subclass__(**kwargs: Unpack[ConfigDict])
This signature is included purely to help type-checkers check arguments to class declaration, which provides a way to conveniently set model_config key/value pairs.
from pydantic import BaseModel
class MyModel(BaseModel, extra='allow'): ...
However, this may be deceiving, since the actual calls to __init_subclass__ will not receive any
of the config arguments, and will only receive any keyword arguments passed during class initialization
that are not expected keys in ConfigDict. (This is due to the way ModelMetaclass.__new__ works.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Unpack[ConfigDict]
|
Keyword arguments passed to the class definition, which set model_config |
{}
|
Note
You may want to override __pydantic_init_subclass__ instead, which behaves similarly but is called
after the class is fully initialized.
Source code in pydantic/main.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
__iter__
¤
__iter__() -> TupleGenerator
So dict(model) works.
Source code in pydantic/main.py
1229 1230 1231 1232 1233 1234 | |
__pydantic_init_subclass__
classmethod
¤
__pydantic_init_subclass__(**kwargs: Any) -> None
This is intended to behave just like __init_subclass__, but is called by ModelMetaclass
only after basic class initialization is complete. In particular, attributes like model_fields will
be present when this is called, but forward annotations are not guaranteed to be resolved yet,
meaning that creating an instance of the class may fail.
This is necessary because __init_subclass__ will always be called by type.__new__,
and it would require a prohibitively large refactor to the ModelMetaclass to ensure that
type.__new__ was called in such a manner that the class would already be sufficiently initialized.
This will receive the same kwargs that would be passed to the standard __init_subclass__, namely,
any kwargs passed to the class definition that aren't used internally by Pydantic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Any keyword arguments passed to the class definition that aren't used internally by Pydantic. |
{}
|
Note
You may want to override __pydantic_on_complete__()
instead, which is called once the class and its fields are fully initialized and ready for validation.
Source code in pydantic/main.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
__pydantic_on_complete__
classmethod
¤
__pydantic_on_complete__() -> None
This is called once the class and its fields are fully initialized and ready to be used.
This typically happens when the class is created (just before
__pydantic_init_subclass__() is called on the superclass),
except when forward annotations are used that could not immediately be resolved.
In that case, it will be called later, when the model is rebuilt automatically or explicitly using
model_rebuild().
Source code in pydantic/main.py
877 878 879 880 881 882 883 884 885 886 | |
__replace__
¤
__replace__(**changes: Any) -> Self
Source code in pydantic/main.py
1125 1126 | |
__repr__
¤
__repr__() -> str
Source code in pydantic/main.py
1236 1237 | |
__repr_args__
¤
__repr_args__() -> _repr.ReprArgs
Source code in pydantic/main.py
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
__setattr__
¤
__setattr__(name: str, value: Any) -> None
Source code in pydantic/main.py
1028 1029 1030 1031 1032 1033 1034 | |
__setstate__
¤
__setstate__(state: dict[Any, Any]) -> None
Source code in pydantic/main.py
1139 1140 1141 1142 1143 | |
__str__
¤
__str__() -> str
Source code in pydantic/main.py
1274 1275 | |
cli_cmd
¤
cli_cmd()
Source code in src/bioimageio/core/cli.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 | |
construct
classmethod
¤
construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Source code in pydantic/main.py
1477 1478 1479 1480 1481 1482 1483 1484 1485 | |
copy
¤
copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) -> Self
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in pydantic/main.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | |
dict
¤
dict(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> Dict[str, Any]
Source code in pydantic/main.py
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | |
from_orm
classmethod
¤
from_orm(obj: Any) -> Self
Source code in pydantic/main.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
json
¤
json(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
model_computed_fields
classmethod
¤
model_computed_fields() -> dict[str, ComputedFieldInfo]
A mapping of computed field names to their respective ComputedFieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
273 274 275 276 277 278 279 280 281 282 | |
model_construct
classmethod
¤
model_construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Note
model_construct() generally respects the model_config.extra setting on the provided model.
That is, if model_config.extra == 'allow', then all extra passed values are added to the model instance's __dict__
and __pydantic_extra__ fields. If model_config.extra == 'ignore' (the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct(), having model_config.extra == 'forbid' does not result in
an error if extra values are passed, but they will be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
set[str] | None
|
A set of field names that were originally explicitly set during instantiation. If provided,
this is directly used for the |
None
|
|
Any
|
Trusted or pre-validated data dictionary. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
A new instance of the |
Source code in pydantic/main.py
303 304 305 306 307 308 309 310 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
model_copy
¤
Usage Documentation
Returns a copy of the model.
Note
The underlying instance's [__dict__][object.__dict__] attribute is copied. This
might have unexpected side effects if you store anything in it, on top of the model
fields (e.g. the value of [cached properties][functools.cached_property]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, Any] | None
|
Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data. |
None
|
|
bool
|
Set to |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
New model instance. |
Source code in pydantic/main.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
model_dump
¤
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> dict[str, Any]
Usage Documentation
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Literal['json', 'python'] | str
|
The mode in which |
'python'
|
|
IncEx | None
|
A set of fields to include in the output. |
None
|
|
IncEx | None
|
A set of fields to exclude from the output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to use the field's alias in the dictionary key if defined. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representation of the model. |
Source code in pydantic/main.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
model_dump_json
¤
model_dump_json(*, indent: int | None = None, ensure_ascii: bool = False, include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> str
Usage Documentation
Generates a JSON representation of the model using Pydantic's to_json method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
|
bool
|
If |
False
|
|
IncEx | None
|
Field(s) to include in the JSON output. |
None
|
|
IncEx | None
|
Field(s) to exclude from the JSON output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to serialize using field aliases. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representation of the model. |
Source code in pydantic/main.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
model_fields
classmethod
¤
A mapping of field names to their respective FieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
262 263 264 265 266 267 268 269 270 271 | |
model_json_schema
classmethod
¤
model_json_schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema, mode: JsonSchemaMode = 'validation', *, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of') -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to use attribute aliases or not. |
True
|
|
str
|
The reference template. |
DEFAULT_REF_TEMPLATE
|
|
Literal['any_of', 'primitive_type_array']
|
The format to use when combining schemas from unions together. Can be one of:
|
'any_of'
|
|
type[GenerateJsonSchema]
|
To override the logic used to generate the JSON schema, as a subclass of
|
GenerateJsonSchema
|
|
JsonSchemaMode
|
The mode in which to generate the schema. |
'validation'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON schema for the given model class. |
Source code in pydantic/main.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
model_parametrized_name
classmethod
¤
model_parametrized_name(params: tuple[type[Any], ...]) -> str
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
| Type | Description |
|---|---|
str
|
String representing the new class where |
Raises:
| Type | Description |
|---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in pydantic/main.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
model_post_init
¤
model_post_init(context: Any) -> None
Override this method to perform additional initialization after __init__ and model_construct.
This is useful if you want to do some validation that requires the entire model to be initialized.
Source code in pydantic/main.py
612 613 614 615 | |
model_rebuild
classmethod
¤
model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to force the rebuilding of the model schema, defaults to |
False
|
|
bool
|
Whether to raise errors, defaults to |
True
|
|
int
|
The depth level of the parent namespace, defaults to 2. |
2
|
|
MappingNamespace | None
|
The types namespace, defaults to |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
Returns |
Source code in pydantic/main.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
model_validate
classmethod
¤
model_validate(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, from_attributes: bool | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate a pydantic model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
bool | None
|
Whether to extract data from object attributes. |
None
|
|
Any | None
|
Additional context to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the object could not be validated. |
Returns:
| Type | Description |
|---|---|
Self
|
The validated model instance. |
Source code in pydantic/main.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
model_validate_json
classmethod
¤
model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Usage Documentation
Validate the given JSON data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in pydantic/main.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
model_validate_strings
classmethod
¤
model_validate_strings(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate the given object with string data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object containing string data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Source code in pydantic/main.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
parse_file
classmethod
¤
parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
parse_obj
classmethod
¤
parse_obj(obj: Any) -> Self
Source code in pydantic/main.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 | |
parse_raw
classmethod
¤
parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
schema
classmethod
¤
schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE) -> Dict[str, Any]
Source code in pydantic/main.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 | |
schema_json
classmethod
¤
schema_json(*, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
update_forward_refs
classmethod
¤
update_forward_refs(**localns: Any) -> None
Source code in pydantic/main.py
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
validate
classmethod
¤
validate(value: Any) -> Self
Source code in pydantic/main.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 | |
ValidateFormatCmd
¤
ValidateFormatCmd(**data: Any)
Bases: CmdBase, WithSource, WithSummaryLogging
flowchart TD
bioimageio.core.cli.ValidateFormatCmd[ValidateFormatCmd]
bioimageio.core.cli.CmdBase[CmdBase]
bioimageio.core.cli.WithSource[WithSource]
bioimageio.core.cli.WithSummaryLogging[WithSummaryLogging]
bioimageio.core.cli.ArgMixin[ArgMixin]
pydantic.main.BaseModel[BaseModel]
bioimageio.core.cli.CmdBase --> bioimageio.core.cli.ValidateFormatCmd
pydantic.main.BaseModel --> bioimageio.core.cli.CmdBase
bioimageio.core.cli.WithSource --> bioimageio.core.cli.ValidateFormatCmd
bioimageio.core.cli.ArgMixin --> bioimageio.core.cli.WithSource
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
bioimageio.core.cli.WithSummaryLogging --> bioimageio.core.cli.ValidateFormatCmd
bioimageio.core.cli.ArgMixin --> bioimageio.core.cli.WithSummaryLogging
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
click bioimageio.core.cli.ValidateFormatCmd href "" "bioimageio.core.cli.ValidateFormatCmd"
click bioimageio.core.cli.CmdBase href "" "bioimageio.core.cli.CmdBase"
click bioimageio.core.cli.WithSource href "" "bioimageio.core.cli.WithSource"
click bioimageio.core.cli.WithSummaryLogging href "" "bioimageio.core.cli.WithSummaryLogging"
click bioimageio.core.cli.ArgMixin href "" "bioimageio.core.cli.ArgMixin"
click pydantic.main.BaseModel href "" "pydantic.main.BaseModel"
Validate the meta data format of a bioimageio resource.
Raises ValidationError if the input data cannot be
validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
Methods:
| Name | Description |
|---|---|
__class_getitem__ |
|
__copy__ |
Returns a shallow copy of the model. |
__deepcopy__ |
Returns a deep copy of the model. |
__delattr__ |
|
__eq__ |
|
__get_pydantic_core_schema__ |
|
__get_pydantic_json_schema__ |
Hook into generating the model's JSON schema. |
__getattr__ |
|
__getstate__ |
|
__init_subclass__ |
This signature is included purely to help type-checkers check arguments to class declaration, which |
__iter__ |
So |
__pydantic_init_subclass__ |
This is intended to behave just like |
__pydantic_on_complete__ |
This is called once the class and its fields are fully initialized and ready to be used. |
__replace__ |
|
__repr__ |
|
__repr_args__ |
|
__setattr__ |
|
__setstate__ |
|
__str__ |
|
cli_cmd |
|
construct |
|
copy |
Returns a copy of the model. |
dict |
|
from_orm |
|
json |
|
log |
|
model_computed_fields |
A mapping of computed field names to their respective |
model_construct |
Creates a new instance of the |
model_copy |
Usage Documentation |
model_dump |
Usage Documentation |
model_dump_json |
Usage Documentation |
model_fields |
A mapping of field names to their respective |
model_json_schema |
Generates a JSON schema for a model class. |
model_parametrized_name |
Compute the class name for parametrizations of generic classes. |
model_post_init |
Override this method to perform additional initialization after |
model_rebuild |
Try to rebuild the pydantic-core schema for the model. |
model_validate |
Validate a pydantic model instance. |
model_validate_json |
Usage Documentation |
model_validate_strings |
Validate the given object with string data against the Pydantic model. |
parse_file |
|
parse_obj |
|
parse_raw |
|
schema |
|
schema_json |
|
update_forward_refs |
|
validate |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__class_vars__ |
set[str]
|
The names of the class variables defined on the model. |
__fields__ |
dict[str, FieldInfo]
|
|
__fields_set__ |
set[str]
|
|
__pretty__ |
|
|
__private_attributes__ |
Dict[str, ModelPrivateAttr]
|
Metadata about the private attributes of the model. |
__pydantic_complete__ |
bool
|
Whether model building is completed, or if there are still undefined fields. |
__pydantic_computed_fields__ |
Dict[str, ComputedFieldInfo]
|
A dictionary of computed field names and their corresponding |
__pydantic_core_schema__ |
CoreSchema
|
The core schema of the model. |
__pydantic_custom_init__ |
bool
|
Whether the model has a custom |
__pydantic_decorators__ |
_decorators.DecoratorInfos
|
Metadata containing the decorators defined on the model. |
__pydantic_extra__ |
Dict[str, Any] | None
|
A dictionary containing extra values, if |
__pydantic_fields__ |
Dict[str, FieldInfo]
|
A dictionary of field names and their corresponding |
__pydantic_fields_set__ |
set[str]
|
The names of fields explicitly set during instantiation. |
__pydantic_generic_metadata__ |
_generics.PydanticGenericMetadata
|
Metadata for generic models; contains data used for a similar purpose to |
__pydantic_parent_namespace__ |
Dict[str, Any] | None
|
Parent namespace of the model, used for automatic rebuilding of models. |
__pydantic_post_init__ |
None | Literal['model_post_init']
|
The name of the post-init method for the model, if defined. |
__pydantic_private__ |
Dict[str, Any] | None
|
Values of private attributes set on the model instance. |
__pydantic_root_model__ |
bool
|
Whether the model is a |
__pydantic_serializer__ |
SchemaSerializer
|
The |
__pydantic_setattr_handlers__ |
Dict[str, Callable[[BaseModel, str, Any], None]]
|
|
__pydantic_validator__ |
SchemaValidator | PluggableSchemaValidator
|
The |
__repr_name__ |
|
|
__repr_recursion__ |
|
|
__repr_str__ |
|
|
__rich_repr__ |
|
|
__signature__ |
Signature
|
The synthesized |
__slots__ |
|
|
descr |
|
|
descr_id |
str
|
a more user-friendly description id |
model_config |
ConfigDict
|
Configuration for the model, should be a dictionary conforming to |
model_extra |
dict[str, Any] | None
|
Get extra fields set during validation. |
model_fields_set |
set[str]
|
Returns the set of fields that have been explicitly set on this model instance. |
perform_io_checks |
bool
|
Wether or not to perform validations that requires downloading remote files. |
source |
CliPositionalArg[str]
|
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file |
summary |
List[Union[Literal['display'], Path]]
|
Display the validation summary or save it as JSON, Markdown or HTML. |
Source code in pydantic/main.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__class_vars__
class-attribute
¤
__class_vars__: set[str]
The names of the class variables defined on the model.
__private_attributes__
class-attribute
¤
__private_attributes__: Dict[str, ModelPrivateAttr]
Metadata about the private attributes of the model.
__pydantic_complete__
class-attribute
¤
__pydantic_complete__: bool = False
Whether model building is completed, or if there are still undefined fields.
__pydantic_computed_fields__
class-attribute
¤
__pydantic_computed_fields__: Dict[str, ComputedFieldInfo]
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
__pydantic_core_schema__
class-attribute
¤
__pydantic_core_schema__: CoreSchema
The core schema of the model.
__pydantic_custom_init__
class-attribute
¤
__pydantic_custom_init__: bool
Whether the model has a custom __init__ method.
__pydantic_decorators__
class-attribute
¤
__pydantic_decorators__: _decorators.DecoratorInfos = _decorators.DecoratorInfos()
Metadata containing the decorators defined on the model.
This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
__pydantic_extra__
pydantic-field
¤
__pydantic_extra__: Dict[str, Any] | None
A dictionary containing extra values, if extra is set to 'allow'.
__pydantic_fields__
class-attribute
¤
__pydantic_fields__: Dict[str, FieldInfo]
A dictionary of field names and their corresponding FieldInfo objects.
This replaces Model.__fields__ from Pydantic V1.
__pydantic_fields_set__
pydantic-field
¤
__pydantic_fields_set__: set[str]
The names of fields explicitly set during instantiation.
__pydantic_generic_metadata__
class-attribute
¤
__pydantic_generic_metadata__: _generics.PydanticGenericMetadata
Metadata for generic models; contains data used for a similar purpose to args, origin, parameters in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__
class-attribute
¤
__pydantic_parent_namespace__: Dict[str, Any] | None = None
Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__
class-attribute
¤
__pydantic_post_init__: None | Literal['model_post_init']
The name of the post-init method for the model, if defined.
__pydantic_private__
pydantic-field
¤
__pydantic_private__: Dict[str, Any] | None
Values of private attributes set on the model instance.
__pydantic_root_model__
class-attribute
¤
__pydantic_root_model__: bool = False
Whether the model is a RootModel.
__pydantic_serializer__
class-attribute
¤
__pydantic_serializer__: SchemaSerializer
The pydantic-core SchemaSerializer used to dump instances of the model.
__pydantic_setattr_handlers__
class-attribute
¤
__pydantic_setattr_handlers__: Dict[str, Callable[[BaseModel, str, Any], None]]
__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__
__pydantic_validator__
class-attribute
¤
__pydantic_validator__: SchemaValidator | PluggableSchemaValidator
The pydantic-core SchemaValidator used to validate instances of the model.
__signature__
class-attribute
¤
__signature__: Signature
The synthesized __init__ [Signature][inspect.Signature] of the model.
__slots__
pydantic-field
¤
__slots__ = ('__dict__', '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__')
descr_id
property
¤
descr_id: str
a more user-friendly description id (replacing legacy ids with their nicknames)
model_config
class-attribute
¤
model_config: ConfigDict = ConfigDict()
Configuration for the model, should be a dictionary conforming to ConfigDict.
model_extra
property
¤
model_extra: dict[str, Any] | None
Get extra fields set during validation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dictionary of extra fields, or |
model_fields_set
property
¤
model_fields_set: set[str]
Returns the set of fields that have been explicitly set on this model instance.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of strings representing the fields that have been set, i.e. that were not filled from defaults. |
perform_io_checks
class-attribute
instance-attribute
¤
Wether or not to perform validations that requires downloading remote files.
Note: Default value is set by BIOIMAGEIO_PERFORM_IO_CHECKS environment variable.
source
instance-attribute
¤
source: CliPositionalArg[str]
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file or a bioimage.io resource identifier, e.g. 'affable-shark'
summary
class-attribute
instance-attribute
¤
summary: List[Union[Literal['display'], Path]] = Field(default_factory=lambda: ['display'], examples=[Path('summary.md'), Path('bioimageio_summaries/'), ['display', Path('summary.md')]])
Display the validation summary or save it as JSON, Markdown or HTML.
The format is chosen based on the suffix: .json, .md, .html.
If a folder is given (path w/o suffix) the summary is saved in all formats.
Choose/add "display" to render the validation summary to the terminal.
__class_getitem__
¤
__class_getitem__(typevar_values: type[Any] | tuple[type[Any], ...]) -> type[BaseModel] | _forward_ref.PydanticRecursiveRef
Source code in pydantic/main.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
__copy__
¤
__copy__() -> Self
Returns a shallow copy of the model.
Source code in pydantic/main.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
__deepcopy__
¤
__deepcopy__(memo: dict[int, Any] | None = None) -> Self
Returns a deep copy of the model.
Source code in pydantic/main.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
__delattr__
¤
__delattr__(item: str) -> Any
Source code in pydantic/main.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
__eq__
¤
__eq__(other: Any) -> bool
Source code in pydantic/main.py
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
__get_pydantic_core_schema__
classmethod
¤
__get_pydantic_core_schema__(source: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema
Source code in pydantic/main.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
__get_pydantic_json_schema__
classmethod
¤
__get_pydantic_json_schema__(core_schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue
Hook into generating the model's JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CoreSchema
|
A |
required |
|
GetJsonSchemaHandler
|
Call into Pydantic's internal JSON schema generation.
This will raise a |
required |
Returns:
| Type | Description |
|---|---|
JsonSchemaValue
|
A JSON schema, as a Python object. |
Source code in pydantic/main.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
__getattr__
¤
__getattr__(item: str) -> Any
Source code in pydantic/main.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
__getstate__
¤
__getstate__() -> dict[Any, Any]
Source code in pydantic/main.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
__init_subclass__
¤
__init_subclass__(**kwargs: Unpack[ConfigDict])
This signature is included purely to help type-checkers check arguments to class declaration, which provides a way to conveniently set model_config key/value pairs.
from pydantic import BaseModel
class MyModel(BaseModel, extra='allow'): ...
However, this may be deceiving, since the actual calls to __init_subclass__ will not receive any
of the config arguments, and will only receive any keyword arguments passed during class initialization
that are not expected keys in ConfigDict. (This is due to the way ModelMetaclass.__new__ works.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Unpack[ConfigDict]
|
Keyword arguments passed to the class definition, which set model_config |
{}
|
Note
You may want to override __pydantic_init_subclass__ instead, which behaves similarly but is called
after the class is fully initialized.
Source code in pydantic/main.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
__iter__
¤
__iter__() -> TupleGenerator
So dict(model) works.
Source code in pydantic/main.py
1229 1230 1231 1232 1233 1234 | |
__pydantic_init_subclass__
classmethod
¤
__pydantic_init_subclass__(**kwargs: Any) -> None
This is intended to behave just like __init_subclass__, but is called by ModelMetaclass
only after basic class initialization is complete. In particular, attributes like model_fields will
be present when this is called, but forward annotations are not guaranteed to be resolved yet,
meaning that creating an instance of the class may fail.
This is necessary because __init_subclass__ will always be called by type.__new__,
and it would require a prohibitively large refactor to the ModelMetaclass to ensure that
type.__new__ was called in such a manner that the class would already be sufficiently initialized.
This will receive the same kwargs that would be passed to the standard __init_subclass__, namely,
any kwargs passed to the class definition that aren't used internally by Pydantic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Any keyword arguments passed to the class definition that aren't used internally by Pydantic. |
{}
|
Note
You may want to override __pydantic_on_complete__()
instead, which is called once the class and its fields are fully initialized and ready for validation.
Source code in pydantic/main.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
__pydantic_on_complete__
classmethod
¤
__pydantic_on_complete__() -> None
This is called once the class and its fields are fully initialized and ready to be used.
This typically happens when the class is created (just before
__pydantic_init_subclass__() is called on the superclass),
except when forward annotations are used that could not immediately be resolved.
In that case, it will be called later, when the model is rebuilt automatically or explicitly using
model_rebuild().
Source code in pydantic/main.py
877 878 879 880 881 882 883 884 885 886 | |
__replace__
¤
__replace__(**changes: Any) -> Self
Source code in pydantic/main.py
1125 1126 | |
__repr__
¤
__repr__() -> str
Source code in pydantic/main.py
1236 1237 | |
__repr_args__
¤
__repr_args__() -> _repr.ReprArgs
Source code in pydantic/main.py
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
__setattr__
¤
__setattr__(name: str, value: Any) -> None
Source code in pydantic/main.py
1028 1029 1030 1031 1032 1033 1034 | |
__setstate__
¤
__setstate__(state: dict[Any, Any]) -> None
Source code in pydantic/main.py
1139 1140 1141 1142 1143 | |
__str__
¤
__str__() -> str
Source code in pydantic/main.py
1274 1275 | |
cli_cmd
¤
cli_cmd()
Source code in src/bioimageio/core/cli.py
177 178 179 180 181 182 183 | |
construct
classmethod
¤
construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Source code in pydantic/main.py
1477 1478 1479 1480 1481 1482 1483 1484 1485 | |
copy
¤
copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) -> Self
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in pydantic/main.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | |
dict
¤
dict(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> Dict[str, Any]
Source code in pydantic/main.py
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | |
from_orm
classmethod
¤
from_orm(obj: Any) -> Self
Source code in pydantic/main.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
json
¤
json(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
log
¤
log(descr: Union[ResourceDescr, InvalidDescr])
Source code in src/bioimageio/core/cli.py
131 132 | |
model_computed_fields
classmethod
¤
model_computed_fields() -> dict[str, ComputedFieldInfo]
A mapping of computed field names to their respective ComputedFieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
273 274 275 276 277 278 279 280 281 282 | |
model_construct
classmethod
¤
model_construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Note
model_construct() generally respects the model_config.extra setting on the provided model.
That is, if model_config.extra == 'allow', then all extra passed values are added to the model instance's __dict__
and __pydantic_extra__ fields. If model_config.extra == 'ignore' (the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct(), having model_config.extra == 'forbid' does not result in
an error if extra values are passed, but they will be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
set[str] | None
|
A set of field names that were originally explicitly set during instantiation. If provided,
this is directly used for the |
None
|
|
Any
|
Trusted or pre-validated data dictionary. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
A new instance of the |
Source code in pydantic/main.py
303 304 305 306 307 308 309 310 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
model_copy
¤
Usage Documentation
Returns a copy of the model.
Note
The underlying instance's [__dict__][object.__dict__] attribute is copied. This
might have unexpected side effects if you store anything in it, on top of the model
fields (e.g. the value of [cached properties][functools.cached_property]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, Any] | None
|
Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data. |
None
|
|
bool
|
Set to |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
New model instance. |
Source code in pydantic/main.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
model_dump
¤
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> dict[str, Any]
Usage Documentation
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Literal['json', 'python'] | str
|
The mode in which |
'python'
|
|
IncEx | None
|
A set of fields to include in the output. |
None
|
|
IncEx | None
|
A set of fields to exclude from the output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to use the field's alias in the dictionary key if defined. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representation of the model. |
Source code in pydantic/main.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
model_dump_json
¤
model_dump_json(*, indent: int | None = None, ensure_ascii: bool = False, include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> str
Usage Documentation
Generates a JSON representation of the model using Pydantic's to_json method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
|
bool
|
If |
False
|
|
IncEx | None
|
Field(s) to include in the JSON output. |
None
|
|
IncEx | None
|
Field(s) to exclude from the JSON output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to serialize using field aliases. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representation of the model. |
Source code in pydantic/main.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
model_fields
classmethod
¤
A mapping of field names to their respective FieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
262 263 264 265 266 267 268 269 270 271 | |
model_json_schema
classmethod
¤
model_json_schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema, mode: JsonSchemaMode = 'validation', *, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of') -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to use attribute aliases or not. |
True
|
|
str
|
The reference template. |
DEFAULT_REF_TEMPLATE
|
|
Literal['any_of', 'primitive_type_array']
|
The format to use when combining schemas from unions together. Can be one of:
|
'any_of'
|
|
type[GenerateJsonSchema]
|
To override the logic used to generate the JSON schema, as a subclass of
|
GenerateJsonSchema
|
|
JsonSchemaMode
|
The mode in which to generate the schema. |
'validation'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON schema for the given model class. |
Source code in pydantic/main.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
model_parametrized_name
classmethod
¤
model_parametrized_name(params: tuple[type[Any], ...]) -> str
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
| Type | Description |
|---|---|
str
|
String representing the new class where |
Raises:
| Type | Description |
|---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in pydantic/main.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
model_post_init
¤
model_post_init(context: Any) -> None
Override this method to perform additional initialization after __init__ and model_construct.
This is useful if you want to do some validation that requires the entire model to be initialized.
Source code in pydantic/main.py
612 613 614 615 | |
model_rebuild
classmethod
¤
model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to force the rebuilding of the model schema, defaults to |
False
|
|
bool
|
Whether to raise errors, defaults to |
True
|
|
int
|
The depth level of the parent namespace, defaults to 2. |
2
|
|
MappingNamespace | None
|
The types namespace, defaults to |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
Returns |
Source code in pydantic/main.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
model_validate
classmethod
¤
model_validate(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, from_attributes: bool | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate a pydantic model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
bool | None
|
Whether to extract data from object attributes. |
None
|
|
Any | None
|
Additional context to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the object could not be validated. |
Returns:
| Type | Description |
|---|---|
Self
|
The validated model instance. |
Source code in pydantic/main.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
model_validate_json
classmethod
¤
model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Usage Documentation
Validate the given JSON data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in pydantic/main.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
model_validate_strings
classmethod
¤
model_validate_strings(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate the given object with string data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object containing string data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Source code in pydantic/main.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
parse_file
classmethod
¤
parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
parse_obj
classmethod
¤
parse_obj(obj: Any) -> Self
Source code in pydantic/main.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 | |
parse_raw
classmethod
¤
parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
schema
classmethod
¤
schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE) -> Dict[str, Any]
Source code in pydantic/main.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 | |
schema_json
classmethod
¤
schema_json(*, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
update_forward_refs
classmethod
¤
update_forward_refs(**localns: Any) -> None
Source code in pydantic/main.py
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
validate
classmethod
¤
validate(value: Any) -> Self
Source code in pydantic/main.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 | |
WithSource
¤
WithSource(**data: Any)
Bases: ArgMixin
flowchart TD
bioimageio.core.cli.WithSource[WithSource]
bioimageio.core.cli.ArgMixin[ArgMixin]
pydantic.main.BaseModel[BaseModel]
bioimageio.core.cli.ArgMixin --> bioimageio.core.cli.WithSource
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
click bioimageio.core.cli.WithSource href "" "bioimageio.core.cli.WithSource"
click bioimageio.core.cli.ArgMixin href "" "bioimageio.core.cli.ArgMixin"
click pydantic.main.BaseModel href "" "pydantic.main.BaseModel"
Raises ValidationError if the input data cannot be
validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
-
API Reference
cli
Methods:
| Name | Description |
|---|---|
__class_getitem__ |
|
__copy__ |
Returns a shallow copy of the model. |
__deepcopy__ |
Returns a deep copy of the model. |
__delattr__ |
|
__eq__ |
|
__get_pydantic_core_schema__ |
|
__get_pydantic_json_schema__ |
Hook into generating the model's JSON schema. |
__getattr__ |
|
__getstate__ |
|
__init_subclass__ |
This signature is included purely to help type-checkers check arguments to class declaration, which |
__iter__ |
So |
__pydantic_init_subclass__ |
This is intended to behave just like |
__pydantic_on_complete__ |
This is called once the class and its fields are fully initialized and ready to be used. |
__replace__ |
|
__repr__ |
|
__repr_args__ |
|
__setattr__ |
|
__setstate__ |
|
__str__ |
|
construct |
|
copy |
Returns a copy of the model. |
dict |
|
from_orm |
|
json |
|
model_computed_fields |
A mapping of computed field names to their respective |
model_construct |
Creates a new instance of the |
model_copy |
Usage Documentation |
model_dump |
Usage Documentation |
model_dump_json |
Usage Documentation |
model_fields |
A mapping of field names to their respective |
model_json_schema |
Generates a JSON schema for a model class. |
model_parametrized_name |
Compute the class name for parametrizations of generic classes. |
model_post_init |
Override this method to perform additional initialization after |
model_rebuild |
Try to rebuild the pydantic-core schema for the model. |
model_validate |
Validate a pydantic model instance. |
model_validate_json |
Usage Documentation |
model_validate_strings |
Validate the given object with string data against the Pydantic model. |
parse_file |
|
parse_obj |
|
parse_raw |
|
schema |
|
schema_json |
|
update_forward_refs |
|
validate |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__class_vars__ |
set[str]
|
The names of the class variables defined on the model. |
__fields__ |
dict[str, FieldInfo]
|
|
__fields_set__ |
set[str]
|
|
__pretty__ |
|
|
__private_attributes__ |
Dict[str, ModelPrivateAttr]
|
Metadata about the private attributes of the model. |
__pydantic_complete__ |
bool
|
Whether model building is completed, or if there are still undefined fields. |
__pydantic_computed_fields__ |
Dict[str, ComputedFieldInfo]
|
A dictionary of computed field names and their corresponding |
__pydantic_core_schema__ |
CoreSchema
|
The core schema of the model. |
__pydantic_custom_init__ |
bool
|
Whether the model has a custom |
__pydantic_decorators__ |
_decorators.DecoratorInfos
|
Metadata containing the decorators defined on the model. |
__pydantic_extra__ |
Dict[str, Any] | None
|
A dictionary containing extra values, if |
__pydantic_fields__ |
Dict[str, FieldInfo]
|
A dictionary of field names and their corresponding |
__pydantic_fields_set__ |
set[str]
|
The names of fields explicitly set during instantiation. |
__pydantic_generic_metadata__ |
_generics.PydanticGenericMetadata
|
Metadata for generic models; contains data used for a similar purpose to |
__pydantic_parent_namespace__ |
Dict[str, Any] | None
|
Parent namespace of the model, used for automatic rebuilding of models. |
__pydantic_post_init__ |
None | Literal['model_post_init']
|
The name of the post-init method for the model, if defined. |
__pydantic_private__ |
Dict[str, Any] | None
|
Values of private attributes set on the model instance. |
__pydantic_root_model__ |
bool
|
Whether the model is a |
__pydantic_serializer__ |
SchemaSerializer
|
The |
__pydantic_setattr_handlers__ |
Dict[str, Callable[[BaseModel, str, Any], None]]
|
|
__pydantic_validator__ |
SchemaValidator | PluggableSchemaValidator
|
The |
__repr_name__ |
|
|
__repr_recursion__ |
|
|
__repr_str__ |
|
|
__rich_repr__ |
|
|
__signature__ |
Signature
|
The synthesized |
__slots__ |
|
|
descr |
|
|
descr_id |
str
|
a more user-friendly description id |
model_config |
ConfigDict
|
Configuration for the model, should be a dictionary conforming to |
model_extra |
dict[str, Any] | None
|
Get extra fields set during validation. |
model_fields_set |
set[str]
|
Returns the set of fields that have been explicitly set on this model instance. |
source |
CliPositionalArg[str]
|
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file |
Source code in pydantic/main.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__class_vars__
class-attribute
¤
__class_vars__: set[str]
The names of the class variables defined on the model.
__private_attributes__
class-attribute
¤
__private_attributes__: Dict[str, ModelPrivateAttr]
Metadata about the private attributes of the model.
__pydantic_complete__
class-attribute
¤
__pydantic_complete__: bool = False
Whether model building is completed, or if there are still undefined fields.
__pydantic_computed_fields__
class-attribute
¤
__pydantic_computed_fields__: Dict[str, ComputedFieldInfo]
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
__pydantic_core_schema__
class-attribute
¤
__pydantic_core_schema__: CoreSchema
The core schema of the model.
__pydantic_custom_init__
class-attribute
¤
__pydantic_custom_init__: bool
Whether the model has a custom __init__ method.
__pydantic_decorators__
class-attribute
¤
__pydantic_decorators__: _decorators.DecoratorInfos = _decorators.DecoratorInfos()
Metadata containing the decorators defined on the model.
This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
__pydantic_extra__
pydantic-field
¤
__pydantic_extra__: Dict[str, Any] | None
A dictionary containing extra values, if extra is set to 'allow'.
__pydantic_fields__
class-attribute
¤
__pydantic_fields__: Dict[str, FieldInfo]
A dictionary of field names and their corresponding FieldInfo objects.
This replaces Model.__fields__ from Pydantic V1.
__pydantic_fields_set__
pydantic-field
¤
__pydantic_fields_set__: set[str]
The names of fields explicitly set during instantiation.
__pydantic_generic_metadata__
class-attribute
¤
__pydantic_generic_metadata__: _generics.PydanticGenericMetadata
Metadata for generic models; contains data used for a similar purpose to args, origin, parameters in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__
class-attribute
¤
__pydantic_parent_namespace__: Dict[str, Any] | None = None
Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__
class-attribute
¤
__pydantic_post_init__: None | Literal['model_post_init']
The name of the post-init method for the model, if defined.
__pydantic_private__
pydantic-field
¤
__pydantic_private__: Dict[str, Any] | None
Values of private attributes set on the model instance.
__pydantic_root_model__
class-attribute
¤
__pydantic_root_model__: bool = False
Whether the model is a RootModel.
__pydantic_serializer__
class-attribute
¤
__pydantic_serializer__: SchemaSerializer
The pydantic-core SchemaSerializer used to dump instances of the model.
__pydantic_setattr_handlers__
class-attribute
¤
__pydantic_setattr_handlers__: Dict[str, Callable[[BaseModel, str, Any], None]]
__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__
__pydantic_validator__
class-attribute
¤
__pydantic_validator__: SchemaValidator | PluggableSchemaValidator
The pydantic-core SchemaValidator used to validate instances of the model.
__signature__
class-attribute
¤
__signature__: Signature
The synthesized __init__ [Signature][inspect.Signature] of the model.
__slots__
pydantic-field
¤
__slots__ = ('__dict__', '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__')
descr_id
property
¤
descr_id: str
a more user-friendly description id (replacing legacy ids with their nicknames)
model_config
class-attribute
¤
model_config: ConfigDict = ConfigDict()
Configuration for the model, should be a dictionary conforming to ConfigDict.
model_extra
property
¤
model_extra: dict[str, Any] | None
Get extra fields set during validation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dictionary of extra fields, or |
model_fields_set
property
¤
model_fields_set: set[str]
Returns the set of fields that have been explicitly set on this model instance.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of strings representing the fields that have been set, i.e. that were not filled from defaults. |
source
instance-attribute
¤
source: CliPositionalArg[str]
Url/path to a (folder with a) bioimageio.yaml/rdf.yaml file or a bioimage.io resource identifier, e.g. 'affable-shark'
__class_getitem__
¤
__class_getitem__(typevar_values: type[Any] | tuple[type[Any], ...]) -> type[BaseModel] | _forward_ref.PydanticRecursiveRef
Source code in pydantic/main.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
__copy__
¤
__copy__() -> Self
Returns a shallow copy of the model.
Source code in pydantic/main.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
__deepcopy__
¤
__deepcopy__(memo: dict[int, Any] | None = None) -> Self
Returns a deep copy of the model.
Source code in pydantic/main.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
__delattr__
¤
__delattr__(item: str) -> Any
Source code in pydantic/main.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
__eq__
¤
__eq__(other: Any) -> bool
Source code in pydantic/main.py
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
__get_pydantic_core_schema__
classmethod
¤
__get_pydantic_core_schema__(source: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema
Source code in pydantic/main.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
__get_pydantic_json_schema__
classmethod
¤
__get_pydantic_json_schema__(core_schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue
Hook into generating the model's JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CoreSchema
|
A |
required |
|
GetJsonSchemaHandler
|
Call into Pydantic's internal JSON schema generation.
This will raise a |
required |
Returns:
| Type | Description |
|---|---|
JsonSchemaValue
|
A JSON schema, as a Python object. |
Source code in pydantic/main.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
__getattr__
¤
__getattr__(item: str) -> Any
Source code in pydantic/main.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
__getstate__
¤
__getstate__() -> dict[Any, Any]
Source code in pydantic/main.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
__init_subclass__
¤
__init_subclass__(**kwargs: Unpack[ConfigDict])
This signature is included purely to help type-checkers check arguments to class declaration, which provides a way to conveniently set model_config key/value pairs.
from pydantic import BaseModel
class MyModel(BaseModel, extra='allow'): ...
However, this may be deceiving, since the actual calls to __init_subclass__ will not receive any
of the config arguments, and will only receive any keyword arguments passed during class initialization
that are not expected keys in ConfigDict. (This is due to the way ModelMetaclass.__new__ works.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Unpack[ConfigDict]
|
Keyword arguments passed to the class definition, which set model_config |
{}
|
Note
You may want to override __pydantic_init_subclass__ instead, which behaves similarly but is called
after the class is fully initialized.
Source code in pydantic/main.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
__iter__
¤
__iter__() -> TupleGenerator
So dict(model) works.
Source code in pydantic/main.py
1229 1230 1231 1232 1233 1234 | |
__pydantic_init_subclass__
classmethod
¤
__pydantic_init_subclass__(**kwargs: Any) -> None
This is intended to behave just like __init_subclass__, but is called by ModelMetaclass
only after basic class initialization is complete. In particular, attributes like model_fields will
be present when this is called, but forward annotations are not guaranteed to be resolved yet,
meaning that creating an instance of the class may fail.
This is necessary because __init_subclass__ will always be called by type.__new__,
and it would require a prohibitively large refactor to the ModelMetaclass to ensure that
type.__new__ was called in such a manner that the class would already be sufficiently initialized.
This will receive the same kwargs that would be passed to the standard __init_subclass__, namely,
any kwargs passed to the class definition that aren't used internally by Pydantic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Any keyword arguments passed to the class definition that aren't used internally by Pydantic. |
{}
|
Note
You may want to override __pydantic_on_complete__()
instead, which is called once the class and its fields are fully initialized and ready for validation.
Source code in pydantic/main.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
__pydantic_on_complete__
classmethod
¤
__pydantic_on_complete__() -> None
This is called once the class and its fields are fully initialized and ready to be used.
This typically happens when the class is created (just before
__pydantic_init_subclass__() is called on the superclass),
except when forward annotations are used that could not immediately be resolved.
In that case, it will be called later, when the model is rebuilt automatically or explicitly using
model_rebuild().
Source code in pydantic/main.py
877 878 879 880 881 882 883 884 885 886 | |
__replace__
¤
__replace__(**changes: Any) -> Self
Source code in pydantic/main.py
1125 1126 | |
__repr__
¤
__repr__() -> str
Source code in pydantic/main.py
1236 1237 | |
__repr_args__
¤
__repr_args__() -> _repr.ReprArgs
Source code in pydantic/main.py
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
__setattr__
¤
__setattr__(name: str, value: Any) -> None
Source code in pydantic/main.py
1028 1029 1030 1031 1032 1033 1034 | |
__setstate__
¤
__setstate__(state: dict[Any, Any]) -> None
Source code in pydantic/main.py
1139 1140 1141 1142 1143 | |
__str__
¤
__str__() -> str
Source code in pydantic/main.py
1274 1275 | |
construct
classmethod
¤
construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Source code in pydantic/main.py
1477 1478 1479 1480 1481 1482 1483 1484 1485 | |
copy
¤
copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) -> Self
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in pydantic/main.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | |
dict
¤
dict(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> Dict[str, Any]
Source code in pydantic/main.py
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | |
from_orm
classmethod
¤
from_orm(obj: Any) -> Self
Source code in pydantic/main.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
json
¤
json(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
model_computed_fields
classmethod
¤
model_computed_fields() -> dict[str, ComputedFieldInfo]
A mapping of computed field names to their respective ComputedFieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
273 274 275 276 277 278 279 280 281 282 | |
model_construct
classmethod
¤
model_construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Note
model_construct() generally respects the model_config.extra setting on the provided model.
That is, if model_config.extra == 'allow', then all extra passed values are added to the model instance's __dict__
and __pydantic_extra__ fields. If model_config.extra == 'ignore' (the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct(), having model_config.extra == 'forbid' does not result in
an error if extra values are passed, but they will be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
set[str] | None
|
A set of field names that were originally explicitly set during instantiation. If provided,
this is directly used for the |
None
|
|
Any
|
Trusted or pre-validated data dictionary. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
A new instance of the |
Source code in pydantic/main.py
303 304 305 306 307 308 309 310 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
model_copy
¤
Usage Documentation
Returns a copy of the model.
Note
The underlying instance's [__dict__][object.__dict__] attribute is copied. This
might have unexpected side effects if you store anything in it, on top of the model
fields (e.g. the value of [cached properties][functools.cached_property]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, Any] | None
|
Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data. |
None
|
|
bool
|
Set to |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
New model instance. |
Source code in pydantic/main.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
model_dump
¤
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> dict[str, Any]
Usage Documentation
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Literal['json', 'python'] | str
|
The mode in which |
'python'
|
|
IncEx | None
|
A set of fields to include in the output. |
None
|
|
IncEx | None
|
A set of fields to exclude from the output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to use the field's alias in the dictionary key if defined. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representation of the model. |
Source code in pydantic/main.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
model_dump_json
¤
model_dump_json(*, indent: int | None = None, ensure_ascii: bool = False, include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> str
Usage Documentation
Generates a JSON representation of the model using Pydantic's to_json method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
|
bool
|
If |
False
|
|
IncEx | None
|
Field(s) to include in the JSON output. |
None
|
|
IncEx | None
|
Field(s) to exclude from the JSON output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to serialize using field aliases. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representation of the model. |
Source code in pydantic/main.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
model_fields
classmethod
¤
A mapping of field names to their respective FieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
262 263 264 265 266 267 268 269 270 271 | |
model_json_schema
classmethod
¤
model_json_schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema, mode: JsonSchemaMode = 'validation', *, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of') -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to use attribute aliases or not. |
True
|
|
str
|
The reference template. |
DEFAULT_REF_TEMPLATE
|
|
Literal['any_of', 'primitive_type_array']
|
The format to use when combining schemas from unions together. Can be one of:
|
'any_of'
|
|
type[GenerateJsonSchema]
|
To override the logic used to generate the JSON schema, as a subclass of
|
GenerateJsonSchema
|
|
JsonSchemaMode
|
The mode in which to generate the schema. |
'validation'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON schema for the given model class. |
Source code in pydantic/main.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
model_parametrized_name
classmethod
¤
model_parametrized_name(params: tuple[type[Any], ...]) -> str
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
| Type | Description |
|---|---|
str
|
String representing the new class where |
Raises:
| Type | Description |
|---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in pydantic/main.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
model_post_init
¤
model_post_init(context: Any) -> None
Override this method to perform additional initialization after __init__ and model_construct.
This is useful if you want to do some validation that requires the entire model to be initialized.
Source code in pydantic/main.py
612 613 614 615 | |
model_rebuild
classmethod
¤
model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to force the rebuilding of the model schema, defaults to |
False
|
|
bool
|
Whether to raise errors, defaults to |
True
|
|
int
|
The depth level of the parent namespace, defaults to 2. |
2
|
|
MappingNamespace | None
|
The types namespace, defaults to |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
Returns |
Source code in pydantic/main.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
model_validate
classmethod
¤
model_validate(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, from_attributes: bool | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate a pydantic model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
bool | None
|
Whether to extract data from object attributes. |
None
|
|
Any | None
|
Additional context to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the object could not be validated. |
Returns:
| Type | Description |
|---|---|
Self
|
The validated model instance. |
Source code in pydantic/main.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
model_validate_json
classmethod
¤
model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Usage Documentation
Validate the given JSON data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in pydantic/main.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
model_validate_strings
classmethod
¤
model_validate_strings(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate the given object with string data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object containing string data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Source code in pydantic/main.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
parse_file
classmethod
¤
parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
parse_obj
classmethod
¤
parse_obj(obj: Any) -> Self
Source code in pydantic/main.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 | |
parse_raw
classmethod
¤
parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
schema
classmethod
¤
schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE) -> Dict[str, Any]
Source code in pydantic/main.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 | |
schema_json
classmethod
¤
schema_json(*, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
update_forward_refs
classmethod
¤
update_forward_refs(**localns: Any) -> None
Source code in pydantic/main.py
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
validate
classmethod
¤
validate(value: Any) -> Self
Source code in pydantic/main.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 | |
WithSummaryLogging
¤
WithSummaryLogging(**data: Any)
Bases: ArgMixin
flowchart TD
bioimageio.core.cli.WithSummaryLogging[WithSummaryLogging]
bioimageio.core.cli.ArgMixin[ArgMixin]
pydantic.main.BaseModel[BaseModel]
bioimageio.core.cli.ArgMixin --> bioimageio.core.cli.WithSummaryLogging
pydantic.main.BaseModel --> bioimageio.core.cli.ArgMixin
click bioimageio.core.cli.WithSummaryLogging href "" "bioimageio.core.cli.WithSummaryLogging"
click bioimageio.core.cli.ArgMixin href "" "bioimageio.core.cli.ArgMixin"
click pydantic.main.BaseModel href "" "pydantic.main.BaseModel"
Raises ValidationError if the input data cannot be
validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
-
API Reference
cli
Methods:
| Name | Description |
|---|---|
__class_getitem__ |
|
__copy__ |
Returns a shallow copy of the model. |
__deepcopy__ |
Returns a deep copy of the model. |
__delattr__ |
|
__eq__ |
|
__get_pydantic_core_schema__ |
|
__get_pydantic_json_schema__ |
Hook into generating the model's JSON schema. |
__getattr__ |
|
__getstate__ |
|
__init_subclass__ |
This signature is included purely to help type-checkers check arguments to class declaration, which |
__iter__ |
So |
__pydantic_init_subclass__ |
This is intended to behave just like |
__pydantic_on_complete__ |
This is called once the class and its fields are fully initialized and ready to be used. |
__replace__ |
|
__repr__ |
|
__repr_args__ |
|
__setattr__ |
|
__setstate__ |
|
__str__ |
|
construct |
|
copy |
Returns a copy of the model. |
dict |
|
from_orm |
|
json |
|
log |
|
model_computed_fields |
A mapping of computed field names to their respective |
model_construct |
Creates a new instance of the |
model_copy |
Usage Documentation |
model_dump |
Usage Documentation |
model_dump_json |
Usage Documentation |
model_fields |
A mapping of field names to their respective |
model_json_schema |
Generates a JSON schema for a model class. |
model_parametrized_name |
Compute the class name for parametrizations of generic classes. |
model_post_init |
Override this method to perform additional initialization after |
model_rebuild |
Try to rebuild the pydantic-core schema for the model. |
model_validate |
Validate a pydantic model instance. |
model_validate_json |
Usage Documentation |
model_validate_strings |
Validate the given object with string data against the Pydantic model. |
parse_file |
|
parse_obj |
|
parse_raw |
|
schema |
|
schema_json |
|
update_forward_refs |
|
validate |
|
Attributes:
| Name | Type | Description |
|---|---|---|
__class_vars__ |
set[str]
|
The names of the class variables defined on the model. |
__fields__ |
dict[str, FieldInfo]
|
|
__fields_set__ |
set[str]
|
|
__pretty__ |
|
|
__private_attributes__ |
Dict[str, ModelPrivateAttr]
|
Metadata about the private attributes of the model. |
__pydantic_complete__ |
bool
|
Whether model building is completed, or if there are still undefined fields. |
__pydantic_computed_fields__ |
Dict[str, ComputedFieldInfo]
|
A dictionary of computed field names and their corresponding |
__pydantic_core_schema__ |
CoreSchema
|
The core schema of the model. |
__pydantic_custom_init__ |
bool
|
Whether the model has a custom |
__pydantic_decorators__ |
_decorators.DecoratorInfos
|
Metadata containing the decorators defined on the model. |
__pydantic_extra__ |
Dict[str, Any] | None
|
A dictionary containing extra values, if |
__pydantic_fields__ |
Dict[str, FieldInfo]
|
A dictionary of field names and their corresponding |
__pydantic_fields_set__ |
set[str]
|
The names of fields explicitly set during instantiation. |
__pydantic_generic_metadata__ |
_generics.PydanticGenericMetadata
|
Metadata for generic models; contains data used for a similar purpose to |
__pydantic_parent_namespace__ |
Dict[str, Any] | None
|
Parent namespace of the model, used for automatic rebuilding of models. |
__pydantic_post_init__ |
None | Literal['model_post_init']
|
The name of the post-init method for the model, if defined. |
__pydantic_private__ |
Dict[str, Any] | None
|
Values of private attributes set on the model instance. |
__pydantic_root_model__ |
bool
|
Whether the model is a |
__pydantic_serializer__ |
SchemaSerializer
|
The |
__pydantic_setattr_handlers__ |
Dict[str, Callable[[BaseModel, str, Any], None]]
|
|
__pydantic_validator__ |
SchemaValidator | PluggableSchemaValidator
|
The |
__repr_name__ |
|
|
__repr_recursion__ |
|
|
__repr_str__ |
|
|
__rich_repr__ |
|
|
__signature__ |
Signature
|
The synthesized |
__slots__ |
|
|
model_config |
ConfigDict
|
Configuration for the model, should be a dictionary conforming to |
model_extra |
dict[str, Any] | None
|
Get extra fields set during validation. |
model_fields_set |
set[str]
|
Returns the set of fields that have been explicitly set on this model instance. |
summary |
List[Union[Literal['display'], Path]]
|
Display the validation summary or save it as JSON, Markdown or HTML. |
Source code in pydantic/main.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
__class_vars__
class-attribute
¤
__class_vars__: set[str]
The names of the class variables defined on the model.
__private_attributes__
class-attribute
¤
__private_attributes__: Dict[str, ModelPrivateAttr]
Metadata about the private attributes of the model.
__pydantic_complete__
class-attribute
¤
__pydantic_complete__: bool = False
Whether model building is completed, or if there are still undefined fields.
__pydantic_computed_fields__
class-attribute
¤
__pydantic_computed_fields__: Dict[str, ComputedFieldInfo]
A dictionary of computed field names and their corresponding ComputedFieldInfo objects.
__pydantic_core_schema__
class-attribute
¤
__pydantic_core_schema__: CoreSchema
The core schema of the model.
__pydantic_custom_init__
class-attribute
¤
__pydantic_custom_init__: bool
Whether the model has a custom __init__ method.
__pydantic_decorators__
class-attribute
¤
__pydantic_decorators__: _decorators.DecoratorInfos = _decorators.DecoratorInfos()
Metadata containing the decorators defined on the model.
This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
__pydantic_extra__
pydantic-field
¤
__pydantic_extra__: Dict[str, Any] | None
A dictionary containing extra values, if extra is set to 'allow'.
__pydantic_fields__
class-attribute
¤
__pydantic_fields__: Dict[str, FieldInfo]
A dictionary of field names and their corresponding FieldInfo objects.
This replaces Model.__fields__ from Pydantic V1.
__pydantic_fields_set__
pydantic-field
¤
__pydantic_fields_set__: set[str]
The names of fields explicitly set during instantiation.
__pydantic_generic_metadata__
class-attribute
¤
__pydantic_generic_metadata__: _generics.PydanticGenericMetadata
Metadata for generic models; contains data used for a similar purpose to args, origin, parameters in typing-module generics. May eventually be replaced by these.
__pydantic_parent_namespace__
class-attribute
¤
__pydantic_parent_namespace__: Dict[str, Any] | None = None
Parent namespace of the model, used for automatic rebuilding of models.
__pydantic_post_init__
class-attribute
¤
__pydantic_post_init__: None | Literal['model_post_init']
The name of the post-init method for the model, if defined.
__pydantic_private__
pydantic-field
¤
__pydantic_private__: Dict[str, Any] | None
Values of private attributes set on the model instance.
__pydantic_root_model__
class-attribute
¤
__pydantic_root_model__: bool = False
Whether the model is a RootModel.
__pydantic_serializer__
class-attribute
¤
__pydantic_serializer__: SchemaSerializer
The pydantic-core SchemaSerializer used to dump instances of the model.
__pydantic_setattr_handlers__
class-attribute
¤
__pydantic_setattr_handlers__: Dict[str, Callable[[BaseModel, str, Any], None]]
__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__
__pydantic_validator__
class-attribute
¤
__pydantic_validator__: SchemaValidator | PluggableSchemaValidator
The pydantic-core SchemaValidator used to validate instances of the model.
__signature__
class-attribute
¤
__signature__: Signature
The synthesized __init__ [Signature][inspect.Signature] of the model.
__slots__
pydantic-field
¤
__slots__ = ('__dict__', '__pydantic_fields_set__', '__pydantic_extra__', '__pydantic_private__')
model_config
class-attribute
¤
model_config: ConfigDict = ConfigDict()
Configuration for the model, should be a dictionary conforming to ConfigDict.
model_extra
property
¤
model_extra: dict[str, Any] | None
Get extra fields set during validation.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
A dictionary of extra fields, or |
model_fields_set
property
¤
model_fields_set: set[str]
Returns the set of fields that have been explicitly set on this model instance.
Returns:
| Type | Description |
|---|---|
set[str]
|
A set of strings representing the fields that have been set, i.e. that were not filled from defaults. |
summary
class-attribute
instance-attribute
¤
summary: List[Union[Literal['display'], Path]] = Field(default_factory=lambda: ['display'], examples=[Path('summary.md'), Path('bioimageio_summaries/'), ['display', Path('summary.md')]])
Display the validation summary or save it as JSON, Markdown or HTML.
The format is chosen based on the suffix: .json, .md, .html.
If a folder is given (path w/o suffix) the summary is saved in all formats.
Choose/add "display" to render the validation summary to the terminal.
__class_getitem__
¤
__class_getitem__(typevar_values: type[Any] | tuple[type[Any], ...]) -> type[BaseModel] | _forward_ref.PydanticRecursiveRef
Source code in pydantic/main.py
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 | |
__copy__
¤
__copy__() -> Self
Returns a shallow copy of the model.
Source code in pydantic/main.py
955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
__deepcopy__
¤
__deepcopy__(memo: dict[int, Any] | None = None) -> Self
Returns a deep copy of the model.
Source code in pydantic/main.py
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 | |
__delattr__
¤
__delattr__(item: str) -> Any
Source code in pydantic/main.py
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 | |
__eq__
¤
__eq__(other: Any) -> bool
Source code in pydantic/main.py
1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 | |
__get_pydantic_core_schema__
classmethod
¤
__get_pydantic_core_schema__(source: type[BaseModel], handler: GetCoreSchemaHandler) -> CoreSchema
Source code in pydantic/main.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 | |
__get_pydantic_json_schema__
classmethod
¤
__get_pydantic_json_schema__(core_schema: CoreSchema, handler: GetJsonSchemaHandler) -> JsonSchemaValue
Hook into generating the model's JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
CoreSchema
|
A |
required |
|
GetJsonSchemaHandler
|
Call into Pydantic's internal JSON schema generation.
This will raise a |
required |
Returns:
| Type | Description |
|---|---|
JsonSchemaValue
|
A JSON schema, as a Python object. |
Source code in pydantic/main.py
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 | |
__getattr__
¤
__getattr__(item: str) -> Any
Source code in pydantic/main.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
__getstate__
¤
__getstate__() -> dict[Any, Any]
Source code in pydantic/main.py
1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
__init_subclass__
¤
__init_subclass__(**kwargs: Unpack[ConfigDict])
This signature is included purely to help type-checkers check arguments to class declaration, which provides a way to conveniently set model_config key/value pairs.
from pydantic import BaseModel
class MyModel(BaseModel, extra='allow'): ...
However, this may be deceiving, since the actual calls to __init_subclass__ will not receive any
of the config arguments, and will only receive any keyword arguments passed during class initialization
that are not expected keys in ConfigDict. (This is due to the way ModelMetaclass.__new__ works.)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Unpack[ConfigDict]
|
Keyword arguments passed to the class definition, which set model_config |
{}
|
Note
You may want to override __pydantic_init_subclass__ instead, which behaves similarly but is called
after the class is fully initialized.
Source code in pydantic/main.py
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 | |
__iter__
¤
__iter__() -> TupleGenerator
So dict(model) works.
Source code in pydantic/main.py
1229 1230 1231 1232 1233 1234 | |
__pydantic_init_subclass__
classmethod
¤
__pydantic_init_subclass__(**kwargs: Any) -> None
This is intended to behave just like __init_subclass__, but is called by ModelMetaclass
only after basic class initialization is complete. In particular, attributes like model_fields will
be present when this is called, but forward annotations are not guaranteed to be resolved yet,
meaning that creating an instance of the class may fail.
This is necessary because __init_subclass__ will always be called by type.__new__,
and it would require a prohibitively large refactor to the ModelMetaclass to ensure that
type.__new__ was called in such a manner that the class would already be sufficiently initialized.
This will receive the same kwargs that would be passed to the standard __init_subclass__, namely,
any kwargs passed to the class definition that aren't used internally by Pydantic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
Any keyword arguments passed to the class definition that aren't used internally by Pydantic. |
{}
|
Note
You may want to override __pydantic_on_complete__()
instead, which is called once the class and its fields are fully initialized and ready for validation.
Source code in pydantic/main.py
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 | |
__pydantic_on_complete__
classmethod
¤
__pydantic_on_complete__() -> None
This is called once the class and its fields are fully initialized and ready to be used.
This typically happens when the class is created (just before
__pydantic_init_subclass__() is called on the superclass),
except when forward annotations are used that could not immediately be resolved.
In that case, it will be called later, when the model is rebuilt automatically or explicitly using
model_rebuild().
Source code in pydantic/main.py
877 878 879 880 881 882 883 884 885 886 | |
__replace__
¤
__replace__(**changes: Any) -> Self
Source code in pydantic/main.py
1125 1126 | |
__repr__
¤
__repr__() -> str
Source code in pydantic/main.py
1236 1237 | |
__repr_args__
¤
__repr_args__() -> _repr.ReprArgs
Source code in pydantic/main.py
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 | |
__setattr__
¤
__setattr__(name: str, value: Any) -> None
Source code in pydantic/main.py
1028 1029 1030 1031 1032 1033 1034 | |
__setstate__
¤
__setstate__(state: dict[Any, Any]) -> None
Source code in pydantic/main.py
1139 1140 1141 1142 1143 | |
__str__
¤
__str__() -> str
Source code in pydantic/main.py
1274 1275 | |
construct
classmethod
¤
construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Source code in pydantic/main.py
1477 1478 1479 1480 1481 1482 1483 1484 1485 | |
copy
¤
copy(*, include: AbstractSetIntStr | MappingIntStrAny | None = None, exclude: AbstractSetIntStr | MappingIntStrAny | None = None, update: Dict[str, Any] | None = None, deep: bool = False) -> Self
Returns a copy of the model.
Deprecated
This method is now deprecated; use model_copy instead.
If you need include or exclude, use:
data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to include in the copied model. |
None
|
|
AbstractSetIntStr | MappingIntStrAny | None
|
Optional set or mapping specifying which fields to exclude in the copied model. |
None
|
|
Dict[str, Any] | None
|
Optional dictionary of field-value pairs to override field values in the copied model. |
None
|
|
bool
|
If True, the values of fields that are Pydantic models will be deep-copied. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A copy of the model with included, excluded and updated fields as specified. |
Source code in pydantic/main.py
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 | |
dict
¤
dict(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False) -> Dict[str, Any]
Source code in pydantic/main.py
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 | |
from_orm
classmethod
¤
from_orm(obj: Any) -> Self
Source code in pydantic/main.py
1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 | |
json
¤
json(*, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = False, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, encoder: Callable[[Any], Any] | None = PydanticUndefined, models_as_dict: bool = PydanticUndefined, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 | |
log
¤
log(descr: Union[ResourceDescr, InvalidDescr])
Source code in src/bioimageio/core/cli.py
131 132 | |
model_computed_fields
classmethod
¤
model_computed_fields() -> dict[str, ComputedFieldInfo]
A mapping of computed field names to their respective ComputedFieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
273 274 275 276 277 278 279 280 281 282 | |
model_construct
classmethod
¤
model_construct(_fields_set: set[str] | None = None, **values: Any) -> Self
Creates a new instance of the Model class with validated data.
Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data.
Default values are respected, but no other validation is performed.
Note
model_construct() generally respects the model_config.extra setting on the provided model.
That is, if model_config.extra == 'allow', then all extra passed values are added to the model instance's __dict__
and __pydantic_extra__ fields. If model_config.extra == 'ignore' (the default), then all extra passed values are ignored.
Because no validation is performed with a call to model_construct(), having model_config.extra == 'forbid' does not result in
an error if extra values are passed, but they will be ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
set[str] | None
|
A set of field names that were originally explicitly set during instantiation. If provided,
this is directly used for the |
None
|
|
Any
|
Trusted or pre-validated data dictionary. |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
A new instance of the |
Source code in pydantic/main.py
303 304 305 306 307 308 309 310 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 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
model_copy
¤
Usage Documentation
Returns a copy of the model.
Note
The underlying instance's [__dict__][object.__dict__] attribute is copied. This
might have unexpected side effects if you store anything in it, on top of the model
fields (e.g. the value of [cached properties][functools.cached_property]).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Mapping[str, Any] | None
|
Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data. |
None
|
|
bool
|
Set to |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
New model instance. |
Source code in pydantic/main.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 | |
model_dump
¤
model_dump(*, mode: Literal['json', 'python'] | str = 'python', include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> dict[str, Any]
Usage Documentation
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Literal['json', 'python'] | str
|
The mode in which |
'python'
|
|
IncEx | None
|
A set of fields to include in the output. |
None
|
|
IncEx | None
|
A set of fields to exclude from the output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to use the field's alias in the dictionary key if defined. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representation of the model. |
Source code in pydantic/main.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
model_dump_json
¤
model_dump_json(*, indent: int | None = None, ensure_ascii: bool = False, include: IncEx | None = None, exclude: IncEx | None = None, context: Any | None = None, by_alias: bool | None = None, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, exclude_computed_fields: bool = False, round_trip: bool = False, warnings: bool | Literal['none', 'warn', 'error'] = True, fallback: Callable[[Any], Any] | None = None, serialize_as_any: bool = False) -> str
Usage Documentation
Generates a JSON representation of the model using Pydantic's to_json method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
int | None
|
Indentation to use in the JSON output. If None is passed, the output will be compact. |
None
|
|
bool
|
If |
False
|
|
IncEx | None
|
Field(s) to include in the JSON output. |
None
|
|
IncEx | None
|
Field(s) to exclude from the JSON output. |
None
|
|
Any | None
|
Additional context to pass to the serializer. |
None
|
|
bool | None
|
Whether to serialize using field aliases. |
None
|
|
bool
|
Whether to exclude fields that have not been explicitly set. |
False
|
|
bool
|
Whether to exclude fields that are set to their default value. |
False
|
|
bool
|
Whether to exclude fields that have a value of |
False
|
|
bool
|
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
|
False
|
|
bool
|
If True, dumped values should be valid as input for non-idempotent types such as Json[T]. |
False
|
|
bool | Literal['none', 'warn', 'error']
|
How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
"error" raises a |
True
|
|
Callable[[Any], Any] | None
|
A function to call when an unknown value is encountered. If not provided,
a |
None
|
|
bool
|
Whether to serialize fields with duck-typing serialization behavior. |
False
|
Returns:
| Type | Description |
|---|---|
str
|
A JSON string representation of the model. |
Source code in pydantic/main.py
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
model_fields
classmethod
¤
A mapping of field names to their respective FieldInfo instances.
Warning
Accessing this attribute from a model instance is deprecated, and will not work in Pydantic V3. Instead, you should access this attribute from the model class.
Source code in pydantic/main.py
262 263 264 265 266 267 268 269 270 271 | |
model_json_schema
classmethod
¤
model_json_schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema, mode: JsonSchemaMode = 'validation', *, union_format: Literal['any_of', 'primitive_type_array'] = 'any_of') -> dict[str, Any]
Generates a JSON schema for a model class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to use attribute aliases or not. |
True
|
|
str
|
The reference template. |
DEFAULT_REF_TEMPLATE
|
|
Literal['any_of', 'primitive_type_array']
|
The format to use when combining schemas from unions together. Can be one of:
|
'any_of'
|
|
type[GenerateJsonSchema]
|
To override the logic used to generate the JSON schema, as a subclass of
|
GenerateJsonSchema
|
|
JsonSchemaMode
|
The mode in which to generate the schema. |
'validation'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The JSON schema for the given model class. |
Source code in pydantic/main.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | |
model_parametrized_name
classmethod
¤
model_parametrized_name(params: tuple[type[Any], ...]) -> str
Compute the class name for parametrizations of generic classes.
This method can be overridden to achieve a custom naming scheme for generic BaseModels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
tuple[type[Any], ...]
|
Tuple of types of the class. Given a generic class
|
required |
Returns:
| Type | Description |
|---|---|
str
|
String representing the new class where |
Raises:
| Type | Description |
|---|---|
TypeError
|
Raised when trying to generate concrete names for non-generic models. |
Source code in pydantic/main.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 | |
model_post_init
¤
model_post_init(context: Any) -> None
Override this method to perform additional initialization after __init__ and model_construct.
This is useful if you want to do some validation that requires the entire model to be initialized.
Source code in pydantic/main.py
612 613 614 615 | |
model_rebuild
classmethod
¤
model_rebuild(*, force: bool = False, raise_errors: bool = True, _parent_namespace_depth: int = 2, _types_namespace: MappingNamespace | None = None) -> bool | None
Try to rebuild the pydantic-core schema for the model.
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
bool
|
Whether to force the rebuilding of the model schema, defaults to |
False
|
|
bool
|
Whether to raise errors, defaults to |
True
|
|
int
|
The depth level of the parent namespace, defaults to 2. |
2
|
|
MappingNamespace | None
|
The types namespace, defaults to |
None
|
Returns:
| Type | Description |
|---|---|
bool | None
|
Returns |
Source code in pydantic/main.py
617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
model_validate
classmethod
¤
model_validate(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, from_attributes: bool | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate a pydantic model instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
bool | None
|
Whether to extract data from object attributes. |
None
|
|
Any | None
|
Additional context to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
If the object could not be validated. |
Returns:
| Type | Description |
|---|---|
Self
|
The validated model instance. |
Source code in pydantic/main.py
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 | |
model_validate_json
classmethod
¤
model_validate_json(json_data: str | bytes | bytearray, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Usage Documentation
Validate the given JSON data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | bytes | bytearray
|
The JSON data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
If |
Source code in pydantic/main.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 | |
model_validate_strings
classmethod
¤
model_validate_strings(obj: Any, *, strict: bool | None = None, extra: ExtraValues | None = None, context: Any | None = None, by_alias: bool | None = None, by_name: bool | None = None) -> Self
Validate the given object with string data against the Pydantic model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Any
|
The object containing string data to validate. |
required |
|
bool | None
|
Whether to enforce types strictly. |
None
|
|
ExtraValues | None
|
Whether to ignore, allow, or forbid extra data during model validation.
See the [ |
None
|
|
Any | None
|
Extra variables to pass to the validator. |
None
|
|
bool | None
|
Whether to use the field's alias when validating against the provided input data. |
None
|
|
bool | None
|
Whether to use the field's name when validating against the provided input data. |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
The validated Pydantic model. |
Source code in pydantic/main.py
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
parse_file
classmethod
¤
parse_file(path: str | Path, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 | |
parse_obj
classmethod
¤
parse_obj(obj: Any) -> Self
Source code in pydantic/main.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 | |
parse_raw
classmethod
¤
parse_raw(b: str | bytes, *, content_type: str | None = None, encoding: str = 'utf8', proto: DeprecatedParseProtocol | None = None, allow_pickle: bool = False) -> Self
Source code in pydantic/main.py
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
schema
classmethod
¤
schema(by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE) -> Dict[str, Any]
Source code in pydantic/main.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 | |
schema_json
classmethod
¤
schema_json(*, by_alias: bool = True, ref_template: str = DEFAULT_REF_TEMPLATE, **dumps_kwargs: Any) -> str
Source code in pydantic/main.py
1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
update_forward_refs
classmethod
¤
update_forward_refs(**localns: Any) -> None
Source code in pydantic/main.py
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 | |
validate
classmethod
¤
validate(value: Any) -> Self
Source code in pydantic/main.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 | |