Skip to main content

SDK Python oficial para ECF Service — Facturación Electrónica República Dominicana (DGII)

Project description

ECF Service SDK — Python

SDK oficial para integrar con ECF Service, plataforma de facturación electrónica e-CF certificada DGII para República Dominicana.

Instalación

pip install ecfservice

Inicio rápido

from ecfservice import ECFClient

with ECFClient(api_key="ecf_tu_api_key") as client:
    # Crear factura electrónica (e-CF tipo 31)
    doc = client.ecf.create(
        idempotency_key="INV-2026-0001",
        ecf_type="31",
        payload={
            "Encabezado": {
                "Version": "1.0",
                "IdDoc": {"eNCF": "E310000000001"},
                "Emisor": {"RNC": "130478031", "RazonSocial": "Mi Empresa SRL"},
                "Comprador": {"RNC": "123456789", "RazonSocial": "Cliente S.A."},
                "Totales": {"MontoTotal": 1000.00, "TotalITBIS": 180.00},
            },
            "DetallesItems": {
                "Item": [{"NumeroLinea": 1, "Descripcion": "Servicio", "MontoItem": 1000.00}]
            },
        },
    )
    print(f"Documento: {doc.public_id} — Estado: {doc.status}")

    # Consultar estado
    doc = client.ecf.get(doc.public_id)

    # Descargar XML firmado
    xml_bytes = client.ecf.download_xml(doc.public_id)

    # Descargar PDF (Representación Impresa)
    pdf_bytes = client.ecf.download_pdf(doc.public_id)

Perfil de empresa

profile = client.client.company()
print(f"RNC: {profile.rnc} — Nombre: {profile.name}")

Secuencias eNCF

result = client.client.sequences(active_only=True)
for seq in result.items:
    print(f"Tipo {seq.ecf_type}: {seq.next_sequence} de {seq.range_end} — Disponibles: {seq.available}")

Webhooks

# Crear webhook
wh = client.client.create_webhook(
    url="https://mi-app.com/webhooks/ecf",
    events=["accepted", "rejected"],
)
print(f"Secreto (guardar ahora): {wh.secret}")  # Solo se muestra una vez

# Verificar firma entrante
from ecfservice.webhook import verify_webhook_signature

is_valid = verify_webhook_signature(
    payload=request.body,
    signature=request.headers["X-ECF-Signature"],
    secret=wh_secret,
)

Consultas DGII (públicas, sin API key)

from ecfservice import ECFClient

client = ECFClient(api_key="any", base_url="http://localhost:8000/api/v1")
contributor = client.dgii.rnc("130478031")
print(f"Nombre: {contributor.razon_social} — Estado: {contributor.estado}")

Manejo de errores

from ecfservice import ECFClient, ECFAuthError, ECFValidationError, ECFNotFoundError

with ECFClient(api_key="ecf_...") as client:
    try:
        doc = client.ecf.create(...)
    except ECFAuthError:
        print("API key inválida o expirada")
    except ECFValidationError as e:
        print(f"Error de validación: {e.detail}")
    except ECFNotFoundError:
        print("Recurso no encontrado")

Licencia

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ecfservice-0.2.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ecfservice-0.2.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file ecfservice-0.2.0.tar.gz.

File metadata

  • Download URL: ecfservice-0.2.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for ecfservice-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8fc6f1195fe8c7443816c55cc84babe41a10136613ba4a5ca16d1a086bf3f8ef
MD5 191778385b6e2c77f436783c2085a606
BLAKE2b-256 7bab0b91d0713dafcc8ba6c49a9e74baddbcaf70cef17097e9dabb1abb0290aa

See more details on using hashes here.

File details

Details for the file ecfservice-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ecfservice-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for ecfservice-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c02cefc88aa100182004c9b3c7a62f2884777573a4c8f4587b0646f333b7e8fd
MD5 b80ebe698f20c77f84fb6df1e7749eb7
BLAKE2b-256 37a11e2c03f6a4dd4b456e5ce02ef5e2cc459d7b6789909be2f650e1bbc7b294

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page