Skip to content

Source API

Signatures and documentation are read from the current Python source during the build.

vexy_lines.parser

Parse Vexy Lines .lines XML files into typed dataclasses.

A .lines file contains the full project: layer tree (groups, layers, fills), document properties, and two optional embedded images.

Embedded image encodings: - Source image: base64( 4-byte BE uint32 uncompressed-size + zlib(JPEG) ) - Preview image: base64( raw PNG )

The public API is three functions: :func:parse, :func:extract_source_image, and :func:extract_preview_image.

extract_preview_image(path, output)

Parse a .lines file and save its embedded preview image as PNG.

Args: path: Path to the .lines file. output: Destination path for the PNG file.

Returns: The resolved output :class:~pathlib.Path.

Raises: FileNotFoundError: If path does not exist. ValueError: If no preview image is embedded in the file.

Source code in src/vexy_lines/parser.py
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
def extract_preview_image(path: str | Path, output: str | Path) -> Path:
    """Parse a ``.lines`` file and save its embedded preview image as PNG.

    Args:
        path: Path to the ``.lines`` file.
        output: Destination path for the PNG file.

    Returns:
        The resolved output :class:`~pathlib.Path`.

    Raises:
        FileNotFoundError: If *path* does not exist.
        ValueError: If no preview image is embedded in the file.
    """
    doc = parse(path)
    return _write_extracted_image(
        doc.preview_image_data,
        output,
        missing_message=f"No preview image found in {path}",
        image_label="preview image",
    )

extract_source_image(path, output)

Parse a .lines file and save its embedded source image as JPEG.

Args: path: Path to the .lines file. output: Destination path for the JPEG file.

Returns: The resolved output :class:~pathlib.Path.

Raises: FileNotFoundError: If path does not exist. ValueError: If no source image is embedded in the file.

Source code in src/vexy_lines/parser.py
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
def extract_source_image(path: str | Path, output: str | Path) -> Path:
    """Parse a ``.lines`` file and save its embedded source image as JPEG.

    Args:
        path: Path to the ``.lines`` file.
        output: Destination path for the JPEG file.

    Returns:
        The resolved output :class:`~pathlib.Path`.

    Raises:
        FileNotFoundError: If *path* does not exist.
        ValueError: If no source image is embedded in the file.
    """
    doc = parse(path)
    return _write_extracted_image(
        doc.source_image_data,
        output,
        missing_message=f"No source image found in {path}",
        image_label="source image",
    )

extract_source_images(path, output_dir)

Extract all document and group source images from a .lines file.

Args: path: Path to the .lines file. output_dir: Directory where JPEG files will be written.

Returns: Output paths in extraction order. The document source is first when present, followed by group sources in XML traversal order.

Raises: FileNotFoundError: If path does not exist. ValueError: If no source images are embedded in the file.

Source code in src/vexy_lines/parser.py
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
def extract_source_images(path: str | Path, output_dir: str | Path) -> list[Path]:
    """Extract all document and group source images from a ``.lines`` file.

    Args:
        path: Path to the ``.lines`` file.
        output_dir: Directory where JPEG files will be written.

    Returns:
        Output paths in extraction order. The document source is first when
        present, followed by group sources in XML traversal order.

    Raises:
        FileNotFoundError: If *path* does not exist.
        ValueError: If no source images are embedded in the file.
    """
    source_path = Path(path)
    doc = parse(source_path)
    if not doc.source_images:
        msg = f"No source images found in {path}"
        raise ValueError(msg)

    out_dir = Path(output_dir)
    out_dir.mkdir(parents=True, exist_ok=True)
    outputs: list[Path] = []
    for image in doc.source_images:
        label = _source_filename_part(image)
        output = out_dir / f"{source_path.stem}-source-{image.index:03d}-{label}.jpg"
        output.write_bytes(image.data)
        outputs.append(output)
        logger.info(f"Saved source image {image.index} ({len(image.data)} bytes) -> {output}")
    return outputs

parse(path)

Parse a .lines file and return a :class:~vexy_lines.types.LinesDocument.

This is the main entry point for file-based parsing. The operation is entirely offline: no network access, no Vexy Lines app, and no platform-specific libraries are required. Corrupt or missing embedded images (<SourcePict>, <PreviewDoc>) are handled gracefully — a warning is logged and the corresponding field is set to None rather than raising an exception.

Args: path: Path to the .lines file (str or Path).

Returns: Fully populated :class:~vexy_lines.types.LinesDocument.

Raises: FileNotFoundError: If path does not exist. ET.ParseError: If the file is not valid XML (e.g. truncated or corrupt at the XML level).

Source code in src/vexy_lines/parser.py
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
def parse(path: str | Path) -> LinesDocument:
    """Parse a ``.lines`` file and return a :class:`~vexy_lines.types.LinesDocument`.

    This is the main entry point for file-based parsing.  The operation is
    **entirely offline**: no network access, no Vexy Lines app, and no
    platform-specific libraries are required.  Corrupt or missing embedded
    images (``<SourcePict>``, ``<PreviewDoc>``) are handled gracefully — a
    warning is logged and the corresponding field is set to ``None`` rather
    than raising an exception.

    Args:
        path: Path to the ``.lines`` file (str or Path).

    Returns:
        Fully populated :class:`~vexy_lines.types.LinesDocument`.

    Raises:
        FileNotFoundError: If *path* does not exist.
        ET.ParseError: If the file is not valid XML (e.g. truncated or corrupt
            at the XML level).
    """
    path = Path(path)
    if not path.exists():
        msg = f"File not found: {path}"
        raise FileNotFoundError(msg)

    logger.debug(f"Parsing .lines file: {path}")
    tree = ET.parse(path)  # noqa: S314
    return _parse_root(tree.getroot())

parse_string(xml)

Parse a .lines XML string and return a :class:~vexy_lines.types.LinesDocument.

Use this when you already have the XML content in memory (e.g. from a network response or database) instead of a file path.

Args: xml: Raw XML string from a .lines file.

Returns: Fully populated :class:~vexy_lines.types.LinesDocument.

Raises: ET.ParseError: If xml is not valid XML.

Source code in src/vexy_lines/parser.py
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
def parse_string(xml: str) -> LinesDocument:
    """Parse a ``.lines`` XML string and return a :class:`~vexy_lines.types.LinesDocument`.

    Use this when you already have the XML content in memory
    (e.g. from a network response or database) instead of a file path.

    Args:
        xml: Raw XML string from a ``.lines`` file.

    Returns:
        Fully populated :class:`~vexy_lines.types.LinesDocument`.

    Raises:
        ET.ParseError: If *xml* is not valid XML.
    """
    logger.debug("Parsing .lines XML string")
    root = ET.fromstring(xml)  # noqa: S314
    return _parse_root(root)