Skip to main content

Cliente SOAP/REST para los servicios web de SUNAT (SEE y GRE)

Project description

xfep-ws

Cliente SOAP/REST para los servicios web de SUNAT (SEE y GRE).

Parte del ecosistema XFEP. Envía XML firmado (de xfep-sign) a SUNAT y recibe respuestas (CDR).

Instalación

pip install xfep-ws

Uso

SOAP (Facturas, Boletas, NC, ND, Resumenes)

from xfep.ws import SunatSoap

async with SunatSoap("20123456789", "MODDATOS", "MODDATOS") as client:
    # Enviar factura
    response = await client.send_bill(xml_bytes, "20123456789-01-F001-1")
    print(response.cdr_code, response.cdr_description)

    # Enviar resumen diario
    summary = await client.send_summary(xml_bytes, "20123456789-RC-20260101-1")
    print(summary.ticket)

    # Consultar estado
    status = await client.get_status(summary.ticket)
    print(status.status_code)

REST (Guias de Remision)

from xfep.ws import SunatRest

async with SunatRest("client_id", "client_secret") as client:
    result = await client.send_despatch(xml_bytes, "20123456789-09-T001-1")
    status = await client.get_status(result["numTicket"])

Entornos

Por defecto usa SUNAT Beta. Para produccion:

SunatSoap("20123456789", "USER", "PASS", production=True)
SunatRest("client_id", "secret", production=True)

API

SunatSoap

Método Retorna Descripción
send_bill(xml_bytes, filename) BillResponse Envío directo (Invoice, NC, ND). CDR inmediato.
send_summary(xml_bytes, filename) SummaryResponse Envío batch (Resumen Diario, Baja). Retorna ticket.
get_status(ticket) StatusResponse Consultar estado por ticket.

SunatRest

Método Retorna Descripción
send_despatch(xml_bytes, filename) dict Enviar GRE. Retorna ticket.
get_status(ticket) dict Consultar estado de GRE.

Modelos de respuesta

Modelo Campos principales
BillResponse success, cdr_bytes, cdr_code, cdr_description, hash_value
SummaryResponse success, ticket
StatusResponse success, status_code, cdr_bytes, cdr_code, cdr_description

Endpoints SUNAT

Servicio Beta Producción
SOAP (Facturación) e-beta.sunat.gob.pe e-factura.sunat.gob.pe
REST (GRE) api-cpe-beta.sunat.gob.pe api-cpe.sunat.gob.pe

Desarrollo

git clone https://github.com/xpertik/xfep-ws.git
cd xfep-ws
python3.13 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
pytest -v

Stack

  • Python >= 3.13
  • httpx >= 0.27 (SOAP + REST, async)
  • pytest-asyncio (tests)
  • Build: Hatchling

Parte del ecosistema XFEP

Paquete Estado Descripción
xfep-models v0.1.0 Modelos de datos
xfep-xml v0.1.0 Generación XML UBL 2.1
xfep-sign v0.1.0 Firma digital XMLDSig
xfep-ws v0.1.0 Cliente SOAP/REST SUNAT
xfep-parser pendiente Parseo de respuestas SUNAT

Licencia

Apache License 2.0 — ver LICENSE.

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

xfep_ws-0.1.0.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

xfep_ws-0.1.0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file xfep_ws-0.1.0.tar.gz.

File metadata

  • Download URL: xfep_ws-0.1.0.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for xfep_ws-0.1.0.tar.gz
Algorithm Hash digest
SHA256 026822f642b45eedc9c2a9815a64fc5a3be8aa622afec0ac77af595f30de2a31
MD5 51ff28fe14ca7e32988c2867ecdc58cf
BLAKE2b-256 df7aad715748aa1623f06b1507855c9a85ce35296e300b510fcbd2d346510520

See more details on using hashes here.

File details

Details for the file xfep_ws-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: xfep_ws-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for xfep_ws-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d33a26b324ab0f631c4922d60a0b8ed0de326f4a8063cc985ef1e468a6959543
MD5 5153473fc4746538e895501bb1b58992
BLAKE2b-256 63d2ceda5bc67527a86e4ff5f2732851de8052549c59070bd133d68fbba11b3c

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