Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

Merger Plugin API

Python PyPI

Interfaces and data models for extending the merger-cli tool with custom parsers and exporters.

This package provides:

  • Abstract base classes for custom Parsers and Exporters.
  • Data models for the File Tree structure.
  • Type definitions for seamless integration with merger-cli.

Compatibility

The merger-plugin-api is designed to be highly compatible to allow plugin developers to use a variety of environments.

  • Supported Python Versions: 3.8, 3.9, 3.10, and 3.11.

Installation

pip install merger-plugin-api

Creating Plugins

Plugins are standalone Python modules that define a Parser or TreeExporter class.

Custom Parsers

To support non-text file formats (e.g., PDF, Images), implement a custom parser. More complete examples like this one are available in the examples/parsers/ directory.

Here is an example of a PDF parser using pymupdf:

from pathlib import Path
from typing import Union, Optional, Set, Type

import pymupdf
from merger_plugin_api import Parser

# Optional: List of Python packages required for this plugin
REQUIREMENTS = ["pymupdf"]

# File extensions this parser supports
EXTENSIONS: Set[str] = {".pdf"}


class PdfParser(Parser):
    MAX_BYTES_FOR_VALIDATION: Optional[int] = None

    @classmethod
    def validate(
        cls,
        file_chunk_bytes: Union[bytes, bytearray],
        file_path: Path
    ) -> bool:
        """
        Validate that the given file bytes represent a readable PDF document.
        """
        try:
            with pymupdf.open(stream=file_chunk_bytes) as doc:
                _ = doc[0]
            return True

        except Exception:
            return False

    @classmethod
    def parse(
        cls,
        file_bytes: Union[bytes, bytearray],
        file_path: Path,
    ) -> str:
        """
        Extracts and concatenates text from all pages of a PDF file.
        """
        texts = []
        with pymupdf.open(stream=file_bytes) as doc:
            for page in doc:
                text = page.get_text()
                if text:
                    text = text.replace("\n\n", "")
                    texts.append(text)

        full_text = " ".join(texts)
        return full_text


# Export the parser class
parser_cls: Type[Parser] = PdfParser

Custom Exporters

To output the merged data in a custom format (e.g., XML, Markdown), implement a TreeExporter. More complete examples like this one are available in the examples/exporters/ directory.

Here is an example of an XML exporter:

import xml.etree.ElementTree as ET
from typing import Type
from merger_plugin_api import FileEntry, DirectoryEntry, FileTreeEntry, TreeExporter, FileTree

# The name of the exporter (used in --exporter argument)
NAME = "XML"
# The extension of the output file
FILE_EXTENSION = ".xml"

class XmlExporter(TreeExporter):
    """
    A custom exporter that generates an XML representation of the file tree.
    """

    @classmethod
    def export(cls, tree: FileTree) -> bytes:
        """
        Export the file tree into an XML representation.
        """
        root = ET.Element("filetree")
        cls._to_xml(tree.root, root)

        cls._indent(root)

        return ET.tostring(root, encoding="utf-8", xml_declaration=True)

    @classmethod
    def _to_xml(cls, entry: FileTreeEntry, parent: ET.Element):
        if isinstance(entry, FileEntry):
            file_el = ET.SubElement(parent, "file", {
                "name": entry.name,
                "path": entry.path.as_posix()
            })
            content_el = ET.SubElement(file_el, "content")
            content_el.text = entry.content

        elif isinstance(entry, DirectoryEntry):
            dir_el = ET.SubElement(parent, "directory", {
                "name": entry.name,
                "path": entry.path.as_posix()
            })
            for child in sorted(entry.children.values(), key=lambda e: e.name.lower()):
                cls._to_xml(child, dir_el)

    @classmethod
    def _indent(cls, elem: ET.Element, level: int = 0):
        """
        Recursive function to indent XML elements while preserving text content.
        """
        i = "\n" + level * "  "
        if len(elem):
            if not elem.text or not elem.text.strip():
                elem.text = i + "  "

            if not elem.tail or not elem.tail.strip():
                elem.tail = i

            for child in elem:
                cls._indent(child, level + 1)

            if len(elem) > 0:
                last_child = elem[-1]
                if not last_child.tail or not last_child.tail.strip():
                    last_child.tail = i

        else:
            if level and (not elem.tail or not elem.tail.strip()):
                elem.tail = i

# Export the exporter class
exporter_cls: Type[TreeExporter] = XmlExporter

Data Models

The FileTree object represents the hierarchical structure of the scanned directory.

FileTree

  • root: A DirectoryEntry representing the scan root.

DirectoryEntry

  • name: Name of the directory.
  • path: pathlib.Path relative to the scan root.
  • children: A dictionary mapping names to FileTreeEntry (FileEntry or DirectoryEntry).

FileEntry

  • name: Name of the file.
  • path: pathlib.Path relative to the scan root.
  • content: The parsed text content of the file.
  • extension: File extension (including the dot).

Using Your Plugins

Once you have implemented your plugin, install it via the CLI:

merger --install-plugin path/to/your_plugin.py

Merger will automatically detect if it's a parser or exporter and install any listed REQUIREMENTS using its internal uv manager.

For more information, visit the main repository.

Metadata

Release files for merger-plugin-api 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for merger-plugin-api 1.0.0
File Size Uploaded Provenance Actions
merger_plugin_api-1.0.0.tar.gz 44.1 kB With provenance Details for merger_plugin_api-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for merger-plugin-api 1.0.0
File Interpreter ABI Platform Actions
merger_plugin_api-1.0.0-py3-none-any.whl Python 3 none any Details for merger_plugin_api-1.0.0-py3-none-any.whl

Total release size: 75.0 kB

Release files / merger_plugin_api-1.0.0.tar.gz

Download URL merger_plugin_api-1.0.0.tar.gz
Size 44.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c540ea8539a91ef69ab10a8b3d932a7dffa3e430afa89e445cd758eb02c2a68b
BLAKE2b-256 checksum
How to use checksums
f7755146ea0fa36940bbbda44cc44715bc3ceeb658a95cdfe71d3f9926f8e158
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 2, 2026.

Transparency log

Release files / merger_plugin_api-1.0.0-py3-none-any.whl

Download URL merger_plugin_api-1.0.0-py3-none-any.whl
Size 30.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb7a09d42d68b63cc503ac9a5d09f50f315eaa3aab26b70aa175ca9bc8b0d4fb
BLAKE2b-256 checksum
How to use checksums
bd4914521b79623e86dd5e7525b5587738c65d1e00bd09d1f2b14f0e50490f3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 2, 2026.

Transparency log

Security for merger-plugin-api 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for merger_plugin_api-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page