Skip to content

cuenca-mx/cep-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

20700a1 · Feb 19, 2025

History

70 Commits
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Jun 24, 2020
Jul 31, 2019
Jul 31, 2019
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Feb 19, 2025
Jan 15, 2021
Feb 19, 2025

Repository files navigation

CEP

test codecov PyPI

Python client library for CEP (http://www.banxico.org.mx/cep/)

Installation

pip install cepmex

Development & Testing

You can use a staging environment to test the library:

import cep

cep.configure(beta=True)

To run unit tests, use pytest.

pytest

Usage

from datetime import date
from cep import Transferencia
from cep.exc import TransferNotFoundError

try:
    tr = Transferencia.validar(
        fecha=date(2019, 4, 12),
        clave_rastreo='CUENCA1555093850',
        emisor='90646',  # STP
        receptor='40012',  # BBVA
        cuenta='012180004643051249',
        monto=817, # In cents
    )
    pdf = tr.descargar()
    with open('CUENCA1555093850.pdf', 'wb') as f:
        f.write(pdf)
except TransferNotFoundError as e:
    print('No se encontro la transferencia')

Validate Transfer Parameters

Use the validar method to validate a transfer with the following parameters:

Required Parameters:

  • fecha (datetime.date): Transfer date.
  • clave_rastreo (str): Transfer tracking key.
  • emisor (str): Transfer sender bank code.
  • receptor (str): Transfer receiver bank code.
  • cuenta (str): Transfer account number.
  • monto (int): Transfer amount in cents.

Optional Parameters:

  • pago_a_banco (bool, default=False): Set to True for transfer types 4 and 31.

Download Transfer Data

Use the descargar method to download a transfer in one of the following formats:

  • PDF (default)
  • XML
  • ZIP
tr.descargar(formato='XML')

Exceptions

  • TransferNotFoundError: The transfer was not found.
  • MaxRequestError: The maximum number of requests has been reached.
  • CepNotAvailableError: The transfer was found, but the CEP is not available.