1. Home
  2. UAE E-Invoicing Hub
  3. Custom ERP & Integration

Custom ERP & Integration

Adding UAE E-Invoicing to a Python or Django Application

Python billing systems are common in UAE startups and SaaS platforms. The pipeline is straightforward; the schematron step needs the right tooling.

SZ
Sahil ZainiCRM & ERP Development
·2026-11-24·3 min read
Updated 24 Nov 2026 · checked against MoF Guidelines v2.0

A Django or FastAPI billing system can produce PINT AE documents with lxml templates or a UBL object layer, validate them against UBL XSDs with lxml and against the PINT AE schematron by executing the compiled XSLT with Saxon-HE (via saxonche) or by calling a validation service, submit through an Accredited Service Provider's API from a Celery task with retries, and store acknowledgements in a status model. Celery with a durable broker gives the queueing behaviour the regulations assume.

Key facts at a glance

  • XML: lxml for generation and XSD validation.
  • Schematron: compile to XSLT and run with saxonche, or use a small validation microservice.
  • Queue: Celery with RabbitMQ or Redis; acks_late and retries with back-off.
  • Provider adapter: a class per ASP behind a common interface; credentials from environment.
  • Status: webhook view + periodic beat task for polling.

Generating the document

from lxml import etree
NS = {'cbc': 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2',
      'cac': 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2'}

def build_invoice(inv):
    root = etree.Element('{urn:oasis:names:specification:ubl:schema:xsd:Invoice-2}Invoice', nsmap={None: 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2', **NS})
    sub(root, 'cbc:CustomizationID', PINT_AE_CUSTOMIZATION_ID)
    sub(root, 'cbc:ID', inv.number)
    sub(root, 'cbc:IssueDate', inv.issued_on.isoformat())
    sub(root, 'cbc:InvoiceTypeCode', '380')
    sub(root, 'cbc:DocumentCurrencyCode', inv.currency)
    root.append(party('AccountingSupplierParty', inv.company))   # EndpointID schemeID 0235
    root.append(party('AccountingCustomerParty', inv.customer))
    ...
    return etree.tostring(root, xml_declaration=True, encoding='UTF-8')

Keep element order exactly as the UBL schema requires; lxml will not reorder for you, and schema validation will fail on misplaced elements.

Validating

schema = etree.XMLSchema(etree.parse('UBL-Invoice-2.1.xsd'))
schema.assertValid(etree.fromstring(xml))        # raises on schema errors

from saxonche import PySaxonProcessor
with PySaxonProcessor(license=False) as proc:
    xslt = proc.new_xslt30_processor().compile_stylesheet(stylesheet_file='pint-ae.xsl')
    svrl = xslt.transform_to_string(xdm_node=proc.parse_xml(xml_text=xml.decode()))
fatal = parse_svrl_fatal(svrl)

Compile the stylesheet once per worker process. The compiled PINT AE XSLT is produced from the published schematron with the standard ISO schematron skeleton.

Submitting from Celery

@shared_task(bind=True, acks_late=True, autoretry_for=(TransientAspError,),
             retry_backoff=60, retry_backoff_max=3600, max_retries=10)
def submit_einvoice(self, invoice_id):
    inv = Invoice.objects.select_for_update().get(pk=invoice_id)
    asp = get_asp_adapter(inv.company)
    res = asp.submit(inv.xml, idempotency_key=inv.number)
    Ack.objects.create(invoice=inv, kind='provider_accepted', payload=res.raw)

Operating it

IdempotencyDocument number as the key; make the task safe to run twice.
MonitoringPrometheus metrics for queue depth and rejection rate; alert on queue age > 1 hour.
ControlsDjango permissions for release; signals that block edits after submission.
ArchiveObject storage with versioning; store SHA-256 on the model.

Where Zaini Developers fits in

We have delivered this stack for SaaS platforms that invoice on behalf of many businesses: multi-tenant, per-tenant provider credentials, and a shared validation service so every tenant's documents are checked before they leave.

Book a free consultation →

Frequently asked questions

Is there a Python library for PINT AE?

No widely adopted one yet. lxml plus the public schemas and schematron covers generation and validation; our team can supply a reference implementation.

Can I validate without Saxon?

Options include executing the schematron XSLT with another XSLT 2/3 processor or calling a validation microservice (for example our PHP engine over HTTP).

Does FastAPI change anything?

No. Replace Celery with your preferred task runner and the Django ORM with your persistence layer; the pipeline is the same.

How do SaaS platforms invoice for their customers?

Each customer is a separate seller with its own TIN and provider appointment; the platform acts as their system, not as the seller.

This guide explains published UAE rules in plain language and is not tax or legal advice; confirm your own position with a registered tax adviser. Zaini Developers is not an Accredited Service Provider (ASP); we build and connect systems that transmit through MoF-accredited ASPs. Product names belong to their owners.
Free E-Invoicing Readiness CheckAnswer 8 quick questions and get your score and action plan.
Check my readiness

Let's build together

Need your system e-invoicing ready?
We build and connect it.

We build e-invoicing-ready ERP, CRM and POS systems and connect existing software to UAE e-invoicing.

Chat on WhatsApp