Sie_banxico - A python class for the Economic Information System (SIE) API of Banco de México

Overview

sie_banxico

PyPi Version

A python class for the Economic Information System (SIE) API of Banco de México.

Args: token (str): A query token from Banco de México id_series (list): A list with the economic series id or with the series id range to query. ** A list must be given even though only one serie is consulted. language (str): Language of the obtained information. 'en' (default) for english or 'es' for spanish

Notes: (1) In order to retrive information from the SIE API, a query token is required. The token can be requested here (2) Each economic serie is related to an unique ID. The full series catalogue can be consulted here

Pypi Installation

pip install sie_banxico

SIEBanxico Class Instance

Querying Monetary Aggregates M1 (SF311408) and M2 (SF311418) Data

 >>> from api_banxico import SIEBanxico
 >>> api = SIEBanxico(token = token, id_series = ['SF311408' ,'SF311418'], language = 'en')

Class documentation and attributes

>>> api.__doc__
'Returns the full class documentation'
>>> api.token
'1b7da065cf574289a2cb511faeXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' # This is an example token
>>> api.series
'SF311408,SF311418'

Methods for modify the arguments of the object

set_token: Change the current query token

>>> api.set_token(token = new_token)

set_id_series: Allows to change the series to query

>>> api.append_id_series(id_series = ['SF311412'])
>>> api.series
'SF311408,SF311418,SF311412'

append_id_series: Allows to update the series to query

>>> api.set_id_series(id_series='SF311408-SF311418')
>>> api.series
'SF311408-SF311418'

GET Request Methods

>>> api = SIEBanxico(token = token, id_series = ['SF311408' ,'SF311418']

get_metadata: Allows to consult metadata of the series

    Allows to consult metadata of the series.
    Returns:
        dict: json response format
>>> api.get_metadata()
{'bmx': {'series': [{'idSerie': 'SF311418', 'titulo': 'Monetary Aggregates M2 = M1 + monetary instruments held by residents', 'fechaInicio': '12/01/2000', 'fechaFin': '11/01/2021', 'periodicidad': 'Monthly', 'cifra': 'Stocks', 'unidad': 'Thousands of Pesos', 'versionada': False}, {'idSerie': 'SF311408', 'titulo': 'Monetary Aggregates M1', 'fechaInicio': '12/01/2000', 'fechaFin': '11/01/2021', 'periodicidad': 'Monthly', 'cifra': 'Stocks', 'unidad': 'Thousands of Pesos', 'versionada': False}]}}

get_lastdata: Returns the most recent published data

Returns the most recent published data for the requested series. Args: pct_change (str, optional): None (default) for levels, "PorcObsAnt" for change rate compared to the previous observation, "PorcAnual" for anual change rate, "PorcAcumAnual" for annual acummulated change rate. Returns: dict: json response format

>>> api.get_lastdata()
{'bmx': {'series': [{'idSerie': 'SF311418', 'titulo': 'Monetary Aggregates M2 = M1 + monetary instruments held by residents', 'datos': [{'fecha': '01/11/2021', 'dato': '11,150,071,721.09'}]}, {'idSerie': 'SF311408', 'titulo': 'Monetary Aggregates M1', 'datos': [{'fecha': '01/11/2021', 'dato': '6,105,266,291.65'}]}]}}

get_timeseries: Allows to consult time series data

    Allows to consult the whole time series data, corresponding to the period defined between the initial date and the final date in the metadata.
    Args:
        pct_change (str, optional): None (default) for levels, "PorcObsAnt" for change rate compared to the previous observation, "PorcAnual" for anual change rate, "PorcAcumAnual" for annual acummulated change rate.
    Returns:
        dict: json response format
>>> api.get_timeseries(pct_change='PorcAnual')
{'bmx': {'series': [{'idSerie': 'SF311418',
    'titulo': 'Monetary Aggregates M2 = M1 + monetary instruments held by residents',
    'datos': [{'fecha': '01/12/2001', 'dato': '12.89'},
     {'fecha': '01/01/2002', 'dato': '13.99'},
     ...
     {'fecha': '01/11/2021', 'dato': '13.38'}],
     'incrementos': 'PorcAnual'}]}}

get_timeseries_range: Returns the data for the period defined

    Returns the data of the requested series, for the defined period.
    Args:
        init_date (str): The date on which the period of obtained data starts. The date must be sent in the format yyyy-mm-dd. If the given date is out of the metadata time range, the oldest value is returned.
        end_date (str): The date on which the period of obtained data concludes. The date must be sent in the format yyyy-mm-dd. If the given date is out of the metadata time range, the most recent value is returned.
        pct_change (str, optional): None (default) for levels, "PorcObsAnt" for change rate compared to the previous observation, "PorcAnual" for anual change rate, "PorcAcumAnual" for annual acummulated change rate.     
    Returns:
        dict: json response format
>>> api.get_timeseries_range(init_date='2000-12-31', end_date='2004-04-01')
{'bmx': {'series': [{'idSerie': 'SF311408',
    'titulo': 'Monetary Aggregates M1',
    'datos': [{'fecha': '01/01/2001', 'dato': '524,836,129.99'},
     {'fecha': '01/02/2001', 'dato': '517,186,605.97'},
     ...
     {'fecha': '01/04/2004', 'dato': '2,306,755,672.89'}]}]}}

Pandas integration for data manipulation (and further analysis)

All the request methods returns a response in json format that can be used with other Python libraries.

The response for the api.get_timeseries_range(init_date='2000-12-31', end_date='2004-04-01') is a nested dictionary, so we need to follow a path to extract the specific values for the series and then transform the data into a pandas object; like a Serie or a DataFrame. For example:

data = api.get_timeseries_range(init_date='2000-12-31', end_date='2004-04-01')

# Extract the Monetary Aggregate M1 data
data['bmx']['series'][0]['datos']
[{'fecha': '01/01/2001', 'dato': '524,836,129.99'},
 ...
 {'fecha': '01/04/2004', 'dato': '799,774,807.43'}]

# Transform the data into a pandas DataDrame
import pandas as pd
df = pd.DataFrame(timeseries_range['bmx']['series'][0]['datos'])
df.head()
        fecha            dato
0  01/01/2001  524,836,129.99
1  01/02/2001  517,186,605.97
2  01/03/2001  509,701,873.04
3  01/04/2001  511,952,430.01
4  01/05/2001  514,845,459.96

Another useful pandas function to transform json formats into a dataframe is 'json_normalize':

df = pd.json_normalize(timeseries_range['bmx']['series'], record_path = 'datos', meta = ['idSerie', 'titulo'])
df['titulo'] = df['titulo'].apply(lambda x: x.replace('Monetary Aggregates M2 = M1 + monetary instruments held by residents', 'Monetary Aggregates M2'))
df.head()
        fecha            dato   idSerie                  titulo
0  01/01/2001  524,836,129.99  SF311408  Monetary Aggregates M1
1  01/02/2001  517,186,605.97  SF311408  Monetary Aggregates M1
2  01/03/2001  509,701,873.04  SF311408  Monetary Aggregates M1
3  01/04/2001  511,952,430.01  SF311408  Monetary Aggregates M1
4  01/05/2001  514,845,459.96  SF311408  Monetary Aggregates M1
df.tail()
         fecha              dato   idSerie                  titulo
75  01/12/2003  2,331,594,974.69  SF311418  Monetary Aggregates M2
76  01/01/2004  2,339,289,328.74  SF311418  Monetary Aggregates M2
77  01/02/2004  2,285,732,239.36  SF311418  Monetary Aggregates M2
78  01/03/2004  2,312,217,167.10  SF311418  Monetary Aggregates M2
79  01/04/2004  2,306,755,672.89  SF311418  Monetary Aggregates M2

Licence

The MIT License (MIT)

By

Dillan Aguirre Sedeño ([email protected])

Owner
Dillan
Dillan
Telegram bot that sends new offers from otomoto.pl

Telegram bot that sends new offers under certain filters from otomoto.pl How to use this bot? Install requirements with pip install -r requirements.tx

Mikhail Zanka 1 Feb 14, 2022
A simple bot that looks for names and cpfs in the vaccination list made available by the government Fortaleza - CE

A simple bot that looks for names and cpfs in the vaccination list made available by the government Fortaleza - CE

Breno Aquino 1 Dec 21, 2021
Kanata Bot - a modular bot running on python3 with anime theme and have a lot features

Kanata Bot Kanata Bot is a modular bot running on python3 with anime theme and have a lot features. Easiest Way To Deploy On Heroku This Bot is Create

Rikka-Chan 2 Jan 16, 2022
A anti-repostbot script for reddit, runs u/ThisIsARepostBotBot

ThisIsARepostBotBot So you found a repost bot, now what? This is a bot to reply to all posts of a repost bot with a message urging users to report and

3 May 23, 2022
Url-shortener - A url shortener made in python using the API's from the pyshorteners lib

URL Shortener Um encurtador de link feito em python usando as API's da lib pysho

Spyware 3 Jan 07, 2022
google-resumable-media Apache-2google-resumable-media (🥉28 · ⭐ 27) - Utilities for Google Media Downloads and Resumable.. Apache-2

google-resumable-media Utilities for Google Media Downloads and Resumable Uploads See the docs for examples and usage. Experimental asyncio Support Wh

Google APIs 36 Nov 22, 2022
Network simulation tools

Overview I'm building my network simulation environments with Vagrant using libvirt plugin on a Ubuntu 20.04 system... and I always hated how boring i

Ivan Pepelnjak 219 Jan 07, 2023
Python Package For MTN Zambia Momo API. This package can also be used by MTN momo in other countries.

MTN MoMo API Lite Python Client Power your apps with Lite-Python MTN MoMo API Usage Installation Add the latest version of the library to your project

Mathews Musukuma 7 Jan 01, 2023
Rio Userbot Adalah Bot Untuk Membantu Mempermudahkan Sesuatu Di Telegram, Last Repository With Pytgcalls v0.8.3

RIO - USERBOT Disclaimer Saya tidak bertanggung jawab atas penyalahgunaan bot ini. Bot ini dimaksudkan untuk bersenang-senang sekaligus membantu Anda

RioProjectX 4 Oct 18, 2022
Announces when a web3 wallet receives a token

excitare_cito v2.0 by Bogdan Vaida ([email protected]) Announces wh

1 Nov 30, 2021
Translator based on Google API

Yakusu Toshiko Translator based on Google API. Instance of this bot is running as @yakusubot. Features Add a plus to a language's name to show an orig

Arisu W. 2 Sep 21, 2022
Python SDK for LUSID by FINBOURNE, a bi-temporal investment management data platform with portfolio accounting capabilities.

LUSID® Python SDK This is the Python SDK for LUSID by FINBOURNE, a bi-temporal investment management data platform with portfolio accounting capabilit

FINBOURNE 6 Dec 24, 2022
Wrapper for wttr.in weather forecast.

pywttr Wrapper for wttr.in weather forecast. Asynchronous version here. Installation pip install pywttr Example This example prints the average temper

Almaz 6 Dec 25, 2022
Python package for Calendly API v2

PyCalendly Python package to use Calendly API-v2. Installation Install with pip $ pip install PyCalendly Usage Getting Started See Getting Started wi

Lakshmanan Meiyappan 20 Dec 05, 2022
AI-El-Yazisini-Tanima - Fotoğraflardaki El Yazını Yapay Zeka İle Otomatik Tanıma Yazılımı

AI-El Yazısını Tanıma Fotoğraflardaki El Yazını Yapay Zeka İle Otomatik Tanıma Yazılımı Amaç : Birden fazla makine öğrenmesi modelini bir arada kullan

Özgür Tokay 3 Mar 02, 2022
Modified Version Of Media Search bot

Modified Version Of Media Search bot

1 Oct 09, 2021
Elemeno.ai standard development kit in Python

Overview A set of glue code and utilities to make using elemeno AI platform a smooth experience Free software: Apache Software License 2.0 Installatio

Elemeno AI 3 Dec 14, 2022
💬 Send iMessages using Python through the Shortcuts app.

py-imessage-shortcuts Send iMessages using Python through the Shortcuts app. Requires macOS Monterey (macOS 12) or later. Compatible with Apple Silico

Kevin Schaich 10 Nov 30, 2022
ShotsGram - For sending captures from your monitor to a telegram chat (robot)

ShotsGram pt-BR Envios de capturas do seu monitor para um chat do telegram. Essa

Carlos Alberto 1 Apr 24, 2022
PyManGenerator is a token generator for discord, it joins servers using webbot to automate everything

PyManGenerator is a token generator for discord, it joins servers using webbot to automate everything. Captcha can be done by itself unless you used your current IP Address more than once.

5 Nov 27, 2021