invoapi Python SDK
Python-Client für die invoapi.de E-Rechnungs-API: XRechnung, ZUGFeRD / Factur-X, EN 16931, UBL, CII und Peppol erzeugen, gegen die offiziellen Regelwerke prüfen, umwandeln und auslesen.
- Python 3.9 oder neuer, keine Abhängigkeiten (nur die Standardbibliothek)
- Jede erzeugte Rechnung wird mit dem offiziellen KoSIT-Validator geprüft
- Automatische Wiederholung bei Tempolimit (429) und kurzzeitigen Ausfällen (5xx)
- Vollständig typisiert (
py.typed)
English: Python client for the invoapi.de e-invoicing API. Create XRechnung, ZUGFeRD / Factur-X, EN 16931, UBL, CII and Peppol invoices, validate them against the official rule sets (KoSIT), convert and parse them. Python 3.9+, no dependencies. Install with
pip install invoapi; see the API documentation for all invoice fields.
Installation
pip install invoapi
Den API-Schlüssel finden Sie im Dashboard unter API-Schlüssel. Der Client liest ihn aus der Umgebungsvariable INVOAPI_API_KEY, oder Sie übergeben ihn direkt: invoapi.Client("inv_live_…").
Schnellstart: XRechnung erzeugen
import invoapi
client = invoapi.Client() # liest INVOAPI_API_KEY
rechnung = client.generate({
"invoice_number": "RE-2026-0001",
"issue_date": "2026-10-28",
"due_date": "2026-11-27",
"currency": "EUR",
"buyer_reference": "04011000-12345-34", # Leitweg-ID, Pflicht bei XRechnung an Behörden
"seller": {
"name": "Muster GmbH", "street": "Musterstraße 1", "postal_code": "10115",
"city": "Berlin", "country_code": "DE", "vat_id": "DE123456789",
"email": "rechnung@muster.de", "phone": "+49 30 1234567",
},
"buyer": {
"name": "Beispiel GmbH", "street": "Teststraße 10", "postal_code": "20095",
"city": "Hamburg", "country_code": "DE", "email": "kreditoren@beispiel.de",
},
"items": [
{"name": "Beratung", "quantity": 8, "unit": "HUR", "unit_price": 145, "vat_rate": 19},
],
"payment": {"means_code": "58", "iban": "DE02120300000000202051"},
}, format="xrechnung")
if rechnung.is_valid:
rechnung.save() # RE-2026-0001.xml
print(rechnung.totals["payable"]) # "1380.40"
Beträge dürfen auch Decimal sein, Datumsangaben datetime.date. Alle Felder der Rechnung beschreibt die API-Dokumentation.
ZUGFeRD-PDF
pdf = client.generate(daten, format="zugferd", output="pdf", profile="en16931")
pdf.save("RE-2026-0001.pdf") # PDF/A-3 mit eingebettetem XML
Eingehende E-Rechnung prüfen
from pathlib import Path
bericht = client.validate(Path("eingang.xml")) # Pfad, bytes oder XML-Text; auch ZUGFeRD-PDF
if not bericht.is_valid:
for fehler in bericht.errors:
print(f"{fehler['rule']}: {fehler['message']}") # z. B. "BR-DE-15: Leitweg-ID fehlt"
is_valid ist nur dann True, wenn ein offizielles Regelwerk tatsächlich gelaufen ist.
Auslesen, erkennen, umwandeln, rechnen
daten = client.parse(xml_oder_pdf) # Rechnung als dict: Verkäufer, Käufer, Positionen, Summen
art = client.detect(xml_oder_pdf) # {"format": "xrechnung", "syntax": "ubl", ...}
cii = client.convert(ubl_xml, "xml", format="xrechnung", syntax="cii")
pdf = client.convert(ubl_xml, "pdf", format="zugferd") # XRechnung → ZUGFeRD-PDF
html = client.render(xml_oder_pdf, "html") # lesbare Ansicht für Menschen (bytes)
summen = client.calculate(daten)["totals"] # kostenlos, zählt nicht aufs Kontingent
Fehlerbehandlung
Jede Ablehnung löst eine Ausnahme mit der verständlichen Meldung der API aus:
| Ausnahme | Wann | Was tun |
|---|---|---|
invoapi.InvalidRequestError |
Rechnung oder Dokument fehlerhaft (400/422) | details nennt die Felder |
invoapi.AuthenticationError |
Schlüssel falsch, E-Mail unbestätigt, Konto gesperrt | Schlüssel im Dashboard prüfen |
invoapi.QuotaExhaustedError |
Gratis-Kontingent aufgebraucht (402) | Tarif wählen: invoapi.de/preise |
invoapi.RateLimitError |
Zu viele Aufrufe (429), nach den Wiederholungen | retry_after Sekunden warten |
invoapi.ServiceUnavailableError |
Dienst kurz nicht erreichbar (5xx) | später erneut versuchen |
invoapi.APIConnectionError |
Keine Verbindung (DNS, TLS, Timeout) | Netzwerk prüfen |
Alle erben von invoapi.InvoapiError mit http_status, code und request_id. Die Request-ID hilft uns bei Support-Anfragen.
try:
rechnung = client.generate(daten)
except invoapi.InvalidRequestError as fehler:
print(fehler, fehler.details)
except invoapi.InvoapiError as fehler:
log.error("invoapi: %s (%s)", fehler, fehler.request_id)
Optionen
client = invoapi.Client(
api_key,
timeout=90, # Sekunden pro Anfrage
max_retries=2, # Wiederholungen bei 429/5xx, 0 schaltet sie ab
)
Tests
pip install -e . pytest
pytest -m "not integration" # ohne Netzwerk
INVOAPI_API_KEY=inv_… pytest -m integration # gegen die echte API, verbraucht Kontingent
Lizenz
MIT
Metadata
Release files for invoapi 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| invoapi-0.1.0.tar.gz | 13.3 kB | With provenance | Details for invoapi-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| invoapi-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for invoapi-0.1.0-py3-none-any.whl |
Total release size: 25.5 kB
Release files / invoapi-0.1.0.tar.gz
| Download URL | invoapi-0.1.0.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d3b07a3f5099b6f52653847cba9b6ff364d4ec04f0930aa4f58cf0d0da2b8103
|
|
BLAKE2b-256 checksum How to use checksums |
17d0eb5fc2041005644ccb7c867b037b91b489133879e772d4e809bbf34099cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logRelease files / invoapi-0.1.0-py3-none-any.whl
| Download URL | invoapi-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
02296041dea88b059c87c09dc771c6cbe26a7cdfaa0f5ec587a059e389a45b4f
|
|
BLAKE2b-256 checksum How to use checksums |
f6f0d9dadadde5d3285bc4b13a7c57e03d4ac1869da31193ade12a0e10964705
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logSecurity for invoapi 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for invoapi-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 30, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.