Central Bank of the Republic of Türkiye (TCMB) Python API.
Project description
tcmb
tcmb
is a Python API wrapper around the Central Bank of the Republic of Türkiye (TCMB) Web Service. It is an unofficial open-source Python package intended for personal use (Disclaimer).
tcmb
, Türkiye Cumhuriyeti Merkez Bankası (TCMB) Web Servisi'ne Python aracılığıyla erişimi sağlayan resmi olmayan API uygulamasıdır. Kişisel kullanım ve araştırma maksadıyla hazırlanmıştır (Elektronik Veri Dağıtım Sistemi (EVDS) Kullanım Koşulları).
Quickstart
pip install tcmb
import tcmb
client = tcmb.Client(api_key="...")
data = client.read(series="TP.DK.USD.S.YTL")
Overview
Data Hierarchy
- Categories:
Categories are at the top level of the TCMB data hierarchy.
client = tcmb.Client(api_key="...")
# show categories
Client.categories
{'CATEGORY_ID': 1.0,
'TOPIC_TITLE_ENG': 'MARKET STATISTICS',
'TOPIC_TITLE_TR': 'PİYASA VERİLERİ'}
It is also possible to get the same information using the client.get_categories_metadata()
method.
- Data Groups:
Each category consists of a number of data groups.
client = tcmb.Client(api_key="...")
# show data groups
Client.datagroups
[{'DATAGROUP_CODE': 'bie_pyrepo',
'CATEGORY_ID': 1,
'DATAGROUP_NAME': 'Açık Piyasa Repo ve Ters Repo İşlemleri',
'DATAGROUP_NAME_ENG': 'Open Market Repo and Reverse Repo Transactions',
...}
{'DATAGROUP_CODE': 'bie_mkbral',
'CATEGORY_ID': 0,
'DATAGROUP_NAME': 'Altın Borsası İşlemleri-İstanbul (TL-ABD Doları)(Arşiv)',
'DATAGROUP_NAME_ENG': 'Istanbul Gold Exchange (TRY-USD)(Archive)',
...}]
It is also possible to filter the datagroups metadata using the client.get_datagroups_metadata()
method.
- Series
Datagroups consist of time series, each having a series key such as TP.YSSK.A1
or TP.DK.USD.S.YTL
. Series is read using the .read()
method.
import tcmb
client = tcmb.Client(api_key="...")
# read one time series
data = client.read("TP.YSSK.A1")
# read multiple time series
data = client.read(["TP.YSSK.A1", "TP.YSSK.A2", "TP.YSSK.A3"])
A convenient way to read time series without initializing the Client instance is using the read()
function in the core.py
module.
import tcmb
# read one time series
data = tcmb.read("TP.YSSK.A1", api_key="...")
# read multiple time series
data = tcmb.read(["TP.YSSK.A1", "TP.YSSK.A2", "TP.YSSK.A3"], api_key="...")
Series metadata can be fetched with .get_series_metadata()
method.
# show metadata of each series within a data group
client.get_series_metadata(datagroup="bie_yssk")
[{'SERIE_CODE': 'TP.YSSK.A1',
'DATAGROUP_CODE': 'bie_yssk',
'SERIE_NAME': '1-2 Yıl(ABD doları)',
'SERIE_NAME_ENG': '1-2 Years(USD)',
...},
{'SERIE_CODE': 'TP.YSSK.A2',
'DATAGROUP_CODE': 'bie_yssk',
'SERIE_NAME': '3 Yıl(ABD doları)',
'SERIE_NAME_ENG': '3 Years(USD)',
...}]
# show metadata of a specific time series
client.get_series_metadata(series="TP.YSSK.A1")
[{'SERIE_CODE': 'TP.YSSK.A1',
'DATAGROUP_CODE': 'bie_yssk',
'SERIE_NAME': '1-2 Yıl(ABD doları)',
'SERIE_NAME_ENG': '1-2 Years(USD)',
...}]
Wildcard Characters
The wildcard characters are represented as an asterisk *
or a question mark ?
. The asterisk *
represents any number of characters, while the question mark ?
represents a single character. Additionally, omitting the value has the same effect as using an asterisk. Note that, wildcard character option is not a feature of TCMB web service. Wildcard pattern search is implemented within the tcmb
package and depends on the package data.
>>> data = tcmb.read("TP.DK.USD.*.YTL")
>>> print(data.columns)
Index(['TP_DK_USD_A_YTL', 'TP_DK_USD_S_YTL', 'TP_DK_USD_C_YTL',
'TP_DK_USD_A_EF_YTL', 'TP_DK_USD_S_EF_YTL'],
dtype='object')
Installation
pip install tcmb
Authentication
An API key is required to access the Web Service. Users can sign up from the login page. Once logged in, API Key is generated from the Profile page.
There are two ways of providing API key to the tcmb
client.
- Using environment variables:
$ export TCMB_API_KEY="..."
import os
os.environ["TCMB_API_KEY"] = "..."
- Passing
api_key
when initializing theClient
class.
client = Client(api_key="...")
Disclaimer
tcmb
is an unofficial open-source package intended for personal use and research purposes. Please see TCMB's EVDS Disclaimer for the official terms of use of the EVDS Web Service.
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
Built Distribution
File details
Details for the file tcmb-0.4.1.tar.gz
.
File metadata
- Download URL: tcmb-0.4.1.tar.gz
- Upload date:
- Size: 142.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da4acae4c7e18ee4f353b70c46648fe6de297c1492c4b408eab65821f8517857 |
|
MD5 | 3f92e26669cdccf45c4f4a20f0606a4e |
|
BLAKE2b-256 | e7d71e8d33081f188035c4bd91d038586b65d5651a84bce5bc8817c04725bf9b |
File details
Details for the file tcmb-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: tcmb-0.4.1-py3-none-any.whl
- Upload date:
- Size: 136.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59fdbbd7ef887c0889e1a2afdd2f3388707e812d3313dc108df46e81b7256bc6 |
|
MD5 | a514aebec0b93ca29bd043aa1817f5cd |
|
BLAKE2b-256 | 29e9398fc23d382df94fc0b7b4c33fa264289e98fb9218c15e7bf18e2245e414 |