Facturalo para Python
SDK oficial de Facturalo para Python: emite facturas, boletas, notas de crédito y débito y guías de remisión ante SUNAT, consulta RUC, DNI y tipo de cambio, trabaja el SIRE y verifica los webhooks. Cliente delgado sobre la API REST v3, con la misma superficie que los SDKs de Node.js y PHP.
pip install facturalo-pe
Requiere Python 3.9 o superior.
Tu primera factura
import os
from facturalo import FacturaloClient
facturalo = FacturaloClient(os.environ["FACTURALO_TOKEN"]) # sk_test_... (demo) o sk_live_...
envio = facturalo.documentos.enviar(
{
"sunatTransaccion": "0101",
"tipoComprobante": "01",
"serie": "F001",
"correlativo": "1",
"fechaEmision": "2026-11-03",
"moneda": "PEN",
"formaPago": "CONTADO",
"cliente": {
"tipoDocumento": "6",
"numeroDocumento": "20000000001",
"denominacion": "EMPRESA S.A.C.",
"direccion": "AV. LIMA 123 - LIMA - LIMA - LIMA",
},
"items": [
{"unidadMedida": "NIU", "descripcion": "SERVICIO DE CONSULTORÍA", "cantidad": 1, "precioUnitario": 118, "tipoIgv": "10"},
],
},
idempotency_key="pedido-1001",
)
print(envio["estado"]) # ACEPTADA o RECHAZADA
print(envio["enlaces"]["pdf"]) # PDF A4; también pdfTicket, xml y cdr
El token decide el entorno: sk_test_ envía a SUNAT Beta (demo) y sk_live_ a producción. Un rechazo de SUNAT no es una excepción: vuelve con estado == "RECHAZADA" y el motivo en envio["sunat"].
Recursos
| Cliente | Token | Recursos |
|---|---|---|
FacturaloClient |
sk_test_... / sk_live_... |
documentos (enviar, generar_xml, consultar, buscar, listar, anular, reenviar, eventos, eliminar, url_archivo, descargar), guias (enviar, consultar, consultar_ticket, eventos, listar, descargar), consultas (ruc, dni, tipo_cambio, placa, soat, licencia…), webhooks (listar, reenviar), sire.ventas / sire.compras |
FacturaloCuentaClient |
user_sk_... |
empresas (listar, obtener, verificar_ruc, crear, actualizar, webhook, regenerar_token…), establecimientos, consultas |
facturalo.consultas.ruc("20100006538")
facturalo.consultas.tipo_cambio("2026-10-30")
facturalo.documentos.anular("01", "F001", "1", motivo="Error en los datos del cliente")
pdf = facturalo.documentos.descargar(envio["documento"]["id"], "pdf") # bytes
Errores
Todas heredan de FacturaloError. Los errores HTTP son FacturaloApiError con status, errors y body:
| Excepción | Cuándo |
|---|---|
FacturaloValidationError |
400 / 422: datos inválidos (revisa e.errors) |
FacturaloAuthenticationError |
401: token inválido o revocado |
FacturaloPermissionError |
403 |
FacturaloNotFoundError |
404 |
FacturaloRateLimitError |
429 |
FacturaloConnectionError |
Red, DNS o timeout |
Reintentos e idempotencia
- Timeout por defecto de 90 s: el envío síncrono espera la respuesta de SUNAT.
- Los
GETse reintentan ante 429, 502, 503, 504 o fallos de conexión. - Los envíos solo se reintentan si llevan
idempotency_key: el servidor deduplica y nunca se emite dos veces el mismo comprobante.
Webhooks
from facturalo import construir_evento, FacturaloSignatureVerificationError
# Django: request.body · Flask: request.get_data() · FastAPI: await request.body()
try:
evento = construir_evento(cuerpo_crudo, request.headers.get("X-Facturalo-Firma"), os.environ["FACTURALO_WEBHOOK_SECRET"])
except FacturaloSignatureVerificationError:
... # responde 400
if evento["evento"] == "documento.sunat.respuesta":
...
La firma es HMAC-SHA256(secret, cuerpo crudo) en hexadecimal y se compara en tiempo constante.
Desarrollo
python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]"
pytest
Documentación completa: docs.facturalo.pe. Licencia MIT · © Consultia Digital S.A.C. (Facturalo).
Metadata
Release files for facturalo-pe 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 |
|---|---|---|---|---|
| facturalo_pe-1.0.0.tar.gz | 11.3 kB | Without provenance | Details for facturalo_pe-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| facturalo_pe-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for facturalo_pe-1.0.0-py3-none-any.whl |
Total release size: 27.1 kB
Release files / facturalo_pe-1.0.0.tar.gz
| Download URL | facturalo_pe-1.0.0.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5f021aff03393eca1dcf0c6e5c33ed48c674bab07f5cc72a1e187245be782ab2
|
|
BLAKE2b-256 checksum How to use checksums |
bfc91bce450cee125c63f1cffbc66ec5a8ab027aceec544afa5018588d23f63f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / facturalo_pe-1.0.0-py3-none-any.whl
| Download URL | facturalo_pe-1.0.0-py3-none-any.whl |
|---|---|
| Size | 15.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cab6859f5da1d3b0a23689e646025131e52685755c0c882e11f4387d652d1980
|
|
BLAKE2b-256 checksum How to use checksums |
290dffa62f1b453d2ef2b845743966b0414def4c61a0a7570b206e14c5f278c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Security for facturalo-pe 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.