ch_api.types.base#
Base Pydantic model for Companies House API types.
Extends Pydantic’s BaseModel with field name normalization for API responses.
See also
- class ch_api.types.base.BaseModel[source]#
Base Pydantic model for Companies House API responses.
Automatically normalizes field names to lowercase for consistency. Inherits from this class for all API response models.
- model_config = {'extra': 'ignore'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- classmethod model_validate(data: Any, **kwargs: Any) BaseModel[source]#
Validate and create model instance from API response data.
This method extends Pydantic’s validation to handle Companies House API response patterns including field name normalization and filtering of deprecated/unused fields.
The method performs the following transformations:
Field name normalization: Converts all field names to lowercase
Whitespace trimming: Removes leading/trailing whitespace from field names
Deprecated field filtering: Removes fields marked as
[notinuse]
- Parameters:
data (Any) –
Raw data from API response, typically a dictionary with field names that may use mixed case (e.g.,
CompanyName,company_number).Also supports non-dict data, which is passed directly to Pydantic’s validation without modification.
- Returns:
A validated model instance with normalized field names and deprecated fields removed.
- Return type:
Example
Validate API response with mixed-case field names:
>>> from ch_api.types.base import BaseModel >>> # The BaseModel normalizes field names automatically >>> # Example: API returns {"CompanyNumber": "..."} but model expects company_number >>> # This is handled transparently by model_validate() >>> # >>> # Deprecated fields marked with [notinuse] are automatically filtered: >>> # Example: {"OldField[notinuse]": "value"} -> automatically excluded
Note
This method is automatically called by Pydantic when deserializing JSON or dict data into the model. You typically don’t need to call this method directly unless you’re doing custom serialization/deserialization.
See also
pydantic.BaseModel.model_validateParent Pydantic validation method
- __pydantic_fields_set__#
The names of fields explicitly set during instantiation.
- __pydantic_extra__#
A dictionary containing extra values, if [extra][pydantic.config.ConfigDict.extra] is set to ‘allow’.
- __pydantic_private__#
Values of private attributes set on the model instance.
- __class_vars__ = {}#
The names of the class variables defined on the model.
- __private_attributes__ = {}#
Metadata about the private attributes of the model.
- __pydantic_complete__ = True#
Whether model building is completed, or if there are still undefined fields.
- __pydantic_computed_fields__ = {}#
A dictionary of computed field names and their corresponding [ComputedFieldInfo][pydantic.fields.ComputedFieldInfo] objects.
- __pydantic_core_schema__ = {'cls': <class 'ch_api.types.base.BaseModel'>, 'config': {'extra_fields_behavior': 'ignore', 'title': 'BaseModel'}, 'custom_init': False, 'metadata': {'pydantic_js_functions': [<bound method BaseModel.__get_pydantic_json_schema__ of <class 'ch_api.types.base.BaseModel'>>]}, 'ref': 'ch_api.types.base.BaseModel:94287134004496', 'root_model': False, 'schema': {'computed_fields': [], 'fields': {}, 'model_name': 'BaseModel', 'type': 'model-fields'}, 'type': 'model'}#
The core schema of the model.
- __pydantic_custom_init__ = False#
Whether the model has a custom __init__ method.
- __pydantic_decorators__ = DecoratorInfos(validators={}, field_validators={}, root_validators={}, field_serializers={}, model_serializers={}, model_validators={}, computed_fields={})#
Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.
- __pydantic_fields__ = {}#
A dictionary of field names and their corresponding [FieldInfo][pydantic.fields.FieldInfo] objects. This replaces Model.__fields__ from Pydantic V1.
- __pydantic_generic_metadata__ = {'args': (), 'origin': None, 'parameters': ()}#
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__ = None#
Parent namespace of the model, used for automatic rebuilding of models.
- __pydantic_post_init__ = None#
The name of the post-init method for the model, if defined.
- __pydantic_serializer__ = SchemaSerializer(serializer=Model( ModelSerializer { class: Py( 0x000055c0ef211510, ), serializer: Fields( GeneralFieldsSerializer { fields: {}, computed_fields: Some( ComputedFields( [], ), ), mode: SimpleDict, extra_serializer: None, filter: SchemaFilter { include: None, exclude: None, }, required_fields: 0, }, ), has_extra: false, root_model: false, name: "BaseModel", }, ), definitions=[])#
The pydantic-core SchemaSerializer used to dump instances of the model.
- __pydantic_setattr_handlers__ = {}#
__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__
- __pydantic_validator__ = SchemaValidator(title="BaseModel", validator=Model( ModelValidator { revalidate: Never, validator: ModelFields( ModelFieldsValidator { fields: [], model_name: "BaseModel", extra_behavior: Ignore, extras_validator: None, extras_keys_validator: None, strict: false, from_attributes: false, loc_by_alias: true, validate_by_alias: None, validate_by_name: None, }, ), class: Py( 0x000055c0ef211510, ), generic_origin: None, post_init: None, frozen: false, custom_init: false, root_model: false, undefined: Py( 0x00007f70cd6e8550, ), name: "BaseModel", }, ), definitions=[], cache_strings=True)#
The pydantic-core SchemaValidator used to validate instances of the model.
- __signature__ = <Signature () -> None>#
The synthesized __init__ [Signature][inspect.Signature] of the model.
- __weakref__#
list of weak references to the object