Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Invoice2Data class for object oriented usage #480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/invoice2data/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .main import extract_data # noqa: F401
from .main import Invoice2Data # noqa: F401
13 changes: 13 additions & 0 deletions src/invoice2data/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@
output_mapping = {"csv": to_csv, "json": to_json, "xml": to_xml, "none": None}


class Invoice2Data:
def __init__(self, load_built_in_templates=True):
self.templates = []
if load_built_in_templates:
self.templates += read_templates()

def read_templates(self, path):
self.templates += read_templates(os.path.abspath(path))

def extract_data(self, path, input_module=None):
return extract_data(path, self.templates, input_module)


def extract_data(invoicefile, templates=None, input_module=None):
"""Extracts structured data from PDF/image invoices.

Expand Down