💱 Banxico SIE
Cliente Python para consultar tipos de cambio del Sistema de Información Económica (SIE) de Banxico.
🚀 Instalación
pip install banxico-sie-xp
O desde el source:
git clone https://github.com/soyrushian/banxico-sie.git
cd banxico-sie
pip install -e .
🔑 Requisitos
Necesitas un token de la API de Banxico. Lo consigues gratis aquí: 👉 https://www.banxico.org.mx/SieAPIRest/service/v1/token
💡 Uso
Setup básico
from banxico_sie import BanxicoSIEClient, Currency
# Inicializa el cliente con tu token
client = BanxicoSIEClient("tu_token_aqui")
Consultar tipo de cambio actual
# USD FIX (por determinación)
usd = client.get_rate(Currency.USD) # Dólar (FIX - Determinación DOF)
print(f"USD: ${usd['valor']} MXN")
# USD Spot (para liquidación)
usd_spot = client.get_rate(Currency.USD_SPOT) # Dólar (Para liquidación)
print(f"USD SPOT: ${usd_spot['valor']} MXN")
# Otras monedas
eur = client.get_rate(Currency.EUR) # Euro
cad = client.get_rate(Currency.CAD) # Dolar canadiense
gbp = client.get_rate(Currency.GBP) # Libra Esterlina
Consultar fecha específica
from datetime import datetime
# Fecha específica como string
rate = client.get_rate(Currency.USD, fecha="2024-12-01")
print(f"USD el 1 dic 2024: ${rate['valor']}")
# Fecha como datetime
rate = client.get_rate(Currency.EUR, fecha=datetime(2024, 11, 15))
Rango de fechas
# Histórico USD FIX
historico = client.get_rates_range(
Currency.USD,
start_date="2024-01-01",
end_date="2024-12-31"
)
# Histórico USD para liquidación
historico_pagos = client.get_rates_range(
Currency.USD_PAGOS,
start_date="2024-01-01",
end_date="2024-12-31"
)
for rate in historico:
print(f"{rate['fecha']}: ${rate['valor']}")
Obtener el más reciente
# Último USD FIX
latest = client.get_latest(Currency.USD)
print(f"Último USD: ${latest['valor']} ({latest['fecha']})")
# Último USD para liquidación
latest_pagos = client.get_latest(Currency.USD_PAGOS)
print(f"Último USD PAGOS: ${latest_pagos['valor']} ({latest_pagos['fecha']})")
🌍 Monedas disponibles
Currency.USD # 🇺🇸 Dólar (FIX - Determinación DOF)
Currency.USD_SPOT # 🇺🇸 Dólar (Para liquidación)
Currency.CAD # 🇨🇦 Dólar canadiense (Cotización Cruzada)
Currency.EUR # 🇪🇺 Euro (Cotización Cruzada)
Currency.JPY # 🇯🇵 Yen japonés (Cotización Cruzada)
Currency.GBP # 🇬🇧 Libra Esterlina (Cotización Cruzada)
📦 Estructura de respuesta
{
'fecha': '26/12/2024',
'moneda': 'USD',
'moneda_nombre': 'Dólar estadounidense',
'simbolo': '$',
'valor': 20.3456,
'tipo': 'FIX - Determinación publicada en DOF'
}
Para Currency.USD_SPOT:
{
'fecha': '26/12/2024',
'moneda': 'USD',
'moneda_nombre': 'Dólar estadounidense',
'simbolo': '$',
'valor': 20.4567,
'tipo': 'Para liquidación (obligaciones)'
}
📋 Series de Banxico
| Currency | Serie | Símbolo | Tipo |
|---|---|---|---|
Currency.USD |
SF43718 | $ | FIX - Determinación publicada en DOF |
Currency.USD_SPOT |
SF60653 | $ | Para liquidación (obligaciones) |
Currency.CAD |
SF60632 | C$ | Cotización Cruzada |
Currency.EUR |
SF46410 | € | Cotización Cruzada |
Currency.JPY |
SF46406 | ¥ | Cotización Cruzada |
Currency.GBP |
SF46407 | £ | Cotización Cruzada |
🔥 Ejemplos prácticos
Comparar USD FIX vs SPOT
usd_fix = client.get_rate(Currency.USD)
usd_spot = client.get_rate(Currency.USD_SPOT)
print(f"USD FIX: ${usd_fix['valor']:.4f}")
print(f"USD SPOT: ${usd_spot['valor']:.4f}")
print(f"Diferencia: ${abs(usd_fix['valor'] - usd_spot['valor']):.4f}")
Histórico con análisis
from datetime import datetime, timedelta
hace_mes = datetime.now() - timedelta(days=30)
historico = client.get_rates_range(
Currency.USD,
start_date=hace_mes,
end_date=datetime.now()
)
valores = [r['valor'] for r in historico if r['valor']]
print(f"Mínimo: ${min(valores):.4f}")
print(f"Máximo: ${max(valores):.4f}")
print(f"Promedio: ${sum(valores)/len(valores):.4f}")
Tabla de todas las monedas
monedas = [
Currency.USD,
Currency.USD_SPOT,
Currency.EUR,
Currency.CAD,
Currency.JPY,
Currency.GBP
]
for moneda in monedas:
rate = client.get_rate(moneda)
print(f"{rate['simbolo']} {rate['moneda']}: ${rate['valor']:.4f} MXN")
📝 Licencia
MIT License - puedes hacer lo que quieras con este código.
🤝 Contribuir
Pull requests son bienvenidos. Para cambios grandes, abre un issue primero para discutir qué te gustaría cambiar.
⚠️ Disclaimer
Este paquete no está afiliado con el Banco de México. Usa los datos bajo tu propio riesgo y verifica la información crítica directamente con fuentes oficiales.
🔗 Links útiles
📮 Contacto
Metadata
Release files for banxico-sie-xp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| banxico_sie_xp-0.1.0.tar.gz | 13.2 kB | Without provenance | Details for banxico_sie_xp-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| banxico_sie_xp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for banxico_sie_xp-0.1.0-py3-none-any.whl |
Total release size: 22.2 kB
Release files / banxico_sie_xp-0.1.0.tar.gz
| Download URL | banxico_sie_xp-0.1.0.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9af58354465980d8e335df1e03ca5a99f82aa92fa6e7ca4c93ea91346b2c3ea7
|
|
BLAKE2b-256 checksum How to use checksums |
78582698d185ac232fb22d7a53a9948d57e637386fa8db42161873e90154c2d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / banxico_sie_xp-0.1.0-py3-none-any.whl
| Download URL | banxico_sie_xp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f2dcf2011d070b38c7a736d7f8fd76b918c3a5b7eda48dca5fd6740f429d8ef9
|
|
BLAKE2b-256 checksum How to use checksums |
c85d57b87999545aa2fc76f8d2442c664f927a2f0d48817359b5e96dd00974f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for banxico-sie-xp 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.