Python client library for CEP (http://www.banxico.org.mx/cep/)
pip install cepmexYou can use a staging environment to test the library:
import cep
cep.configure(beta=True)To run unit tests, use pytest.
pytestfrom 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')Use the validar method to validate a transfer with the following 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.
pago_a_banco(bool, default=False): Set toTruefor transfer types 4 and 31.
Use the descargar method to download a transfer in one of the following formats:
PDF(default)XMLZIP
tr.descargar(formato='XML')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.