Code Monkey home page Code Monkey logo

factur-x-ng's Introduction

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 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:

  • Edit and save existing XML metadata fields.
  • Create new XML representation from template and embed in PDF.
  • Add existing XML representation to PDF.
  • Validate existing XML representation.

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:

  • Dump embedded metadata: facturx dump file-with-xml.pdf metadata.(xml|json|yml)
  • Validate existing metadata: facturx validate file-with-xml.pdf
  • Add external metadata file: facturx add no-xml.pdf metadata.xml
  • Extract fields from PDF and embed: facturx extract no-xml.pdf

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 on which this lib depends).

Contributors

  • Alexis de Lattre [email protected]: Initial version, PDF- and XMP processing.
  • Manuel Riel: Python 3 support, support for editing individual fields, separate support for different standards

factur-x-ng's People

Contributors

m3nu avatar alexis-via avatar duskybomb avatar adit-negi avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.