From 0027e6d4257ae252c8440968a3fdb744e2fcce5e Mon Sep 17 00:00:00 2001 From: Kenny Zhang Date: Tue, 18 Feb 2025 12:44:18 -0500 Subject: [PATCH] added wrapper class for converter file input --- packages/markitdown/src/markitdown/__init__.py | 2 ++ packages/markitdown/src/markitdown/_input.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 packages/markitdown/src/markitdown/_input.py diff --git a/packages/markitdown/src/markitdown/__init__.py b/packages/markitdown/src/markitdown/__init__.py index 59d9750..53a4e5e 100644 --- a/packages/markitdown/src/markitdown/__init__.py +++ b/packages/markitdown/src/markitdown/__init__.py @@ -10,6 +10,7 @@ from ._exceptions import ( FileConversionException, UnsupportedFormatException, ) +from ._input import ConverterInput from .converters import DocumentConverter, DocumentConverterResult __all__ = [ @@ -21,4 +22,5 @@ __all__ = [ "ConverterPrerequisiteException", "FileConversionException", "UnsupportedFormatException", + "ConverterInput", ] diff --git a/packages/markitdown/src/markitdown/_input.py b/packages/markitdown/src/markitdown/_input.py new file mode 100644 index 0000000..858f3b1 --- /dev/null +++ b/packages/markitdown/src/markitdown/_input.py @@ -0,0 +1,18 @@ +from typing import Any, Union + +class ConverterInput: + """ + Wrapper for inputs to converter functions. + """ + def __init__( + self, + input_type: str = "filepath", + filepath: Union[str, None] = None, + file_object: Union[Any, None] = None, + ): + if input_type not in ["filepath", "object"]: + raise ValueError(f"Invalid converter input type: {input_type}") + + self.input_type = input_type + self.filepath = filepath + self.file_object = file_object \ No newline at end of file