Skip to content

Python API

Autogenerated from the xpict package with mkdocstrings.

Public surface

xpict

xpict — molecule depiction.

Two first-class APIs (same paint as JS / Rust):

Single molecule — mol / render / to_svg::

from xpict import mol, render, to_svg

benzene = mol("c1ccccc1")
rendered = render(benzene, MolRenderOptions(color="#0b6e4f"))
svg = to_svg(rendered.scene)

Declarative document — nested DepictSpec via Rust depict::

from xpict import depict, to_svg

rows = depict({"type": "mol", "smiles": "CCO"})
svg = to_svg(rows[0].scene)

MolSpec module-attribute

MolSpec = MolNode

__version__ module-attribute

__version__ = '0.7.1'

Mol dataclass

Mol(
    source: str,
    frame_molblock: str | None = None,
    id: str | None = None,
    align_to: str | None = None,
    label: str | None = None,
    label_pos: LabelPos | None = None,
    label_color: str | None = None,
    label_scale: float | None = None,
)

Bases: PictBase

Input molecule — SMILES / CXSMILES / molfile plus optional align frame.

with_label

with_label(
    text: str,
    *,
    pos: LabelPos | None = None,
    color: str | None = None,
    scale: float | None = None,
) -> Mol

Return a copy with a caption (mol(..., name=...) equivalent).

Source code in python/xpict/spec.py
def with_label(
    self,
    text: str,
    *,
    pos: LabelPos | None = None,
    color: str | None = None,
    scale: float | None = None,
) -> Mol:
    """Return a copy with a caption (``mol(..., name=...)`` equivalent)."""
    return replace(
        self,
        label=text,
        label_pos=pos,
        label_color=color if color is not None else self.label_color,
        label_scale=scale if scale is not None else self.label_scale,
    )

to_node

to_node(id: str | None = None) -> MolNode

Build a MolNode from this source (smiles / cxsmiles / molfile).

Source code in python/xpict/spec.py
def to_node(self, id: str | None = None) -> MolNode:
    """Build a ``MolNode`` from this source (smiles / cxsmiles / molfile)."""
    text = self.source.strip()
    if "V2000" in text or "V3000" in text or text.count("\n") >= 3:
        kind_fields = {"molfile": text}
    elif "|" in text:
        kind_fields = {"cxsmiles": text}
    else:
        kind_fields = {"smiles": text}
    nid = self.id if id is None else id
    node = MolNode.model_validate(
        {"id": nid, "align_to": self.align_to, **kind_fields}
    )
    cap = (self.label or "").strip()
    if not cap:
        return node
    mid = (node.id or "m_0").strip() or "m_0"
    # Privileged wire ``name`` — default side below (handled in Rust).
    if (
        self.label_pos is not None
        or self.label_color is not None
        or self.label_scale is not None
    ):
        name: str | MolTextSpec = MolTextSpec(
            content=cap,
            pos=self.label_pos,
            color=self.label_color,
            scale=self.label_scale,
        )
    else:
        name = cap
    return node.model_copy(update={"id": mid, "name": name})

to_caption_nodes

to_caption_nodes(id: str | None = None) -> list[MolNode]

Lone mol node (caption lives on MolNode.name, not a sibling text).

Source code in python/xpict/spec.py
def to_caption_nodes(self, id: str | None = None) -> list[MolNode]:
    """Lone mol node (caption lives on ``MolNode.name``, not a sibling text)."""
    return [self.to_node(id=id)]

to_spec

to_spec(opts: MolRenderOptions | None = None) -> DepictSpec

Document for paint — identity on the mol; cascade via .opts bag.

Source code in python/xpict/spec.py
def to_spec(self, opts: MolRenderOptions | None = None) -> DepictSpec:
    """Document for paint — identity on the mol; cascade via ``.opts`` bag."""
    if opts is None:
        return DepictSpec(self.to_node())
    shade = opts.shade_scores()

    overlay: dict[str, object] = {}
    if opts.star_labels is not None:
        overlay["star_labels"] = opts.star_labels
    if shade is not None:
        overlay["shade"] = shade
    if opts.circle is not None:
        overlay["circle"] = opts.circle

    if opts.align_to is None:
        node = self.to_node(id=opts.id)
        if overlay:
            node = node.model_copy(update=overlay)
        doc = DepictSpec(node)
    else:
        ref = opts.reference_mol()
        ref_id = ref.id or "m_0"
        qid = opts.id or self.id or "m_1"
        if qid == ref_id:
            qid = "m_1"
        query = self.to_node(id=qid).model_copy(
            update={
                "align_to": opts.align_wire(),
                **overlay,
            }
        )
        doc = DepictSpec(
            GroupNode(
                type="group",
                align=False,
                children=[ref.to_node(id=ref_id), query],
            )
        )

    kw = opts.cascade_keywords()
    return DepictSpec(doc.opts(**kw).root) if kw else doc

Rendered dataclass

Rendered(
    width: float,
    height: float,
    scene: Scene,
    molecule: MoleculeIn,
    source: str,
    frame_molblock: str,
    coords: list[SvgAtom],
    svg_coords: list[SvgAtom],
    bonds: list[SvgBond],
    mol: Mol | None = None,
)

Bases: PictBase

Painted depiction — editable scene plus alignment frame.

MolRenderOptions dataclass

MolRenderOptions(
    id: str | None = None,
    color: str | None = None,
    atom_shade: list[float] | None = None,
    bond_shade: list[float] | None = None,
    circle: CircleField | None = None,
    star_labels: list[str | None] | None = None,
    weight: float | None = None,
    scale: float | None = None,
    aromatic: AromaticStyle | None = None,
    debug_box: bool | None = None,
    debug_align: bool | None = None,
    align_to: Mol | Rendered | None = None,
    atom_map: list[tuple[int, int]] | None = None,
)

Render options — parity with JS / Rust MolRenderOptions.

cascade_keywords

cascade_keywords() -> OptsKeywords

Universal MolOpts keys for the document opts bag.

Source code in python/xpict/spec.py
def cascade_keywords(self) -> OptsKeywords:
    """Universal ``MolOpts`` keys for the document ``opts`` bag."""
    out: OptsKeywords = {}
    for key in (
        "color",
        "weight",
        "scale",
        "aromatic",
        "debug_box",
        "debug_align",
    ):
        val = getattr(self, key)
        if val is not None:
            out[key] = val  # type: ignore[literal-required]
    return out

shade_scores

shade_scores() -> ShadeSpec | None

Non-cascading per-atom / per-bond scores (leaf MolNode.shade).

Source code in python/xpict/spec.py
def shade_scores(self) -> ShadeSpec | None:
    """Non-cascading per-atom / per-bond scores (leaf ``MolNode.shade``)."""
    if self.atom_shade is None and self.bond_shade is None:
        return None
    return ShadeSpec(atoms=self.atom_shade, bonds=self.bond_shade)

reference_mol

reference_mol() -> Mol

align_to as a Mol (unwraps Rendered).

Source code in python/xpict/spec.py
def reference_mol(self) -> Mol:
    """``align_to`` as a ``Mol`` (unwraps ``Rendered``)."""
    if self.align_to is None:
        raise ValueError("align_to is required")
    if isinstance(self.align_to, Rendered):
        back = self.align_to.mol
        return back if isinstance(back, Mol) else mol(self.align_to.source)
    return self.align_to

Pict

Pict(*, format: OutputFormat = 'svg')

Native Rust depiction engine (no layout-backend switch).

Source code in python/xpict/api.py
def __init__(self, *, format: OutputFormat = "svg") -> None:
    self.format: OutputFormat = format

layout

layout(spec: DepictInput) -> list[MoleculeIn]

Lay out molecules via Rust depict (MoleculeIn from painted rows).

Source code in python/xpict/api.py
def layout(self, spec: DepictInput) -> list[MoleculeIn]:
    """Lay out molecules via Rust ``depict`` (``MoleculeIn`` from painted rows)."""
    return [r.molecule for r in depict(to_live_depict(spec))]

DepictSpec

Bases: PictBase, DepictSpec

Live document root — generated wire model + host operators via PictBase.

Scene

Bases: StrictModel

Full drawable document before SVG/HTML serialization.

mol

mol(
    smiles_or_molfile: str,
    *,
    id: str | None = None,
    align_to: str | None = None,
    name: str | None = None,
    label: str | None = None,
    label_pos: LabelPos | None = None,
    label_color: str | None = None,
    label_scale: float | None = None,
) -> Mol

Construct a Mol (JS / Rust xpict.mol).

name (preferred) / label (alias) set wire MolNode.name — painted inside the mol SVG by Rust. Default side is below; optional label_pos / color / scale map onto styled MolText.

Source code in python/xpict/spec.py
def mol(
    smiles_or_molfile: str,
    *,
    id: str | None = None,
    align_to: str | None = None,
    name: str | None = None,
    label: str | None = None,
    label_pos: LabelPos | None = None,
    label_color: str | None = None,
    label_scale: float | None = None,
) -> Mol:
    """Construct a ``Mol`` (JS / Rust ``xpict.mol``).

    ``name`` (preferred) / ``label`` (alias) set wire ``MolNode.name`` — painted
    inside the mol SVG by Rust. Default side is below; optional ``label_pos`` /
    color / scale map onto styled ``MolText``.
    """
    text = smiles_or_molfile.strip()
    if not text:
        raise ValueError("mol() requires a non-empty SMILES or molfile")
    if name is not None and label is not None and name != label:
        raise ValueError("mol() got both name= and label=; use only one")
    caption = name if name is not None else label
    return Mol(
        source=text,
        id=id,
        align_to=align_to,
        label=caption,
        label_pos=label_pos,
        label_color=label_color,
        label_scale=label_scale,
    )

render

render(
    input: Mol | str, opts: MolRenderOptions | None = None
) -> Rendered
render(
    input: DepictSpec | DepictSpecDict | PictSpec,
    opts: None = None,
    *,
    format: OutputFormat = "svg",
) -> str
render(
    input: Mol
    | str
    | DepictSpec
    | DepictSpecDict
    | PictSpec,
    opts: MolRenderOptions | None = None,
    *,
    format: OutputFormat = "svg",
) -> Rendered | str

Single-mol render(mol, opts) or document render(doc) via Rust.

Source code in python/xpict/__init__.py
def render(
    input: Mol | str | DepictSpec | DepictSpecDict | PictSpec,
    opts: MolRenderOptions | None = None,
    *,
    format: OutputFormat = "svg",
) -> Rendered | str:
    """Single-mol ``render(mol, opts)`` or document ``render(doc)`` via Rust."""
    if isinstance(input, (Mol, str)):
        return render_mol(input, opts)
    if opts is not None:
        raise TypeError(
            "document render() does not take a second positional opts; "
            "use format= keywords, or mol()/render(mol, opts) for single-mol"
        )
    if isinstance(input, DepictSpec) or (
        isinstance(input, dict) and is_live_depict_spec(input)
    ):
        if format != "svg":
            return Pict(format=format).render(input)
        return depict_svg(input)
    return Pict(format=format).render(input)

to_svg

to_svg(scene: Scene | SceneDict) -> str

Scene JSON / Scene → SVG string (JS xpict.toSvg).

Source code in python/xpict/rendered.py
def to_svg(scene: Scene | SceneDict) -> str:
    """Scene JSON / ``Scene`` → SVG string (JS ``xpict.toSvg``)."""
    if isinstance(scene, dict):
        scene = Scene.model_validate(scene)
    return scene_to_svg(scene)

depict

depict(spec: DepictSpecLike) -> list[Rendered]

One Rust render: layout, mol-spec paint, pack cells.

Source code in python/xpict/depict_spec.py
def depict(spec: DepictSpecLike) -> list[Rendered]:
    """One Rust ``render``: layout, mol-spec paint, pack cells."""
    doc = as_depict_spec(spec)
    painted = _native_depict(doc)
    return [as_rendered(row) for row in painted]

Single molecule

xpict.spec

Host DepictSpec + single-mol sugar (mol / render).

render module-attribute

render = render_mol

Mol dataclass

Mol(
    source: str,
    frame_molblock: str | None = None,
    id: str | None = None,
    align_to: str | None = None,
    label: str | None = None,
    label_pos: LabelPos | None = None,
    label_color: str | None = None,
    label_scale: float | None = None,
)

Bases: PictBase

Input molecule — SMILES / CXSMILES / molfile plus optional align frame.

source instance-attribute

source: str

frame_molblock class-attribute instance-attribute

frame_molblock: str | None = None

id class-attribute instance-attribute

id: str | None = None

align_to class-attribute instance-attribute

align_to: str | None = None

label class-attribute instance-attribute

label: str | None = None

label_pos class-attribute instance-attribute

label_pos: LabelPos | None = None

label_color class-attribute instance-attribute

label_color: str | None = None

label_scale class-attribute instance-attribute

label_scale: float | None = None

render

render(opts: MolRenderOptions | None = None) -> Rendered
Source code in python/xpict/spec.py
def render(self, opts: MolRenderOptions | None = None) -> Rendered:
    return render_mol(self, opts)

ensure_frame

ensure_frame() -> str
Source code in python/xpict/spec.py
def ensure_frame(self) -> str:
    if not self.frame_molblock:
        self.frame_molblock = render_mol(self).frame_molblock
    return self.frame_molblock

with_label

with_label(
    text: str,
    *,
    pos: LabelPos | None = None,
    color: str | None = None,
    scale: float | None = None,
) -> Mol

Return a copy with a caption (mol(..., name=...) equivalent).

Source code in python/xpict/spec.py
def with_label(
    self,
    text: str,
    *,
    pos: LabelPos | None = None,
    color: str | None = None,
    scale: float | None = None,
) -> Mol:
    """Return a copy with a caption (``mol(..., name=...)`` equivalent)."""
    return replace(
        self,
        label=text,
        label_pos=pos,
        label_color=color if color is not None else self.label_color,
        label_scale=scale if scale is not None else self.label_scale,
    )

to_node

to_node(id: str | None = None) -> MolNode

Build a MolNode from this source (smiles / cxsmiles / molfile).

Source code in python/xpict/spec.py
def to_node(self, id: str | None = None) -> MolNode:
    """Build a ``MolNode`` from this source (smiles / cxsmiles / molfile)."""
    text = self.source.strip()
    if "V2000" in text or "V3000" in text or text.count("\n") >= 3:
        kind_fields = {"molfile": text}
    elif "|" in text:
        kind_fields = {"cxsmiles": text}
    else:
        kind_fields = {"smiles": text}
    nid = self.id if id is None else id
    node = MolNode.model_validate(
        {"id": nid, "align_to": self.align_to, **kind_fields}
    )
    cap = (self.label or "").strip()
    if not cap:
        return node
    mid = (node.id or "m_0").strip() or "m_0"
    # Privileged wire ``name`` — default side below (handled in Rust).
    if (
        self.label_pos is not None
        or self.label_color is not None
        or self.label_scale is not None
    ):
        name: str | MolTextSpec = MolTextSpec(
            content=cap,
            pos=self.label_pos,
            color=self.label_color,
            scale=self.label_scale,
        )
    else:
        name = cap
    return node.model_copy(update={"id": mid, "name": name})

to_caption_nodes

to_caption_nodes(id: str | None = None) -> list[MolNode]

Lone mol node (caption lives on MolNode.name, not a sibling text).

Source code in python/xpict/spec.py
def to_caption_nodes(self, id: str | None = None) -> list[MolNode]:
    """Lone mol node (caption lives on ``MolNode.name``, not a sibling text)."""
    return [self.to_node(id=id)]

to_spec

to_spec(opts: MolRenderOptions | None = None) -> DepictSpec

Document for paint — identity on the mol; cascade via .opts bag.

Source code in python/xpict/spec.py
def to_spec(self, opts: MolRenderOptions | None = None) -> DepictSpec:
    """Document for paint — identity on the mol; cascade via ``.opts`` bag."""
    if opts is None:
        return DepictSpec(self.to_node())
    shade = opts.shade_scores()

    overlay: dict[str, object] = {}
    if opts.star_labels is not None:
        overlay["star_labels"] = opts.star_labels
    if shade is not None:
        overlay["shade"] = shade
    if opts.circle is not None:
        overlay["circle"] = opts.circle

    if opts.align_to is None:
        node = self.to_node(id=opts.id)
        if overlay:
            node = node.model_copy(update=overlay)
        doc = DepictSpec(node)
    else:
        ref = opts.reference_mol()
        ref_id = ref.id or "m_0"
        qid = opts.id or self.id or "m_1"
        if qid == ref_id:
            qid = "m_1"
        query = self.to_node(id=qid).model_copy(
            update={
                "align_to": opts.align_wire(),
                **overlay,
            }
        )
        doc = DepictSpec(
            GroupNode(
                type="group",
                align=False,
                children=[ref.to_node(id=ref_id), query],
            )
        )

    kw = opts.cascade_keywords()
    return DepictSpec(doc.opts(**kw).root) if kw else doc

MolRenderOptions dataclass

MolRenderOptions(
    id: str | None = None,
    color: str | None = None,
    atom_shade: list[float] | None = None,
    bond_shade: list[float] | None = None,
    circle: CircleField | None = None,
    star_labels: list[str | None] | None = None,
    weight: float | None = None,
    scale: float | None = None,
    aromatic: AromaticStyle | None = None,
    debug_box: bool | None = None,
    debug_align: bool | None = None,
    align_to: Mol | Rendered | None = None,
    atom_map: list[tuple[int, int]] | None = None,
)

Render options — parity with JS / Rust MolRenderOptions.

id class-attribute instance-attribute

id: str | None = None

color class-attribute instance-attribute

color: str | None = None

atom_shade class-attribute instance-attribute

atom_shade: list[float] | None = None

bond_shade class-attribute instance-attribute

bond_shade: list[float] | None = None

circle class-attribute instance-attribute

circle: CircleField | None = None

star_labels class-attribute instance-attribute

star_labels: list[str | None] | None = None

weight class-attribute instance-attribute

weight: float | None = None

scale class-attribute instance-attribute

scale: float | None = None

aromatic class-attribute instance-attribute

aromatic: AromaticStyle | None = None

debug_box class-attribute instance-attribute

debug_box: bool | None = None

debug_align class-attribute instance-attribute

debug_align: bool | None = None

align_to class-attribute instance-attribute

align_to: Mol | Rendered | None = None

atom_map class-attribute instance-attribute

atom_map: list[tuple[int, int]] | None = None

cascade_keywords

cascade_keywords() -> OptsKeywords

Universal MolOpts keys for the document opts bag.

Source code in python/xpict/spec.py
def cascade_keywords(self) -> OptsKeywords:
    """Universal ``MolOpts`` keys for the document ``opts`` bag."""
    out: OptsKeywords = {}
    for key in (
        "color",
        "weight",
        "scale",
        "aromatic",
        "debug_box",
        "debug_align",
    ):
        val = getattr(self, key)
        if val is not None:
            out[key] = val  # type: ignore[literal-required]
    return out

shade_scores

shade_scores() -> ShadeSpec | None

Non-cascading per-atom / per-bond scores (leaf MolNode.shade).

Source code in python/xpict/spec.py
def shade_scores(self) -> ShadeSpec | None:
    """Non-cascading per-atom / per-bond scores (leaf ``MolNode.shade``)."""
    if self.atom_shade is None and self.bond_shade is None:
        return None
    return ShadeSpec(atoms=self.atom_shade, bonds=self.bond_shade)

reference_mol

reference_mol() -> Mol

align_to as a Mol (unwraps Rendered).

Source code in python/xpict/spec.py
def reference_mol(self) -> Mol:
    """``align_to`` as a ``Mol`` (unwraps ``Rendered``)."""
    if self.align_to is None:
        raise ValueError("align_to is required")
    if isinstance(self.align_to, Rendered):
        back = self.align_to.mol
        return back if isinstance(back, Mol) else mol(self.align_to.source)
    return self.align_to

align_wire

align_wire() -> AlignTo | None
Source code in python/xpict/spec.py
def align_wire(self) -> AlignTo | None:
    if self.align_to is None:
        return None
    if self.atom_map is not None:
        ref = self.align_to
        if isinstance(ref, Rendered):
            back = ref.mol
            rid = (
                (back.id if isinstance(back, Mol) else None)
                or ref.molecule.id
                or "m_0"
            )
        else:
            rid = ref.id or "m_0"
        return AlignToSpec(
            ref=str(rid),
            atom_map=[(int(q), int(r)) for q, r in self.atom_map],
        )
    if isinstance(self.align_to, Rendered):
        back = self.align_to.mol
        if isinstance(back, Mol) and back.id:
            return str(back.id)
        mid = self.align_to.molecule.id
        return str(mid) if mid else "m_0"
    return self.align_to.id or "m_0"

mol

mol(
    smiles_or_molfile: str,
    *,
    id: str | None = None,
    align_to: str | None = None,
    name: str | None = None,
    label: str | None = None,
    label_pos: LabelPos | None = None,
    label_color: str | None = None,
    label_scale: float | None = None,
) -> Mol

Construct a Mol (JS / Rust xpict.mol).

name (preferred) / label (alias) set wire MolNode.name — painted inside the mol SVG by Rust. Default side is below; optional label_pos / color / scale map onto styled MolText.

Source code in python/xpict/spec.py
def mol(
    smiles_or_molfile: str,
    *,
    id: str | None = None,
    align_to: str | None = None,
    name: str | None = None,
    label: str | None = None,
    label_pos: LabelPos | None = None,
    label_color: str | None = None,
    label_scale: float | None = None,
) -> Mol:
    """Construct a ``Mol`` (JS / Rust ``xpict.mol``).

    ``name`` (preferred) / ``label`` (alias) set wire ``MolNode.name`` — painted
    inside the mol SVG by Rust. Default side is below; optional ``label_pos`` /
    color / scale map onto styled ``MolText``.
    """
    text = smiles_or_molfile.strip()
    if not text:
        raise ValueError("mol() requires a non-empty SMILES or molfile")
    if name is not None and label is not None and name != label:
        raise ValueError("mol() got both name= and label=; use only one")
    caption = name if name is not None else label
    return Mol(
        source=text,
        id=id,
        align_to=align_to,
        label=caption,
        label_pos=label_pos,
        label_color=label_color,
        label_scale=label_scale,
    )

Contracts (document)

xpict.contracts.depict

DepictSpec — live document ABI from xpict-core (schemars).

DepictSpec

Bases: RootModel[DepictSpecRoot]

Declarative document (mol, group, reaction_scheme, or grid root).

model_dump

model_dump(*args, **kwargs)
Source code in python/xpict/contracts/depict.py
def model_dump(self, *args, **kwargs):
    kwargs.setdefault('exclude_none', True)
    return super().model_dump(*args, **kwargs)

model_dump_json

model_dump_json(*args, **kwargs)
Source code in python/xpict/contracts/depict.py
def model_dump_json(self, *args, **kwargs):
    kwargs.setdefault('exclude_none', True)
    return super().model_dump_json(*args, **kwargs)

MolNode

Bases: StrictModel

Mol node — [MolOpts] fields + non-cascading identity / scores / align.

type class-attribute instance-attribute

type: Literal['mol'] = 'mol'

align_to class-attribute instance-attribute

align_to: Annotated[
    AlignTo | None,
    Field(
        description='Template id string, or `{ "ref", "atom_map"?, "min_atoms"?, "mode"?, "timeout_ms"? }`.'
    ),
] = None

aromatic class-attribute instance-attribute

aromatic: Annotated[
    AromaticStyle | None,
    Field(
        description="Aromatic ring paint: ``circle`` (default) or ``kekule``."
    ),
] = None

atom_label class-attribute instance-attribute

atom_label: Annotated[
    AtomLabelSpec | None,
    Field(
        description='Per-atom arbitrary text map (`{ "1": "α" }` or `{ "labels": {…}, "scale"? }`).'
    ),
] = None

atom_number class-attribute instance-attribute

atom_number: Annotated[
    AtomNumberSpec | None,
    Field(
        description='Atom index / map-number labels (`"index"` | `"mapno"` | policy object).'
    ),
] = None

callout class-attribute instance-attribute

callout: Annotated[
    CalloutField | None,
    Field(description="Callout annotation(s)."),
] = None

circle class-attribute instance-attribute

circle: Annotated[
    CircleField | None,
    Field(
        description="Atom / bond / ring highlight circle(s)."
    ),
] = None

color class-attribute instance-attribute

color: str | None = None

cxsmiles class-attribute instance-attribute

cxsmiles: str | None = None

debug_align class-attribute instance-attribute

debug_align: Annotated[
    bool | None,
    Field(
        description="Paint alignment correspondence (matched atom tags + mol role badge)."
    ),
] = None

debug_box class-attribute instance-attribute

debug_box: Annotated[
    bool | None,
    Field(
        description="Paint dashed debug rectangles for layout boxes (labels / mol / scene)."
    ),
] = None

halo class-attribute instance-attribute

halo: bool | None = None

id class-attribute instance-attribute

id: str | None = None

label class-attribute instance-attribute

label: Annotated[
    Label | None,
    Field(
        description="Caption: [`Label`] (string id, list, or `{id, pos?}` — text-node refs)."
    ),
] = None

molfile class-attribute instance-attribute

molfile: str | None = None

name class-attribute instance-attribute

name: Annotated[
    MolText | None,
    Field(
        description="Privileged figure name / caption painted inside the mol SVG (default below)."
    ),
] = None

opts class-attribute instance-attribute

opts: Annotated[
    Opts | None,
    Field(
        description="Cascade patches for this node (list or singleton)."
    ),
] = None

pad class-attribute instance-attribute

pad: Annotated[
    float | None,
    Field(
        description="Post-layout SVG viewBox pad (px). Omit → small house default (rarely override)."
    ),
] = None

region class-attribute instance-attribute

region: Annotated[
    RegionField | None,
    Field(
        description="Region highlight(s) — one object or a list."
    ),
] = None

scale class-attribute instance-attribute

scale: float | None = None

shade class-attribute instance-attribute

shade: Annotated[
    ShadeSpec | None,
    Field(
        description="Shade **scores** (+ legacy window); window also cascades via [`Opts`]."
    ),
] = None

smiles class-attribute instance-attribute

smiles: str | None = None

star_labels class-attribute instance-attribute

star_labels: list[str | None] | None = None

weight class-attribute instance-attribute

weight: float | None = None

GroupNode

Bases: StrictModel

type class-attribute instance-attribute

type: Literal['group'] = 'group'

align class-attribute instance-attribute

align: bool = Field(
    default=False,
    description="When true, later children align onto the first (or each `align_to`).",
)

aromatic class-attribute instance-attribute

aromatic: AromaticStyle | None = None

children class-attribute instance-attribute

children: list[Node] = Field(
    default_factory=list,
    description="Child **nodes** — mol | text (no edges).",
)

color class-attribute instance-attribute

color: str | None = None

debug_align class-attribute instance-attribute

debug_align: Annotated[
    bool | None,
    Field(
        description="Paint alignment correspondence (matched atom tags + mol role badge)."
    ),
] = None

debug_box class-attribute instance-attribute

debug_box: bool | None = None

id class-attribute instance-attribute

id: str | None = None

opts class-attribute instance-attribute

opts: Annotated[
    Opts | None,
    Field(
        description="Group-level cascade bag (list container for child inheritance)."
    ),
] = None

pad class-attribute instance-attribute

pad: Annotated[
    float | None,
    Field(
        description="Post-layout SVG viewBox pad (px). Omit → small house default."
    ),
] = None

scale class-attribute instance-attribute

scale: float | None = None

Engine

xpict.api

Public Pict / render API — native Rust depict only (no layout backends).

Pict

Pict(*, format: OutputFormat = 'svg')

Native Rust depiction engine (no layout-backend switch).

Source code in python/xpict/api.py
def __init__(self, *, format: OutputFormat = "svg") -> None:
    self.format: OutputFormat = format

layout

layout(spec: DepictInput) -> list[MoleculeIn]

Lay out molecules via Rust depict (MoleculeIn from painted rows).

Source code in python/xpict/api.py
def layout(self, spec: DepictInput) -> list[MoleculeIn]:
    """Lay out molecules via Rust ``depict`` (``MoleculeIn`` from painted rows)."""
    return [r.molecule for r in depict(to_live_depict(spec))]

render

render(
    spec: DepictInput, *, format: OutputFormat = "svg"
) -> str

Shorthand for Pict(format=...).render(spec).

Source code in python/xpict/api.py
def render(
    spec: DepictInput,
    *,
    format: OutputFormat = "svg",
) -> str:
    """Shorthand for ``Pict(format=...).render(spec)``."""
    return Pict(format=format).render(spec)