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:
file_pathPath

Location of the BoM XML file.

allow_unsupported_databool, default: True

If False, an exception is raised if there is data in the BoM XML that cannot be deserialized.

Added in version 2.3.

Returns:
eco2412.BillOfMaterials or eco2301.BillOfMaterials
Raises:
ValueError

If the BoM cannot be deserialized. Additional detail is included in the exception message.

ValueError

If 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 = False is 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:
bom_textstr

String object containing an XML representation of a BoM.

allow_unsupported_databool, default: True

If False, an exception is raised if there is data in the BoM XML that cannot be deserialized.

Added in version 2.3.

Returns:
eco2412.BillOfMaterials or eco2301.BillOfMaterials
Raises:
ValueError

If the BoM cannot be deserialized.

ValueError

If 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 = False is 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_version argument.

Added in version 2.3.

Parameters:
bomeco2412.BillOfMaterials or eco2301.BillOfMaterials

The BoM to convert.

target_bom_versionType[eco2412.BillOfMaterials] | Type[eco2301.BillOfMaterials]

The BillOfMaterials class 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.

Returns:
eco2412.BillOfMaterials or eco2301.BillOfMaterials
Raises:
ValueError

If the BoM cannot be deserialized. Additional detail is included in the exception message.

ValueError

If the BoM contains data that cannot be represented by classes in the target XML namespace and allow_unsupported_data = False is specified.

ValueError

If the target_bom_version argument is invalid.

dump_bom(bom)#

Convert a BillOfMaterials object into a string XML representation.

Parameters:
bomeco2412.BillOfMaterials or eco2301.BillOfMaterials
Returns:
str

Serialized representation of the BoM.