Skip to main content

Cliente async para SUNAT GRE (Guias de Remision Electronica)

Project description

xfep-gre

Cliente async para SUNAT GRE (Guías de Remisión Electrónica) — Perú.

Parte del ecosistema XFEP. Implementa el flujo OAuth2 client_credentials y el envío/consulta de guías contra la API REST de SUNAT GRE.

Instalación

pip install xfep-gre

Uso

import asyncio
from xfep.gre import GreClient

async def main():
    async with GreClient(
        client_id="tu_client_id",
        client_secret="tu_client_secret",
        production=False,  # True = SUNAT prod, False = SUNAT beta
    ) as client:
        # Enviar guía de remisión firmada
        result = await client.send_despatch(
            xml_bytes=xml_firmado,
            filename="20123456789-09-T001-1",
        )
        print("Ticket:", result.ticket)

        # Consultar estado por ticket
        status = await client.get_status(result.ticket)
        print(status.status, status.description)

asyncio.run(main())

Características

  • OAuth2 con caché de token — Renovación automática con margen de seguridad de 30s.
  • Reintento automático en 401 — Invalida token y reintenta una vez.
  • Ambientes separadosproduction=False usa SUNAT Beta (api-cpe-beta.sunat.gob.pe).
  • Excepciones tipadasAuthenticationError, GreError.
  • 100% async/await — Construido sobre httpx.AsyncClient.
  • Context managerasync with garantiza cierre del cliente HTTP.

API

GreClient

GreClient(
    client_id: str,
    client_secret: str,
    *,
    production: bool = False,
    http_client: httpx.AsyncClient | None = None,
)

send_despatch(xml_bytes: bytes, filename: str) -> GreResponse Envía una guía de remisión firmada. filename sigue el formato {RUC}-{TIPO}-{SERIE}-{CORRELATIVO}, ej: 20123456789-09-T001-1.

get_status(ticket: str) -> GreResponse Consulta el estado de un envío previo por su número de ticket.

Enums

  • GreStatus — estados retornados por SUNAT (ACCEPTED, REJECTED, IN_PROCESS, etc.)

Excepciones

  • AuthenticationError — Autenticación falló después del retry.
  • GreError — Errores 5xx, timeout, u otros.

Stack

  • Python >= 3.13
  • httpx >= 0.27
  • Build: Hatchling
  • Tests: pytest + pytest-asyncio

Desarrollo

git clone https://github.com/Xpertik/xfep-gre.git
cd xfep-gre

python3.13 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

pytest -v

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_gre-0.1.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

xfep_gre-0.1.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for xfep_gre-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4104e74522c5fb4c021913db9959d6fe2be979dfb1f71d65a59b9409d505f5fb
MD5 54ab8573af3651bb81de9c8e56c2785e
BLAKE2b-256 f8f26c2bcad54669ea1fbe22f2a6a1528da457c96b1c2c3076aefc8a33ac41a2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: xfep_gre-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.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_gre-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9aef3488d58dd1387422f845c1b38da0206f3395b86a33f174e2755b93d3e066
MD5 a35c75b3aa7e5d497834d03a281663d9
BLAKE2b-256 5dceb4ec6fe6c8010d4c9a39e9316f272d185e19771f01abc68882743ca14953

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