Help for developers to integrate Verifactu with Python: learn to make REST requests, generate invoices with QR, sign with digital certificate and create XML efficiently.

In Python, the most widely used library for making HTTP requests is requests. To call a REST API like Verifacti's using the requests library, you can use the following code:
import requests
url = "https://api.verifacti.com/verifactu/create"
headers = {
"Authorization": "Bearer <API_KEY>",
"Content-Type": "application/json"
}
payload = {
"serie": "A",
"numero": "234634",
"fecha_expedicion": "02-12-2024",
"tipo_factura": "F1",
"descripcion": "Descripcion de la operacion",
"nif": "A15022510",
"nombre": "Nombre cliente",
"lineas": [{
"base_imponible": "200",
"tipo_impositivo": "21",
"cuota_repercutida": "42"
}],
"importe_total": "242"
}
response = requests.post(url, headers=headers, json=payload)
print(response.text)
To embed a QR code in a PDF, you can use the following libraries:
Example with reportlab:
from reportlab.pdfgen import canvas
from reportlab.lib.utils import ImageReader
def agregar_qr_a_pdf():
c = canvas.Canvas("FacturaConQR.pdf")
qr_image = ImageReader("QRFactura.png")
c.drawImage(qr_image, 100, 100, 100, 100)
c.save()
agregar_qr_a_pdf()To generate QR codes in Python, you can use:
Example with qrcode:
import qrcode
def generar_qr():
qr = qrcode.make("https://verifacti.com")
qr.save("QRFactura.png")
generar_qr()The content provided by Bilbabit SL in any of its sections (Blog, guides, landing pages, FAQ section, commercial or customer support emails) is for informational purposes only and has no legal validity. BILBABIT is not a tax consulting firm, but a fiscal software developer, so the information it provides is of an indicative nature. In any case, any activity related to invoicing and taxation should always and without exception be consulted with a tax advisor who understands the specific implications of each regulation for each company or professional in particular.