invoice-x / factur-x-ng

Python lib for Factur-X, the e-invoicing standard for France and Germany
Other
34 stars 8 forks source link

Factur-X Python library

Factur-X is a EU standard for embedding XML representations of invoices in PDF files. This library provides an interface for reading, editing and saving the this metadata.

Since there are multiple flavors of the embedded XML data, this library abstracts them into a Python dict, which can be used to load and save from/to different flavors.

This project was forked from Akretion <https://github.com/akretion/factur-x>_ and continues to be under the same license. We aim to make the library higher-level, make editing fields easier and support more standards and flavors.

Main features:

Installation

::

pip install PyPDF2 lxml pyyaml pycountry pip install --index-url https://test.pypi.org/simple/ --upgrade factur-x-ng

::

Usage

Load PDF file without XML and assign some values to common fields.

::

from facturx import FacturX

inv = FacturX('some-file.pdf') inv['due_date'] = datetime(2018, 10, 10) inv['seller.name'] = 'Smith Ltd.' inv['buyer.country'] = 'France'

Validate and save PDF including XML representation.

::

inv.is_valid() inv.write_pdf('my-file.pdf')

Load PDF with XML embedded. View and update fields via pivot dict.

::

inv = FacturX('another-file.pdf') inv_dict = inv.as_dict() inv_dict['currency'] = 'USD' inv.update(inv_dict)

Save XML metadata in separate file in different formats.

::

inv.write_xml('metadata.xml') inv.write_json('metadata.json') inv.write_yaml('metadata.yml')

To have more examples, look at the source code of the command line tools located in the bin subdirectory.

Command line tools

Several sub-commands are provided with this lib:

All these command line tools have a -h option that explains how to use them and shows all the available options.

Licence

This library is published under the BSD licence (same licence as PyPDF2 <http://mstamy2.github.io/PyPDF2/>__ on which this lib depends).

Contributors