Serializer¶
pybeerxml.serializer.Serializer
¶
Serialize Recipe objects into BeerXML.
The API mirrors Parser on the write side:
serialize()returns a complete BeerXML document stringwrite()writes a complete BeerXML document to diskrecipe_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 |
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. |