Python library for SBGN

Matthias König

Humboldt-Universität zu Berlin, Faculty of Life Science, Institute of Biology, ITB
University of Stuttgart, Institute of Structural Mechanics and Dynamics in Aerospace Engineering

February 2, 2026

SBGN

  • Systems Biology Graphical Notation1
  • Standardise graphical notation used in maps of biological processes
  • Process Description (PD)2: temporal courses of biochemical interactions in a network
  • Entity Relationship (ER)3: all relationships between participates, regardless of the temporal aspects
  • Activity Flow (AF)4: flow of information between biochemical entities in a network

libsbgnpy

  • Python library for SBGN1
  • Supports AF, PD, ER
  • Supports libsbgn/0.3
  • new: xsdata v26.1 dataclasses (stricter validation)
  • new: py3.10 - py3.14 support
  • new: better documentation: https://matthiaskoenig.github.io/libsbgnpy/

1. Create map

"""Ethanol example."""
# create new map
map = Map(
    language=MapLanguage.PROCESS_DESCRIPTION,
    bbox=Bbox(x=0, y=0, w=363, h=253),
)
# add map to new sbgn
sbgn = Sbgn(map=[map])

2. Add glyphs

"""Ethanol example."""
map.glyph.extend([
    Glyph(
        class_value=GlyphClass.SIMPLE_CHEMICAL,
        id="ethanol",
        label=Label(text="Ethanol"),
        bbox=Bbox(x=40, y=120, w=60, h=60),
    ),
    Glyph(
        class_value=GlyphClass.SIMPLE_CHEMICAL,
        id="ethanal",
        label=Label(text="Ethanal"),
        bbox=Bbox(x=220, y=110, w=60, h=60),
    ),
    Glyph(
        class_value=GlyphClass.MACROMOLECULE,
        id="adh1",
        label=Label(text="ADH1"),
        bbox=Bbox(x=106, y=20, w=108, h=60),
    ),
    Glyph(
        class_value=GlyphClass.SIMPLE_CHEMICAL,
        id="h",
        label=Label(text="H+"),
        bbox=Bbox(x=220, y=190, w=60, h=60),
        clone=Glyph.Clone(),
    ),
    Glyph(
        class_value=GlyphClass.SIMPLE_CHEMICAL,
        id="nad",
        label=Label(text="NAD+"),
        bbox=Bbox(x=40, y=190, w=60, h=60),
        clone=Glyph.Clone(),
    ),
    Glyph(
        class_value=GlyphClass.SIMPLE_CHEMICAL,
        id="glyph_nadh",
        label=Label(text="NADH"),
        bbox=Bbox(x=300, y=150, w=60, h=60),
        clone=Glyph.Clone(),
    ),
    # glyph with ports (process)
    Glyph(
        class_value=GlyphClass.PROCESS,
        id="pn1",
        orientation=GlyphOrientation.HORIZONTAL,
        bbox=Bbox(x=148, y=168, w=24, h=24),
        port=[
            Port(x=136, y=180, id="pn1.1"),
            Port(x=184, y=180, id="pn1.2"),
        ],
    ),
])

2. Add glyphs

3. Add arcs

"""Ethanol example."""
# create arcs and set the start and end points
map.arc.extend(
    [
        Arc(
            id="a01",
            class_value=ArcClass.CONSUMPTION,
            source="ethanol",
            target="pn1.1",
            start=Arc.Start(x=98, y=160),
            end=Arc.End(x=136, y=180),
        ),
        Arc(
            id="a02",
            class_value=ArcClass.PRODUCTION,
            source="pn1.2",
            target="nadh",
            start=Arc.Start(x=184, y=180),
            end=Arc.End(x=300, y=180),
        ),
        Arc(
            id="a03",
            class_value=ArcClass.CATALYSIS,
            source="adh1",
            target="pn1",
            start=Arc.Start(x=160, y=80),
            end=Arc.End(x=160, y=168),
        ),
        Arc(
            id="a04",
            class_value=ArcClass.PRODUCTION,
            source="pn1.2",
            target="h",
            start=Arc.Start(x=184, y=180),
            end=Arc.End(x=224, y=202),
        ),
        Arc(
            id="a05",
            class_value=ArcClass.PRODUCTION,
            source="pn1.2",
            target="ethanal",
            start=Arc.Start(x=184, y=180),
            end=Arc.End(x=224, y=154),
        ),
        Arc(
            id="a06",
            class_value=ArcClass.CONSUMPTION,
            source="nad",
            target="pn1.1",
            start=Arc.Start(x=95, y=202),
            end=Arc.End(x=136, y=180),
        ),
    ]
)

3. Add arcs

4. Add render information

render_info = RenderInformation(
    id="ethanol_render_info",
    program_name="libsbgnpy",
    program_version="0.4.0",
    list_of_color_definitions=ListOfColorDefinitions(
        color_definition=[
            ColorDefinition(id="blue", value="#1f77b4bb"),
            ColorDefinition(id="orange", value="#ff7f0ebb"),
            ColorDefinition(id="white", value="#000000"),
            ColorDefinition(id="grey", value="#cccccccc"),
            ColorDefinition(id="black", value="#ffffff"),
        ]
    ),
    list_of_gradient_definitions=ListOfGradientDefinitions(),
    list_of_styles=ListOfStyles(
        [
            Style(
                id_list="ethanol ethanal",
                g=G(stroke="black", stroke_width=2, fill="blue"),
            ),
            Style(
                id_list="adh1",
                g=G(stroke="black", stroke_width=2, fill="orange"),
            ),
            Style(
                id_list="nad nadh h",
                g=G(stroke="black", stroke_width=1, fill="grey"),
            ),
        ]
    ),
)

5. Save and render

# serialize to string
xml_str: str =  write_sbgn_to_string(sbgn)

# serialize to file
write_sbgn_to_file(sbgn, "ethanol_example.sbgn")

# render SBGN
render_sbgn(sbgn, "ethanol_example.png")

Want to know more

libsbgnpy documentation

Bergmann, Frank T., Tobias Czauderna, Ugur Dogrusoz, Adrien Rougny, Andreas Dräger, Vasundra Touré, Alexander Mazein, Michael L. Blinov, and Augustin Luna. 2020. “Systems Biology Graphical Notation Markup Language (SBGNML) Version 0.3.” Journal of Integrative Bioinformatics 17 (2-3): 20200016. https://doi.org/10.1515/jib-2020-0016.
König, Matthias. 2026. “Libsbgnpy: Python Library for SBGN.” Zenodo. https://doi.org/10.5281/zenodo.18455396.
Le Novère, Nicolas, Michael Hucka, Huaiyu Mi, Stuart Moodie, Falk Schreiber, Anatoly Sorokin, Emek Demir, et al. 2009. “The Systems Biology Graphical Notation.” Nature Biotechnology 27 (8): 735–41. https://doi.org/10.1038/nbt.1558.
Mi, Huaiyu, Falk Schreiber, Stuart Moodie, Tobias Czauderna, Emek Demir, Robin Haw, Augustin Luna, Nicolas Le Novère, Anatoly Sorokin, and Alice Villéger. 2015. “Systems Biology Graphical Notation: Activity Flow Language Level 1 Version 1.2.” Journal of Integrative Bioinformatics 12 (2): 265. https://doi.org/10.2390/biecoll-jib-2015-265.
Rougny, Adrien, Vasundra Touré, Stuart Moodie, Irina Balaur, Tobias Czauderna, Hanna Borlinghaus, Ugur Dogrusoz, et al. 2019. “Systems Biology Graphical Notation: Process Description Language Level 1 Version 2.0.” Journal of Integrative Bioinformatics 16 (2): 20190022. https://doi.org/10.1515/jib-2019-0022.
Sorokin, Anatoly, Nicolas Le Novère, Augustin Luna, Tobias Czauderna, Emek Demir, Robin Haw, Huaiyu Mi, Stuart Moodie, Falk Schreiber, and Alice Villéger. 2015. “Systems Biology Graphical Notation: Entity Relationship Language Level 1 Version 2.” Journal of Integrative Bioinformatics 12 (2): 264. https://doi.org/10.2390/biecoll-jib-2015-264.
van Iersel, Martijn P., Alice C. Villéger, Tobias Czauderna, Sarah E. Boyd, Frank T. Bergmann, Augustin Luna, Emek Demir, et al. 2012. “Software Support for SBGN Maps: SBGN-ML and LibSBGN.” Bioinformatics 28 (15): 2016–21. https://doi.org/10.1093/bioinformatics/bts270.