Skip to content

Serializer

pybeerxml.serializer.Serializer

Serialize Recipe objects into BeerXML.

The API mirrors Parser on the write side:

  • serialize() returns a complete BeerXML document string
  • write() writes a complete BeerXML document to disk
  • recipe_to_xml_element() returns a single <RECIPE> element

BeerXML requires recipe record-set containers such as HOPS and FERMENTABLES, so those sections are emitted even when empty.

recipe_to_xml_element(recipe)

Serialize a single recipe as a BeerXML <RECIPE> element.

Parameters:

Name Type Description Default
recipe Recipe

The recipe to serialize.

required

Returns:

Type Description
Element

A single <RECIPE> XML element.

serialize(recipes, encoding='utf-8', xml_declaration=True)

Serialize recipes into a complete BeerXML document string.

Parameters:

Name Type Description Default
recipes list[Recipe]

Recipes to include in the document.

required
encoding str

XML encoding to use for output.

'utf-8'
xml_declaration bool

Whether to include the XML declaration.

True

Returns:

Type Description
str

A BeerXML document as a string.

write(recipes, path, encoding='utf-8')

Write recipes to a BeerXML file.

Parameters:

Name Type Description Default
recipes list[Recipe]

Recipes to serialize.

required
path str | Path

Destination file path.

required
encoding str

XML encoding to use for output.

'utf-8'