cfdi (cfdi-toolkit)
Python toolkit for Mexican electronic invoicing — CFDI (Comprobante Fiscal Digital por Internet, SAT México). Validate, build, stamp, verify and convert CFDI documents.
Features
- Validation of invoice requests
- Building of CFDI XML documents
- SOAP integration with the PAC (digital stamping)
- Sealed XML and PDF download
- SAT verification QR code generation
- Digital stamp (timbre) information extraction
- Number-to-words conversion in Spanish (Mexican pesos)
- Creation of ZIP archives with multiple documents
Installation
pip install cfdi-toolkit
Or, to develop locally from this repository:
pip install -e .[test]
Quick start
from cfdi import CFDI
# Validate a request
datos = {
'jbautoinc': 12345,
'RFC': 'ABC123456XYZ',
'CFDI': '<xml>...</xml>',
'MetodoPago': 'PUE',
'FormaPago': '01',
}
es_valido, errores = CFDI.validate_invoice_request(datos)
# Build XML and stamp via PAC
cfdi = CFDI(timeout=600)
xml = CFDI.get_cfdi_xml({'CFDI': {'Folio': '001', 'Total': '1500.00'}})
resultado = cfdi.obtener_xml_pdf(xml) # seals via SOAP and downloads
# Number to words
print(CFDI.num2letras(1234.56))
# Mil doscientos treinta y cuatro pesos 56/100 M.N.
# SAT verification QR
qr = CFDI.generate_qr('uuid', 'RfcEmisor', 'RfcReceptor', '1500.00', 'sello123')
# Extract timbre from a sealed XML
timbre = CFDI.get_timbre(xml_sellado)
print(timbre['UUID'])
API overview
| Method | Description |
|---|---|
CFDI.validate_invoice_request(data) |
Validate required invoice fields |
CFDI.get_cfdi_xml(request_data) |
Build the CFDI XML |
CFDI.obtener_xml_pdf(document, document_type='1') |
Seal via SOAP and download XML + PDF |
CFDI.generate_invoice(document, document_type='1') |
Perform the SOAP request to the PAC |
CFDI.get_timbre(xml_content) |
Extract digital stamp info |
CFDI.generate_qr(uuid, rfc_emisor, rfc_receptor, total, sello) |
Generate verification QR |
CFDI.create_zip(files, output_path=None) |
Group documents into a ZIP |
CFDI.num2letras(num, feminine=False, decimals=True) |
Number to words |
LoginObject(username, password) |
SOAP credentials holder |
Exceptions: CFDIError (base), CFDIValidationError, CFDISoapError.
Configuration
Environment variables (optionally loaded via python-dotenv):
| Variable | Description |
|---|---|
SLACK_WEBHOOK_CFDI |
Slack webhook for error notifications |
EMISOR_EMAIL |
Issuer email (for PDFs) |
EMISOR_TEL |
Issuer phone (for PDFs) |
CFDI_SOAP_USERNAME / CFDI_SOAP_PASSWORD |
Optional SOAP credentials |
Note: the PAC endpoint is configured through
CFDI.CFDI_360_URL. Set this value (or aPAC_URL) before using it in production.
Tests
pip install -e .[test]
python -m pytest tests -v
Examples
Run the practical examples:
python examples/examples.py
Contributing
See CONTRIBUTING.md.
License
MIT — see LICENSE.
Metadata
Release files for cfdi-toolkit 1.0.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 |
|---|---|---|---|---|
| cfdi_toolkit-1.0.0.tar.gz | 14.1 kB | Without provenance | Details for cfdi_toolkit-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cfdi_toolkit-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for cfdi_toolkit-1.0.0-py3-none-any.whl |
Total release size: 24.4 kB
Release files / cfdi_toolkit-1.0.0.tar.gz
| Download URL | cfdi_toolkit-1.0.0.tar.gz |
|---|---|
| Size | 14.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c0a1878f142ccc171d99d624d3e3a8384469da0dd5cc92a3f9ece67fd1cd0956
|
|
BLAKE2b-256 checksum How to use checksums |
44ffd3f58e6a3a72e18f01c0ff6107e8fcb9ac234461d1cbc4c44f3478ef1f82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Release files / cfdi_toolkit-1.0.0-py3-none-any.whl
| Download URL | cfdi_toolkit-1.0.0-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
94bf78963324891d481c83f1a692d52fd7f0b87abd616cb5a390762c024d3505
|
|
BLAKE2b-256 checksum How to use checksums |
03c5782636748615cf0e3493632bf929d41e6587c0e205b62aef5d39b56088a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.13
|
Security for cfdi-toolkit 1.0.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A 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.