BoM handler#
The BoM handler provides the serialization and deserialization of BillOfMaterial objects to and from XML format. This process validates that the BoM has a valid structure, and that the XML provided is syntactically correct.
- class BoMHandler#
Handler for XML formatted BoMs.
Supports reading from files and strings, serializing to string format, and converting BoMs between different versions.
Added in version 2.0.
- load_bom_from_file(file_path, allow_unsupported_data=True)#
Read a BoM from a file and return the corresponding BillOfMaterials object for use.
- Parameters:
- Returns:
- Raises:
ValueErrorIf the BoM cannot be deserialized. Additional detail is included in the exception message.
ValueErrorIf the BoM contains data that cannot be represented by 24/12 XML BoM types or 23/01 XML BoM types classes and
allow_unsupported_data = Falseis specified. The additional data fields are reported in the exception message.
- load_bom_from_text(bom_text, allow_unsupported_data=True)#
Read a BoM from a string and return the corresponding BillOfMaterials object for use.
- Parameters:
- Returns:
- Raises:
ValueErrorIf the BoM cannot be deserialized.
ValueErrorIf the BoM contains data that cannot be represented by 24/12 XML BoM types or 23/01 XML BoM types classes and
allow_unsupported_data = Falseis specified. The additional data fields are reported in the exception message.
- convert(bom, target_bom_version, allow_unsupported_data=True)#
Convert a BoM from one version to another.
The BoM is returned as an instance of the type specified in the
target_bom_versionargument.Added in version 2.3.
- Parameters:
- bom
eco2412.BillOfMaterialsoreco2301.BillOfMaterials The BoM to convert.
- target_bom_version
Type[eco2412.BillOfMaterials] |Type[eco2301.BillOfMaterials] The
BillOfMaterialsclass to convert the provided BoM to. Must be a class, not an instance of a class.- allow_unsupported_databool, default:
True If
False, an exception is raised if there is data in the provided BoM that cannot be represented in the target BoM version.
- bom
- Returns:
- Raises:
ValueErrorIf the BoM cannot be deserialized. Additional detail is included in the exception message.
ValueErrorIf the BoM contains data that cannot be represented by classes in the target XML namespace and
allow_unsupported_data = Falseis specified.ValueErrorIf the
target_bom_versionargument is invalid.