tefasfon 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tefasfon-0.1.0/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025 Uraz Akgül
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,211 @@
1
+ Metadata-Version: 2.1
2
+ Name: tefasfon
3
+ Version: 0.1.0
4
+ Summary: Fetches fund data from the TEFAS website.
5
+ Home-page: https://github.com/urazakgul/tefasfon
6
+ Author: Uraz Akgül
7
+ Author-email: urazdev@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+
15
+ # tefasfon v0.1.0
16
+
17
+ ## Türkçe tercih edenler için:
18
+
19
+ ***Those who prefer English can scroll down the page.***
20
+
21
+ ## Açıklama
22
+
23
+ `tefasfon`, Türkiye Elektronik Fon Alım Satım Platformu'nun (TEFAS) resmi web sitesinde yayımlanan yatırım fonu ve emeklilik fonu verilerini programatik olarak çekmenizi sağlayan bir Python kütüphanesidir. Kütüphane, fon türü ve tarih aralığı seçimiyle esnek veri çekimi sunar. Mesajlar ve hata bildirimleri Türkçe/İngilizce desteklidir; çıktı doğrudan kullanıma hazır pandas DataFrame olarak döner ve isteğe bağlı olarak Excel dosyasına kaydedilebilir.
24
+
25
+ ## Özellikler
26
+
27
+ * İstenilen tarih aralığında ve fon türüne göre TEFAS verilerini hızlıca çekebilirsiniz.
28
+ * Fon bilgisi veya portföy dağılımı (iki farklı sekme) için veri alabilirsiniz.
29
+ * Mesajlar ve hata uyarıları Türkçe/İngilizce gösterilir.
30
+ * Kolay kullanım, çıktı olarak doğrudan `pandas.DataFrame` döner.
31
+ * Çekilen verileri opsiyonel olarak Excel dosyasına kaydedebilirsiniz.
32
+ * Selenium ile gerçek tarayıcı üzerinden veriler alınır, böylece web arayüzündeki tüm güncel verilere ulaşabilirsiniz.
33
+
34
+ ## Kurulum
35
+
36
+ Kütüphaneyi yüklemek için şu adımları izleyin:
37
+
38
+ 1. Python'ı yükleyin: https://www.python.org/downloads/
39
+ 2. Terminal veya komut istemcisinde aşağıdaki komutu çalıştırın:
40
+
41
+ ```bash
42
+ pip install tefasfon
43
+ ```
44
+
45
+ Belirli bir versiyonu yüklemek için:
46
+
47
+ ```bash
48
+ pip install tefasfon==0.1.0
49
+ ```
50
+
51
+ Yüklü versiyonu görüntülemek için:
52
+
53
+ ```bash
54
+ pip show tefasfon
55
+ ```
56
+
57
+ ## Fonksiyonlar
58
+
59
+ ### `fetch_tefas_data`
60
+
61
+ TEFAS web sitesinden fon veya portföy verisi çeker.
62
+
63
+ Parametreler:
64
+
65
+ * `fund_type_code` (int): Fon tipi kodu
66
+ * 0: Menkul Kıymet Yatırım Fonları
67
+ * 1: Emeklilik Fonları
68
+ * 2: Borsa Yatırım Fonları
69
+ * 3: Gayrimenkul Yatırım Fonları
70
+ * 4: Girişim Sermayesi Yatırım Fonları
71
+ * `tab_code` (int): Sekme kodu
72
+ * 0: Genel Bilgiler
73
+ * 1: Portföy Dağılımı
74
+ * `start_date` (str): Başlangıç tarihi, 'gg.aa.yyyy' formatında (örn. '17.07.2025')
75
+ * `end_date` (str): Bitiş tarihi, 'gg.aa.yyyy' formatında (örn. '18.07.2025')
76
+ * `lang` (str): "tr" veya "en" (varsayılan "tr")
77
+ * `save_to_excel` (bool): True verilirse, Excel dosyasına kaydeder (varsayılan: False)
78
+ * `wait_seconds` (int): Web işlemleri arası bekleme süresi (varsayılan: 3)
79
+
80
+ Dönüş:
81
+
82
+ * `pandas.DataFrame` (veya veri yoksa boş DataFrame)
83
+
84
+ ## Örnek Kullanım
85
+
86
+ ```python
87
+ from tefasfon import fetch_tefas_data
88
+
89
+ df = fetch_tefas_data(
90
+ fund_type_code=0,
91
+ tab_code=0,
92
+ start_date="17.08.2025",
93
+ end_date="18.07.2025",
94
+ lang="tr",
95
+ save_to_excel=True
96
+ )
97
+ ```
98
+
99
+ ## Notlar
100
+
101
+ * Kütüphane, TEFAS'ın web sitesindeki verilere bağımlıdır. Herhangi bir değişiklikte veya bakımda, veri çekilemeyebilir. Lütfen [TEFAS](https://www.tefas.gov.tr/TarihselVeriler.aspx) adresinden veri durumu ve güncelliğini kontrol edin.
102
+ * Selenium ve ChromeDriver kullanılır. Bilgisayarınızda Google Chrome kurulu olmalı ve güncel olmalıdır.
103
+ * Kütüphanenin geliştirilmesi ve iyileştirilmesi için geri bildirimlerinizi bekliyorum. GitHub reposuna katkıda bulunun: [GitHub Repo](https://github.com/urazakgul/tefasfon)
104
+ * Herhangi bir sorun veya öneride lütfen GitHub reposundaki "Issue" bölümünden yeni bir konu açarak bildirim sağlayın: [GitHub Issues](https://github.com/urazakgul/tefasfon/issues)
105
+
106
+ ## Sürüm Notları
107
+
108
+ ### v0.1.0 - 20/07/2025
109
+
110
+ * İlk sürüm yayınlandı.
111
+
112
+ ## Lisans
113
+
114
+ Bu proje MIT Lisansı altında lisanslanmıştır.
115
+
116
+ ## For those who prefer English:
117
+
118
+ ## Description
119
+
120
+ `tefasfon` is a Python package that enables you to programmatically fetch investment fund and pension fund data published on the official TEFAS website. The library offers flexible data fetching by fund type and date range. All messages and errors are displayed in Turkish or English. The output is delivered as a ready-to-use pandas DataFrame and can optionally be saved as an Excel file.
121
+
122
+ ## Features
123
+
124
+ * Easily fetch TEFAS data for any desired date range and fund type.
125
+ * Fetch either general fund information or portfolio breakdown (two separate tabs).
126
+ * Errors and status messages are shown in Turkish or English.
127
+ * Simple usage; output is directly returned as a `pandas.DataFrame`.
128
+ * Optionally save the fetched data as an Excel file.
129
+ * Uses Selenium for browser automation, ensuring access to up-to-date data from the web interface.
130
+
131
+ ## Installation
132
+
133
+ To use the package, follow these steps:
134
+
135
+ 1. Install Python: https://www.python.org/downloads/
136
+ 2. Open your terminal or command prompt and run:
137
+
138
+ ```bash
139
+ pip install tefasfon
140
+ ```
141
+
142
+ To install a specific version:
143
+
144
+ ```bash
145
+ pip install tefasfon==0.1.0
146
+ ```
147
+
148
+ To check the installed version:
149
+
150
+ ```bash
151
+ pip show tefasfon
152
+ ```
153
+
154
+ ## Functions
155
+
156
+ ### `fetch_tefas_data`
157
+
158
+ Fetches fund or portfolio data from the TEFAS website.
159
+
160
+ Parameters:
161
+
162
+ * `fund_type_code` (int): Fund type code
163
+ * 0: Securities Mutual Funds
164
+ * 1: Pension Funds
165
+ * 2: Exchange Traded Funds
166
+ * 3: Real Estate Investment Funds
167
+ * 4: Venture Capital Investment Funds
168
+ * `tab_code` (int): Tab code
169
+ * 0: General Information
170
+ * 1: Portfolio Breakdown
171
+ * `start_date` (str): Start date, in 'dd.mm.yyyy' format (e.g. '17.07.2025')
172
+ * `end_date` (str): End date, in 'dd.mm.yyyy' format (e.g. '18.07.2025')
173
+ * `lang` (str): "tr" or "en" (default "tr")
174
+ * `save_to_excel` (bool): If True, saves the result to an Excel file (default: False)
175
+ * `wait_seconds` (int): Wait time between web actions (default: 3)
176
+
177
+ Returns:
178
+
179
+ * `pandas.DataFrame` (or an empty DataFrame if no data)
180
+
181
+ ## Example
182
+
183
+ ```python
184
+ from tefasfon import fetch_tefas_data
185
+
186
+ df = fetch_tefas_data(
187
+ fund_type_code=0,
188
+ tab_code=0,
189
+ start_date="17.08.2025",
190
+ end_date="18.07.2025",
191
+ lang="en",
192
+ save_to_excel=True
193
+ )
194
+ ```
195
+
196
+ ## Notes
197
+
198
+ * The library depends on data from the [TEFAS](https://www.tefas.gov.tr/TarihselVeriler.aspx) official website. In case of any changes or maintenance, data fetching may not be possible. Please check the data status and availability on TEFAS.
199
+ * Selenium and ChromeDriver are used. Google Chrome must be installed and up-to-date on your system.
200
+ * I welcome your feedback to improve and develop the library. You can contribute to the GitHub repository: [GitHub Repo](https://github.com/urazakgul/tefasfon)
201
+ * For any issues or suggestions, please open a new topic in the "Issue" section of the GitHub repository: [GitHub Issues](https://github.com/urazakgul/tefasfon/issues)
202
+
203
+ ## Release Notes
204
+
205
+ ### v0.1.0 - 20/07/2025
206
+
207
+ * First release published.
208
+
209
+ ## License
210
+
211
+ This project is licensed under the MIT License.
@@ -0,0 +1,197 @@
1
+ # tefasfon v0.1.0
2
+
3
+ ## Türkçe tercih edenler için:
4
+
5
+ ***Those who prefer English can scroll down the page.***
6
+
7
+ ## Açıklama
8
+
9
+ `tefasfon`, Türkiye Elektronik Fon Alım Satım Platformu'nun (TEFAS) resmi web sitesinde yayımlanan yatırım fonu ve emeklilik fonu verilerini programatik olarak çekmenizi sağlayan bir Python kütüphanesidir. Kütüphane, fon türü ve tarih aralığı seçimiyle esnek veri çekimi sunar. Mesajlar ve hata bildirimleri Türkçe/İngilizce desteklidir; çıktı doğrudan kullanıma hazır pandas DataFrame olarak döner ve isteğe bağlı olarak Excel dosyasına kaydedilebilir.
10
+
11
+ ## Özellikler
12
+
13
+ * İstenilen tarih aralığında ve fon türüne göre TEFAS verilerini hızlıca çekebilirsiniz.
14
+ * Fon bilgisi veya portföy dağılımı (iki farklı sekme) için veri alabilirsiniz.
15
+ * Mesajlar ve hata uyarıları Türkçe/İngilizce gösterilir.
16
+ * Kolay kullanım, çıktı olarak doğrudan `pandas.DataFrame` döner.
17
+ * Çekilen verileri opsiyonel olarak Excel dosyasına kaydedebilirsiniz.
18
+ * Selenium ile gerçek tarayıcı üzerinden veriler alınır, böylece web arayüzündeki tüm güncel verilere ulaşabilirsiniz.
19
+
20
+ ## Kurulum
21
+
22
+ Kütüphaneyi yüklemek için şu adımları izleyin:
23
+
24
+ 1. Python'ı yükleyin: https://www.python.org/downloads/
25
+ 2. Terminal veya komut istemcisinde aşağıdaki komutu çalıştırın:
26
+
27
+ ```bash
28
+ pip install tefasfon
29
+ ```
30
+
31
+ Belirli bir versiyonu yüklemek için:
32
+
33
+ ```bash
34
+ pip install tefasfon==0.1.0
35
+ ```
36
+
37
+ Yüklü versiyonu görüntülemek için:
38
+
39
+ ```bash
40
+ pip show tefasfon
41
+ ```
42
+
43
+ ## Fonksiyonlar
44
+
45
+ ### `fetch_tefas_data`
46
+
47
+ TEFAS web sitesinden fon veya portföy verisi çeker.
48
+
49
+ Parametreler:
50
+
51
+ * `fund_type_code` (int): Fon tipi kodu
52
+ * 0: Menkul Kıymet Yatırım Fonları
53
+ * 1: Emeklilik Fonları
54
+ * 2: Borsa Yatırım Fonları
55
+ * 3: Gayrimenkul Yatırım Fonları
56
+ * 4: Girişim Sermayesi Yatırım Fonları
57
+ * `tab_code` (int): Sekme kodu
58
+ * 0: Genel Bilgiler
59
+ * 1: Portföy Dağılımı
60
+ * `start_date` (str): Başlangıç tarihi, 'gg.aa.yyyy' formatında (örn. '17.07.2025')
61
+ * `end_date` (str): Bitiş tarihi, 'gg.aa.yyyy' formatında (örn. '18.07.2025')
62
+ * `lang` (str): "tr" veya "en" (varsayılan "tr")
63
+ * `save_to_excel` (bool): True verilirse, Excel dosyasına kaydeder (varsayılan: False)
64
+ * `wait_seconds` (int): Web işlemleri arası bekleme süresi (varsayılan: 3)
65
+
66
+ Dönüş:
67
+
68
+ * `pandas.DataFrame` (veya veri yoksa boş DataFrame)
69
+
70
+ ## Örnek Kullanım
71
+
72
+ ```python
73
+ from tefasfon import fetch_tefas_data
74
+
75
+ df = fetch_tefas_data(
76
+ fund_type_code=0,
77
+ tab_code=0,
78
+ start_date="17.08.2025",
79
+ end_date="18.07.2025",
80
+ lang="tr",
81
+ save_to_excel=True
82
+ )
83
+ ```
84
+
85
+ ## Notlar
86
+
87
+ * Kütüphane, TEFAS'ın web sitesindeki verilere bağımlıdır. Herhangi bir değişiklikte veya bakımda, veri çekilemeyebilir. Lütfen [TEFAS](https://www.tefas.gov.tr/TarihselVeriler.aspx) adresinden veri durumu ve güncelliğini kontrol edin.
88
+ * Selenium ve ChromeDriver kullanılır. Bilgisayarınızda Google Chrome kurulu olmalı ve güncel olmalıdır.
89
+ * Kütüphanenin geliştirilmesi ve iyileştirilmesi için geri bildirimlerinizi bekliyorum. GitHub reposuna katkıda bulunun: [GitHub Repo](https://github.com/urazakgul/tefasfon)
90
+ * Herhangi bir sorun veya öneride lütfen GitHub reposundaki "Issue" bölümünden yeni bir konu açarak bildirim sağlayın: [GitHub Issues](https://github.com/urazakgul/tefasfon/issues)
91
+
92
+ ## Sürüm Notları
93
+
94
+ ### v0.1.0 - 20/07/2025
95
+
96
+ * İlk sürüm yayınlandı.
97
+
98
+ ## Lisans
99
+
100
+ Bu proje MIT Lisansı altında lisanslanmıştır.
101
+
102
+ ## For those who prefer English:
103
+
104
+ ## Description
105
+
106
+ `tefasfon` is a Python package that enables you to programmatically fetch investment fund and pension fund data published on the official TEFAS website. The library offers flexible data fetching by fund type and date range. All messages and errors are displayed in Turkish or English. The output is delivered as a ready-to-use pandas DataFrame and can optionally be saved as an Excel file.
107
+
108
+ ## Features
109
+
110
+ * Easily fetch TEFAS data for any desired date range and fund type.
111
+ * Fetch either general fund information or portfolio breakdown (two separate tabs).
112
+ * Errors and status messages are shown in Turkish or English.
113
+ * Simple usage; output is directly returned as a `pandas.DataFrame`.
114
+ * Optionally save the fetched data as an Excel file.
115
+ * Uses Selenium for browser automation, ensuring access to up-to-date data from the web interface.
116
+
117
+ ## Installation
118
+
119
+ To use the package, follow these steps:
120
+
121
+ 1. Install Python: https://www.python.org/downloads/
122
+ 2. Open your terminal or command prompt and run:
123
+
124
+ ```bash
125
+ pip install tefasfon
126
+ ```
127
+
128
+ To install a specific version:
129
+
130
+ ```bash
131
+ pip install tefasfon==0.1.0
132
+ ```
133
+
134
+ To check the installed version:
135
+
136
+ ```bash
137
+ pip show tefasfon
138
+ ```
139
+
140
+ ## Functions
141
+
142
+ ### `fetch_tefas_data`
143
+
144
+ Fetches fund or portfolio data from the TEFAS website.
145
+
146
+ Parameters:
147
+
148
+ * `fund_type_code` (int): Fund type code
149
+ * 0: Securities Mutual Funds
150
+ * 1: Pension Funds
151
+ * 2: Exchange Traded Funds
152
+ * 3: Real Estate Investment Funds
153
+ * 4: Venture Capital Investment Funds
154
+ * `tab_code` (int): Tab code
155
+ * 0: General Information
156
+ * 1: Portfolio Breakdown
157
+ * `start_date` (str): Start date, in 'dd.mm.yyyy' format (e.g. '17.07.2025')
158
+ * `end_date` (str): End date, in 'dd.mm.yyyy' format (e.g. '18.07.2025')
159
+ * `lang` (str): "tr" or "en" (default "tr")
160
+ * `save_to_excel` (bool): If True, saves the result to an Excel file (default: False)
161
+ * `wait_seconds` (int): Wait time between web actions (default: 3)
162
+
163
+ Returns:
164
+
165
+ * `pandas.DataFrame` (or an empty DataFrame if no data)
166
+
167
+ ## Example
168
+
169
+ ```python
170
+ from tefasfon import fetch_tefas_data
171
+
172
+ df = fetch_tefas_data(
173
+ fund_type_code=0,
174
+ tab_code=0,
175
+ start_date="17.08.2025",
176
+ end_date="18.07.2025",
177
+ lang="en",
178
+ save_to_excel=True
179
+ )
180
+ ```
181
+
182
+ ## Notes
183
+
184
+ * The library depends on data from the [TEFAS](https://www.tefas.gov.tr/TarihselVeriler.aspx) official website. In case of any changes or maintenance, data fetching may not be possible. Please check the data status and availability on TEFAS.
185
+ * Selenium and ChromeDriver are used. Google Chrome must be installed and up-to-date on your system.
186
+ * I welcome your feedback to improve and develop the library. You can contribute to the GitHub repository: [GitHub Repo](https://github.com/urazakgul/tefasfon)
187
+ * For any issues or suggestions, please open a new topic in the "Issue" section of the GitHub repository: [GitHub Issues](https://github.com/urazakgul/tefasfon/issues)
188
+
189
+ ## Release Notes
190
+
191
+ ### v0.1.0 - 20/07/2025
192
+
193
+ * First release published.
194
+
195
+ ## License
196
+
197
+ This project is licensed under the MIT License.
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,31 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r", encoding = "utf-8") as fh:
4
+ long_description = fh.read()
5
+
6
+ setup(
7
+ name="tefasfon",
8
+ version="0.1.0",
9
+ packages=find_packages(),
10
+ author="Uraz Akgül",
11
+ author_email="urazdev@gmail.com",
12
+ description="Fetches fund data from the TEFAS website.",
13
+ long_description=long_description,
14
+ long_description_content_type='text/markdown',
15
+ url="https://github.com/urazakgul/tefasfon",
16
+ license="MIT",
17
+ install_requires=[
18
+ "requests",
19
+ "pandas",
20
+ "openpyxl",
21
+ "selenium",
22
+ "rich",
23
+ "lxml",
24
+ "webdriver-manager",
25
+ ],
26
+ classifiers=[
27
+ 'Programming Language :: Python :: 3',
28
+ 'License :: OSI Approved :: MIT License',
29
+ ],
30
+ python_requires=">=3.8",
31
+ )
@@ -0,0 +1,3 @@
1
+ from .data_fetcher import fetch_tefas_data
2
+
3
+ __all__ = ["fetch_tefas_data"]
@@ -0,0 +1,128 @@
1
+ from selenium.webdriver.common.by import By
2
+ from selenium.webdriver.support.ui import Select
3
+ from selenium.common.exceptions import ElementClickInterceptedException
4
+ import time
5
+ import pandas as pd
6
+ from datetime import timedelta
7
+ from io import StringIO
8
+ from rich.console import Console
9
+
10
+ from .setup_webdriver import setup_webdriver
11
+ from .utils import (
12
+ FUND_TYPE_CODES,
13
+ TAB_CODES,
14
+ get_localized_message,
15
+ parse_and_validate_dates,
16
+ print_rich_panel,
17
+ fix_date
18
+ )
19
+
20
+ def fetch_tefas_data(
21
+ fund_type_code: int,
22
+ tab_code: int,
23
+ start_date: str,
24
+ end_date: str,
25
+ lang: str = "tr",
26
+ save_to_excel: bool = False,
27
+ wait_seconds: int = 3
28
+ ) -> pd.DataFrame:
29
+ console = Console()
30
+
31
+ if fund_type_code not in FUND_TYPE_CODES:
32
+ raise ValueError(get_localized_message("invalid_fund_type", lang, fund_type_code, list(FUND_TYPE_CODES.keys())))
33
+ if tab_code not in TAB_CODES:
34
+ raise ValueError(get_localized_message("invalid_tab_type", lang, tab_code, list(TAB_CODES.keys())))
35
+
36
+ fund_type_label = FUND_TYPE_CODES[fund_type_code]
37
+ tab_label = TAB_CODES[tab_code]
38
+
39
+ start_date_dt, end_date_dt = parse_and_validate_dates(start_date, end_date, lang)
40
+ start_date_filename = start_date_dt.strftime("%Y%m%d")
41
+ end_date_filename = end_date_dt.strftime("%Y%m%d")
42
+ excel_filename = f"tefas_{fund_type_label}_{tab_label}_{start_date_filename}_{end_date_filename}.xlsx"
43
+
44
+ driver = setup_webdriver(lang)
45
+ driver.maximize_window()
46
+ driver.get("https://www.tefas.gov.tr/TarihselVeriler.aspx")
47
+ time.sleep(wait_seconds)
48
+ driver.minimize_window()
49
+ print_rich_panel(console, get_localized_message("browser_minimized", lang), lang)
50
+ time.sleep(wait_seconds)
51
+
52
+ tab_dropdown_table_map = {
53
+ "general_information": {
54
+ "tab_button_id": "ui-id-1",
55
+ "table_id": "table_general_info",
56
+ "next_button_id": "table_general_info_next",
57
+ "dropdown_name": "table_general_info_length"
58
+ },
59
+ "portfolio_breakdown": {
60
+ "tab_button_id": "ui-id-2",
61
+ "table_id": "table_allocation",
62
+ "next_button_id": "table_allocation_next",
63
+ "dropdown_name": "table_allocation_length"
64
+ }
65
+ }
66
+ tab_params = tab_dropdown_table_map[tab_label]
67
+
68
+ tab_button = driver.find_element(By.ID, tab_params["tab_button_id"])
69
+ tab_button.click()
70
+ time.sleep(wait_seconds)
71
+
72
+ all_rows = []
73
+ columns = None
74
+ current_date = start_date_dt
75
+ while current_date <= end_date_dt:
76
+ date_str = current_date.strftime("%d.%m.%Y")
77
+ start_date_input = driver.find_element(By.ID, "TextBoxStartDate")
78
+ start_date_input.clear()
79
+ start_date_input.send_keys(date_str)
80
+ end_date_input = driver.find_element(By.ID, "TextBoxEndDate")
81
+ end_date_input.clear()
82
+ end_date_input.send_keys(date_str)
83
+ view_button = driver.find_element(By.ID, "ButtonSearchDates")
84
+ view_button.click()
85
+ time.sleep(wait_seconds)
86
+
87
+ try:
88
+ select_element = driver.find_element(By.NAME, tab_params["dropdown_name"])
89
+ select_box = Select(select_element)
90
+ max_option = max([int(option.text) for option in select_box.options if option.text.isdigit()])
91
+ select_box.select_by_visible_text(str(max_option))
92
+ time.sleep(wait_seconds)
93
+ except Exception as e:
94
+ print(f"Dropdown selection error: {e}")
95
+
96
+ while True:
97
+ table_element = driver.find_element(By.ID, tab_params["table_id"])
98
+ table_html = table_element.get_attribute("outerHTML")
99
+ page_df = pd.read_html(StringIO(table_html), decimal=',', thousands='.')[0]
100
+ if "Tarih" in page_df.columns:
101
+ page_df["Tarih"] = page_df["Tarih"].apply(fix_date)
102
+ if columns is None:
103
+ columns = page_df.columns.tolist()
104
+ all_rows.extend(page_df.values.tolist())
105
+ try:
106
+ next_button = driver.find_element(By.ID, tab_params["next_button_id"])
107
+ except:
108
+ break
109
+ if "disabled" in next_button.get_attribute("class"):
110
+ break
111
+ if not (next_button.is_displayed() and next_button.is_enabled()):
112
+ break
113
+ try:
114
+ next_button.click()
115
+ time.sleep(wait_seconds)
116
+ except ElementClickInterceptedException:
117
+ break
118
+ time.sleep(wait_seconds)
119
+ current_date += timedelta(days=1)
120
+
121
+ final_df = pd.DataFrame(all_rows, columns=columns)
122
+ print_rich_panel(console, get_localized_message("rows_fetched", lang, final_df.shape[0]), lang, style="green")
123
+ if save_to_excel:
124
+ final_df.to_excel(excel_filename, index=False)
125
+ print_rich_panel(console, get_localized_message("saved_excel", lang, excel_filename), lang, style="bold cyan")
126
+ print_rich_panel(console, get_localized_message("all_done", lang), lang, style="bold green")
127
+ driver.quit()
128
+ return final_df
@@ -0,0 +1,41 @@
1
+ import platform
2
+ from selenium import webdriver
3
+ from selenium.webdriver.chrome.service import Service
4
+ from selenium.webdriver.chrome.options import Options
5
+ from selenium.common.exceptions import SessionNotCreatedException
6
+ from webdriver_manager.chrome import ChromeDriverManager
7
+
8
+ from .utils import get_localized_message
9
+
10
+ def setup_webdriver(lang) -> webdriver.Chrome:
11
+ driver = None
12
+ try:
13
+ chrome_options = Options()
14
+ system_platform = platform.system()
15
+ if system_platform == "Linux":
16
+ chrome_options.add_argument('--no-sandbox')
17
+ chrome_options.add_argument('--disable-dev-shm-usage')
18
+ elif system_platform == "Darwin":
19
+ chrome_options.add_argument('--disable-infobars')
20
+ chrome_options.add_argument('--disable-popup-blocking')
21
+ elif system_platform == "Windows":
22
+ chrome_options.add_argument('--disable-extensions')
23
+
24
+ service = Service(ChromeDriverManager().install())
25
+ driver = webdriver.Chrome(service=service, options=chrome_options)
26
+ return driver
27
+
28
+ except SessionNotCreatedException as e:
29
+ raise RuntimeError(
30
+ get_localized_message(
31
+ "webdriver_version_mismatch", lang, e
32
+ )
33
+ )
34
+ except Exception as e:
35
+ if driver:
36
+ driver.quit()
37
+ raise RuntimeError(
38
+ get_localized_message(
39
+ "webdriver_setup_failed", lang, e
40
+ )
41
+ )
@@ -0,0 +1,82 @@
1
+ import re
2
+ from datetime import datetime
3
+ from rich.panel import Panel
4
+ from rich.text import Text
5
+
6
+ LANGUAGES = {
7
+ "tr": {
8
+ "browser_minimized": "Tarayıcı küçültüldü! Lütfen kapatmayın. İşlem arka planda devam edecek. Bittiğinde bildirim alacaksınız.",
9
+ "info": "BİLGİ",
10
+ "rows_fetched": "{} satır çekildi.",
11
+ "saved_excel": "Excel dosyasına kaydedildi: {}",
12
+ "all_done": "Tüm işlemler başarıyla tamamlandı.",
13
+ "invalid_fund_type": "Geçersiz fon tipi kodu: '{}'. Geçerli kodlar: {}",
14
+ "invalid_tab_type": "Geçersiz sekme kodu: '{}'. Geçerli kodlar: {}",
15
+ "invalid_date_format": "Geçersiz {} formatı! Doğru format: 'gg.aa.yyyy'",
16
+ "start_date_gt_end": "Başlangıç tarihi, bitiş tarihinden sonra olamaz!",
17
+ "webdriver_version_mismatch": "WebDriver sürüm uyumsuzluğu: {}. Lütfen Chrome veya WebDriver'ı güncellemeyi deneyin.",
18
+ "webdriver_setup_failed": "WebDriver kurulumu başarısız oldu: {}. Lütfen Google Chrome'un kurulu ve WebDriver sürümünüzle uyumlu olduğundan emin olun.",
19
+ },
20
+ "en": {
21
+ "browser_minimized": "Browser minimized! Please do not close it. The process will continue in the background. You will get a notification when it finishes.",
22
+ "info": "INFO",
23
+ "rows_fetched": "{} rows fetched.",
24
+ "saved_excel": "Saved to Excel file: {}",
25
+ "all_done": "All operations completed successfully.",
26
+ "invalid_fund_type": "Invalid fund type code: '{}'. Valid codes: {}",
27
+ "invalid_tab_type": "Invalid tab code: '{}'. Valid codes: {}",
28
+ "invalid_date_format": "Invalid {} format! Correct format: 'dd.mm.yyyy'",
29
+ "start_date_gt_end": "Start date cannot be after end date!",
30
+ "webdriver_version_mismatch": "WebDriver version mismatch: {}. Please try updating Chrome or WebDriver.",
31
+ "webdriver_setup_failed": "WebDriver setup failed: {}. Please ensure Google Chrome is installed and compatible with the WebDriver version.",
32
+ }
33
+ }
34
+
35
+ FUND_TYPE_CODES = {
36
+ 0: "securities_mutuals",
37
+ 1: "pension",
38
+ 2: "exchange_traded",
39
+ 3: "real_estate_investment",
40
+ 4: "venture_capital_investment"
41
+ }
42
+ FUND_TYPE_LABELS = {v: k for k, v in FUND_TYPE_CODES.items()}
43
+
44
+ TAB_CODES = {
45
+ 0: "general_information",
46
+ 1: "portfolio_breakdown"
47
+ }
48
+ TAB_LABELS = {v: k for k, v in TAB_CODES.items()}
49
+
50
+ def get_localized_message(key, lang, *args):
51
+ template = LANGUAGES.get(lang, LANGUAGES["en"]).get(key, key)
52
+ return template.format(*args) if args else template
53
+
54
+ def parse_and_validate_dates(start_date_str, end_date_str, lang):
55
+ try:
56
+ start_date = datetime.strptime(start_date_str, "%d.%m.%Y")
57
+ except Exception:
58
+ raise ValueError(get_localized_message("invalid_date_format", lang, "start date"))
59
+ try:
60
+ end_date = datetime.strptime(end_date_str, "%d.%m.%Y")
61
+ except Exception:
62
+ raise ValueError(get_localized_message("invalid_date_format", lang, "end date"))
63
+ if start_date > end_date:
64
+ raise ValueError(get_localized_message("start_date_gt_end", lang))
65
+ return start_date, end_date
66
+
67
+ def print_rich_panel(console, message, lang, style="bold yellow", title_key="info", border_style="bright_magenta"):
68
+ panel = Panel(
69
+ Text(message, style=style, justify="center"),
70
+ title=f"[cyan]{get_localized_message(title_key, lang)}",
71
+ border_style=border_style
72
+ )
73
+ console.print(panel)
74
+
75
+ def fix_date(val):
76
+ if isinstance(val, str) and re.match(r"\d{2}\.\d{2}\.\d{4}", val):
77
+ return val
78
+ elif isinstance(val, (int, float, str)) and len(str(int(float(val)))) == 8:
79
+ s = str(int(float(val)))
80
+ return f"{s[:2]}.{s[2:4]}.{s[4:]}"
81
+ else:
82
+ return str(val)
@@ -0,0 +1,211 @@
1
+ Metadata-Version: 2.1
2
+ Name: tefasfon
3
+ Version: 0.1.0
4
+ Summary: Fetches fund data from the TEFAS website.
5
+ Home-page: https://github.com/urazakgul/tefasfon
6
+ Author: Uraz Akgül
7
+ Author-email: urazdev@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+
15
+ # tefasfon v0.1.0
16
+
17
+ ## Türkçe tercih edenler için:
18
+
19
+ ***Those who prefer English can scroll down the page.***
20
+
21
+ ## Açıklama
22
+
23
+ `tefasfon`, Türkiye Elektronik Fon Alım Satım Platformu'nun (TEFAS) resmi web sitesinde yayımlanan yatırım fonu ve emeklilik fonu verilerini programatik olarak çekmenizi sağlayan bir Python kütüphanesidir. Kütüphane, fon türü ve tarih aralığı seçimiyle esnek veri çekimi sunar. Mesajlar ve hata bildirimleri Türkçe/İngilizce desteklidir; çıktı doğrudan kullanıma hazır pandas DataFrame olarak döner ve isteğe bağlı olarak Excel dosyasına kaydedilebilir.
24
+
25
+ ## Özellikler
26
+
27
+ * İstenilen tarih aralığında ve fon türüne göre TEFAS verilerini hızlıca çekebilirsiniz.
28
+ * Fon bilgisi veya portföy dağılımı (iki farklı sekme) için veri alabilirsiniz.
29
+ * Mesajlar ve hata uyarıları Türkçe/İngilizce gösterilir.
30
+ * Kolay kullanım, çıktı olarak doğrudan `pandas.DataFrame` döner.
31
+ * Çekilen verileri opsiyonel olarak Excel dosyasına kaydedebilirsiniz.
32
+ * Selenium ile gerçek tarayıcı üzerinden veriler alınır, böylece web arayüzündeki tüm güncel verilere ulaşabilirsiniz.
33
+
34
+ ## Kurulum
35
+
36
+ Kütüphaneyi yüklemek için şu adımları izleyin:
37
+
38
+ 1. Python'ı yükleyin: https://www.python.org/downloads/
39
+ 2. Terminal veya komut istemcisinde aşağıdaki komutu çalıştırın:
40
+
41
+ ```bash
42
+ pip install tefasfon
43
+ ```
44
+
45
+ Belirli bir versiyonu yüklemek için:
46
+
47
+ ```bash
48
+ pip install tefasfon==0.1.0
49
+ ```
50
+
51
+ Yüklü versiyonu görüntülemek için:
52
+
53
+ ```bash
54
+ pip show tefasfon
55
+ ```
56
+
57
+ ## Fonksiyonlar
58
+
59
+ ### `fetch_tefas_data`
60
+
61
+ TEFAS web sitesinden fon veya portföy verisi çeker.
62
+
63
+ Parametreler:
64
+
65
+ * `fund_type_code` (int): Fon tipi kodu
66
+ * 0: Menkul Kıymet Yatırım Fonları
67
+ * 1: Emeklilik Fonları
68
+ * 2: Borsa Yatırım Fonları
69
+ * 3: Gayrimenkul Yatırım Fonları
70
+ * 4: Girişim Sermayesi Yatırım Fonları
71
+ * `tab_code` (int): Sekme kodu
72
+ * 0: Genel Bilgiler
73
+ * 1: Portföy Dağılımı
74
+ * `start_date` (str): Başlangıç tarihi, 'gg.aa.yyyy' formatında (örn. '17.07.2025')
75
+ * `end_date` (str): Bitiş tarihi, 'gg.aa.yyyy' formatında (örn. '18.07.2025')
76
+ * `lang` (str): "tr" veya "en" (varsayılan "tr")
77
+ * `save_to_excel` (bool): True verilirse, Excel dosyasına kaydeder (varsayılan: False)
78
+ * `wait_seconds` (int): Web işlemleri arası bekleme süresi (varsayılan: 3)
79
+
80
+ Dönüş:
81
+
82
+ * `pandas.DataFrame` (veya veri yoksa boş DataFrame)
83
+
84
+ ## Örnek Kullanım
85
+
86
+ ```python
87
+ from tefasfon import fetch_tefas_data
88
+
89
+ df = fetch_tefas_data(
90
+ fund_type_code=0,
91
+ tab_code=0,
92
+ start_date="17.08.2025",
93
+ end_date="18.07.2025",
94
+ lang="tr",
95
+ save_to_excel=True
96
+ )
97
+ ```
98
+
99
+ ## Notlar
100
+
101
+ * Kütüphane, TEFAS'ın web sitesindeki verilere bağımlıdır. Herhangi bir değişiklikte veya bakımda, veri çekilemeyebilir. Lütfen [TEFAS](https://www.tefas.gov.tr/TarihselVeriler.aspx) adresinden veri durumu ve güncelliğini kontrol edin.
102
+ * Selenium ve ChromeDriver kullanılır. Bilgisayarınızda Google Chrome kurulu olmalı ve güncel olmalıdır.
103
+ * Kütüphanenin geliştirilmesi ve iyileştirilmesi için geri bildirimlerinizi bekliyorum. GitHub reposuna katkıda bulunun: [GitHub Repo](https://github.com/urazakgul/tefasfon)
104
+ * Herhangi bir sorun veya öneride lütfen GitHub reposundaki "Issue" bölümünden yeni bir konu açarak bildirim sağlayın: [GitHub Issues](https://github.com/urazakgul/tefasfon/issues)
105
+
106
+ ## Sürüm Notları
107
+
108
+ ### v0.1.0 - 20/07/2025
109
+
110
+ * İlk sürüm yayınlandı.
111
+
112
+ ## Lisans
113
+
114
+ Bu proje MIT Lisansı altında lisanslanmıştır.
115
+
116
+ ## For those who prefer English:
117
+
118
+ ## Description
119
+
120
+ `tefasfon` is a Python package that enables you to programmatically fetch investment fund and pension fund data published on the official TEFAS website. The library offers flexible data fetching by fund type and date range. All messages and errors are displayed in Turkish or English. The output is delivered as a ready-to-use pandas DataFrame and can optionally be saved as an Excel file.
121
+
122
+ ## Features
123
+
124
+ * Easily fetch TEFAS data for any desired date range and fund type.
125
+ * Fetch either general fund information or portfolio breakdown (two separate tabs).
126
+ * Errors and status messages are shown in Turkish or English.
127
+ * Simple usage; output is directly returned as a `pandas.DataFrame`.
128
+ * Optionally save the fetched data as an Excel file.
129
+ * Uses Selenium for browser automation, ensuring access to up-to-date data from the web interface.
130
+
131
+ ## Installation
132
+
133
+ To use the package, follow these steps:
134
+
135
+ 1. Install Python: https://www.python.org/downloads/
136
+ 2. Open your terminal or command prompt and run:
137
+
138
+ ```bash
139
+ pip install tefasfon
140
+ ```
141
+
142
+ To install a specific version:
143
+
144
+ ```bash
145
+ pip install tefasfon==0.1.0
146
+ ```
147
+
148
+ To check the installed version:
149
+
150
+ ```bash
151
+ pip show tefasfon
152
+ ```
153
+
154
+ ## Functions
155
+
156
+ ### `fetch_tefas_data`
157
+
158
+ Fetches fund or portfolio data from the TEFAS website.
159
+
160
+ Parameters:
161
+
162
+ * `fund_type_code` (int): Fund type code
163
+ * 0: Securities Mutual Funds
164
+ * 1: Pension Funds
165
+ * 2: Exchange Traded Funds
166
+ * 3: Real Estate Investment Funds
167
+ * 4: Venture Capital Investment Funds
168
+ * `tab_code` (int): Tab code
169
+ * 0: General Information
170
+ * 1: Portfolio Breakdown
171
+ * `start_date` (str): Start date, in 'dd.mm.yyyy' format (e.g. '17.07.2025')
172
+ * `end_date` (str): End date, in 'dd.mm.yyyy' format (e.g. '18.07.2025')
173
+ * `lang` (str): "tr" or "en" (default "tr")
174
+ * `save_to_excel` (bool): If True, saves the result to an Excel file (default: False)
175
+ * `wait_seconds` (int): Wait time between web actions (default: 3)
176
+
177
+ Returns:
178
+
179
+ * `pandas.DataFrame` (or an empty DataFrame if no data)
180
+
181
+ ## Example
182
+
183
+ ```python
184
+ from tefasfon import fetch_tefas_data
185
+
186
+ df = fetch_tefas_data(
187
+ fund_type_code=0,
188
+ tab_code=0,
189
+ start_date="17.08.2025",
190
+ end_date="18.07.2025",
191
+ lang="en",
192
+ save_to_excel=True
193
+ )
194
+ ```
195
+
196
+ ## Notes
197
+
198
+ * The library depends on data from the [TEFAS](https://www.tefas.gov.tr/TarihselVeriler.aspx) official website. In case of any changes or maintenance, data fetching may not be possible. Please check the data status and availability on TEFAS.
199
+ * Selenium and ChromeDriver are used. Google Chrome must be installed and up-to-date on your system.
200
+ * I welcome your feedback to improve and develop the library. You can contribute to the GitHub repository: [GitHub Repo](https://github.com/urazakgul/tefasfon)
201
+ * For any issues or suggestions, please open a new topic in the "Issue" section of the GitHub repository: [GitHub Issues](https://github.com/urazakgul/tefasfon/issues)
202
+
203
+ ## Release Notes
204
+
205
+ ### v0.1.0 - 20/07/2025
206
+
207
+ * First release published.
208
+
209
+ ## License
210
+
211
+ This project is licensed under the MIT License.
@@ -0,0 +1,12 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ tefasfon/__init__.py
5
+ tefasfon/data_fetcher.py
6
+ tefasfon/setup_webdriver.py
7
+ tefasfon/utils.py
8
+ tefasfon.egg-info/PKG-INFO
9
+ tefasfon.egg-info/SOURCES.txt
10
+ tefasfon.egg-info/dependency_links.txt
11
+ tefasfon.egg-info/requires.txt
12
+ tefasfon.egg-info/top_level.txt
@@ -0,0 +1,7 @@
1
+ requests
2
+ pandas
3
+ openpyxl
4
+ selenium
5
+ rich
6
+ lxml
7
+ webdriver-manager
@@ -0,0 +1 @@
1
+ tefasfon