### Install tefas-crawler Source: https://github.com/burakyilmaz321/tefas-crawler/blob/main/README.md Install the tefas-crawler library using pip. ```bash pip install tefas-crawler ``` -------------------------------- ### Fetch All Funds for a Day Source: https://github.com/burakyilmaz321/tefas-crawler/blob/main/README.md Retrieve all fund information for a specific date. The `start` parameter is required. ```python data = tefas.fetch(start="2020-11-20") ``` -------------------------------- ### Snap to Valid API Periods with _months_back Source: https://context7.com/burakyilmaz321/tefas-crawler/llms.txt Internal helper that converts a start date to the nearest valid API `periyod` value from the set {1, 3, 6, 12, 36, 60}. Dates older than 5 years are clamped to 60 months. ```python from datetime import date from dateutil.relativedelta import relativedelta from tefas.crawler import _months_back today = date.today() # 2 weeks ago → snaps up to 1 month print(_months_back(today - relativedelta(weeks=2))) # 1 # 2 months ago → snaps up to 3 months print(_months_back(today - relativedelta(months=2))) # 3 # 7 months ago → snaps up to 12 months print(_months_back(today - relativedelta(months=7))) # 12 # 4 years ago → snaps up to 60 months (max) print(_months_back(today - relativedelta(years=4))) # 60 ``` -------------------------------- ### Fetch Single Fund Data Using Datetime Objects Source: https://context7.com/burakyilmaz321/tefas-crawler/llms.txt Retrieve data for a single fund ('ATA') within a date range, using Python datetime objects for the start and end dates. ```python # --- 4. datetime objects as input --- df_dt = tefas.fetch( start=datetime(2025, 2, 1), end=datetime(2025, 2, 28), name="ATA", ) ``` -------------------------------- ### Fetch Specific Fund Data with Columns Source: https://github.com/burakyilmaz321/tefas-crawler/blob/main/README.md Retrieve data for a specific fund within a date range, selecting only the desired columns. The `start`, `end`, and `name` parameters are used to filter the data, and `columns` specifies which fields to return. ```python data = tefas.fetch(start="2020-11-15", end="2020-11-20", name="YAC", columns=["code", "date", "price"]) ``` -------------------------------- ### Fetch Single Fund Data by Date Range (String Dates) Source: https://context7.com/burakyilmaz321/tefas-crawler/llms.txt Retrieve daily price data for a single fund ('YAC') within a specified date range using string inputs for start and end dates. The output includes columns like 'date', 'code', 'title', 'price', 'category_rank', and 'category_total'. ```python import warnings from datetime import datetime from tefas import Crawler tefas = Crawler() # --- 1. Single fund, date range, string dates --- df = tefas.fetch(start="2025-01-01", end="2025-01-31", name="YAC") print(df.columns.tolist()) # ['date', 'code', 'title', 'price', 'category_rank', 'category_total'] print(df.head(3)) # date code title price category_rank category_total # 0 2025-01-02 YAC Yapı Kredi Asset Mgmt Fund 1.2345 5 80 # 1 2025-01-03 YAC Yapı Kredi Asset Mgmt Fund 1.2401 5 80 # 2 2025-01-06 YAC Yapı Kredi Asset Mgmt Fund 1.2389 4 80 ``` -------------------------------- ### Initialize Crawler Source: https://github.com/burakyilmaz321/tefas-crawler/blob/main/README.md Import the Crawler object and create an instance to begin crawling. ```python from tefas import Crawler tefas = Crawler() ``` -------------------------------- ### Initialize Crawler with Default and Custom Fund Limit Source: https://context7.com/burakyilmaz321/tefas-crawler/llms.txt Instantiate the Crawler class. The default fund limit is 50. You can increase this limit to fetch more funds in bulk. ```python from tefas import Crawler # Default: fan-out capped at 50 funds tefas = Crawler() # Raise the cap to fetch up to 200 funds in bulk tefas_large = Crawler(fund_limit=200) print(tefas.fund_limit) # 50 print(tefas_large.fund_limit) # 200 ``` -------------------------------- ### Crawler Constructor Source: https://context7.com/burakyilmaz321/tefas-crawler/llms.txt Initializes the Crawler class, establishing an HTTP session and setting an optional fund limit for bulk fetches. ```APIDOC ## Crawler(fund_limit=50) — Constructor Creates a persistent HTTP session targeting `https://www.tefas.gov.tr`. The optional `fund_limit` parameter controls how many funds are fetched when `fetch()` is called without a `name` argument. Increase it to retrieve more funds in bulk, keeping in mind that each fund triggers a separate HTTP request. ```python from tefas import Crawler # Default: fan-out capped at 50 funds tefas = Crawler() # Raise the cap to fetch up to 200 funds in bulk tefas_large = Crawler(fund_limit=200) print(tefas.fund_limit) # 50 print(tefas_large.fund_limit) # 200 ``` ``` -------------------------------- ### Bulk Fetch Funds and Handle Warnings Source: https://context7.com/burakyilmaz321/tefas-crawler/llms.txt Perform a bulk fetch of funds without specifying a name. This action emits a UserWarning and is capped by `fund_limit` (default 50). The output confirms the number of unique fund codes fetched. ```python # --- 7. Bulk fetch (no name) — emits UserWarning, capped at fund_limit --- with warnings.catch_warnings(record=True) as caught: warnings.simplefilter("always") df_bulk = tefas.fetch(start="2025-04-01", kind="YAT") print(caught[0].category.__name__) # UserWarning print(len(df_bulk["code"].unique())) # up to 50 unique fund codes ``` -------------------------------- ### Crawler.fetch Method Source: https://context7.com/burakyilmaz321/tefas-crawler/llms.txt Fetches daily price data for specified funds and date ranges. Supports string or datetime objects for dates, and allows filtering by fund type and selecting specific columns. ```APIDOC ## Crawler.fetch(start, end, name, columns, kind) — Fetch Fund Data The primary API. Returns a `pandas.DataFrame` containing daily price rows for the requested fund(s) and date range. `start` and `end` accept either ISO date strings (`"YYYY-MM-DD"`) or `datetime.datetime` / `datetime.date` objects. The `kind` parameter filters by fund type: `"YAT"` (investment funds, default), `"EMK"` (commodity funds), or `"BYF"` (exchange-traded funds). Columns no longer published by the new API (e.g. `market_cap`, `number_of_shares`, asset-allocation breakdowns) are silently dropped with a `UserWarning` rather than raising an error. ```python import warnings from datetime import datetime from tefas import Crawler tefas = Crawler() # --- 1. Single fund, date range, string dates --- df = tefas.fetch(start="2025-01-01", end="2025-01-31", name="YAC") print(df.columns.tolist()) # ['date', 'code', 'title', 'price', 'category_rank', 'category_total'] print(df.head(3)) # date code title price category_rank category_total # 0 2025-01-02 YAC Yapı Kredi Asset Mgmt Fund 1.2345 5 80 # 1 2025-01-03 YAC Yapı Kredi Asset Mgmt Fund 1.2401 5 80 # 2 2025-01-06 YAC Yapı Kredi Asset Mgmt Fund 1.2389 4 80 # --- 2. Single fund, single day --- df_day = tefas.fetch(start="2025-04-01", name="YAC") print(df_day[["date", "price"]]) # date price # 0 2025-04-01 1.3112 # --- 3. Select specific columns --- df_slim = tefas.fetch( start="2025-01-01", end="2025-03-31", name="TI2", columns=["code", "date", "price"], ) print(df_slim.dtypes) # code object # date object # price float64 # --- 4. datetime objects as input --- df_dt = tefas.fetch( start=datetime(2025, 2, 1), end=datetime(2025, 2, 28), name="ATA", ) # --- 5. Exchange-traded fund type (BYF) --- df_byf = tefas.fetch(start="2025-01-15", end="2025-01-31", name="GLDTR", kind="BYF") # --- 6. Requesting a deprecated column triggers a warning, not an error --- with warnings.catch_warnings(record=True) as caught: warnings.simplefilter("always") df_warn = tefas.fetch( start="2025-04-01", name="YAC", columns=["code", "date", "price", "market_cap"], # market_cap is gone ) if caught: print(caught[0].message) # Columns no longer exposed by the tefas.gov.tr API and omitted: ['market_cap'] print(df_warn.columns.tolist()) # ['code', 'date', 'price'] # --- 7. Bulk fetch (no name) — emits UserWarning, capped at fund_limit --- with warnings.catch_warnings(record=True) as caught: warnings.simplefilter("always") df_bulk = tefas.fetch(start="2025-04-01", kind="YAT") print(caught[0].category.__name__) # UserWarning print(len(df_bulk["code"].unique())) # up to 50 unique fund codes # --- 8. Empty result when API returns no data --- df_empty = tefas.fetch(start="2015-01-01", name="NONEXISTENT") print(df_empty.empty) # True print(df_empty.columns.tolist()) # ['date', 'code', 'title', 'price', 'category_rank', 'category_total'] ``` ``` -------------------------------- ### Fetch Single Fund Data for a Single Day Source: https://context7.com/burakyilmaz321/tefas-crawler/llms.txt Retrieve price data for a single fund ('YAC') for a specific day. Only the 'date' and 'price' columns are printed. ```python # --- 2. Single fund, single day --- df_day = tefas.fetch(start="2025-04-01", name="YAC") print(df_day[["date", "price"]]) # date price # 0 2025-04-01 1.3112 ``` -------------------------------- ### Handle Empty Results Source: https://context7.com/burakyilmaz321/tefas-crawler/llms.txt Fetch data for a non-existent fund ('NONEXISTENT'). The result is an empty DataFrame, indicated by `df_empty.empty` being True. The columns of the empty DataFrame are still listed. ```python # --- 8. Empty result when API returns no data --- df_empty = tefas.fetch(start="2015-01-01", name="NONEXISTENT") print(df_empty.empty) # True print(df_empty.columns.tolist()) # ['date', 'code', 'title', 'price', 'category_rank', 'category_total'] ``` -------------------------------- ### Fetch Single Fund Data with Specific Columns Source: https://context7.com/burakyilmaz321/tefas-crawler/llms.txt Retrieve data for a single fund ('TI2') within a date range, selecting only 'code', 'date', and 'price' columns. The output shows the data types of the selected columns. ```python # --- 3. Select specific columns --- df_slim = tefas.fetch( start="2025-01-01", end="2025-03-31", name="TI2", columns=["code", "date", "price"], ) print(df_slim.dtypes) # code object # date object # price float64 ``` -------------------------------- ### Handle Deprecated Columns with Warnings Source: https://context7.com/burakyilmaz321/tefas-crawler/llms.txt Attempt to fetch data including a deprecated column ('market_cap'). The library catches this and issues a UserWarning, omitting the column rather than raising an error. The output shows the available columns after omitting the deprecated one. ```python # --- 6. Requesting a deprecated column triggers a warning, not an error --- with warnings.catch_warnings(record=True) as caught: warnings.simplefilter("always") df_warn = tefas.fetch( start="2025-04-01", name="YAC", columns=["code", "date", "price", "market_cap"], # market_cap is gone ) if caught: print(caught[0].message) # Columns no longer exposed by the tefas.gov.tr API and omitted: ['market_cap'] print(df_warn.columns.tolist()) # ['code', 'date', 'price'] ``` -------------------------------- ### Fetch Exchange-Traded Fund (BYF) Data Source: https://context7.com/burakyilmaz321/tefas-crawler/llms.txt Retrieve data for an exchange-traded fund ('GLDTR') within a specified date range by setting the 'kind' parameter to 'BYF'. ```python # --- 5. Exchange-traded fund type (BYF) --- df_byf = tefas.fetch(start="2025-01-15", end="2025-01-31", name="GLDTR", kind="BYF") ``` -------------------------------- ### fetch Source: https://github.com/burakyilmaz321/tefas-crawler/blob/main/README.md Fetches investment fund information from TEFAS. It can retrieve data for all funds or a specific fund within a given date range and allows for column selection and fund type filtering. ```APIDOC ## fetch(start, end, name, columns, kind) ### Description Fetches investment fund information from TEFAS. It can retrieve data for all funds or a specific fund within a given date range and allows for column selection and fund type filtering. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **start** (string or datetime.datetime) - Required - The date that fund information is crawled for. - **end** (string or datetime.datetime) - Optional - End of the period that fund information is crawled for. - **name** (string) - Optional - Name of the fund. If not given, all funds will be returned. - **columns[]** (list of string) - Optional - List of columns to be returned. - **kind** (string) - Optional - Type of the fund. One of `YAT`, `EMK`, or `BYF`. Defaults to `YAT`. ### Request Example ```python data = tefas.fetch(start="2020-11-20") ``` ### Request Example 2 ```python data = tefas.fetch(start="2020-11-15", end="2020-11-20", name="YAC", columns=["code", "date", "price"]) ``` ### Response #### Success Response (200) - **data** (object) - Fund information data. #### Response Example ```json { "example": "[Fund data]" } ``` ``` -------------------------------- ### Parse Dates with _parse_date Utility Source: https://context7.com/burakyilmaz321/tefas-crawler/llms.txt Internal helper to normalize string, datetime.datetime, or datetime.date inputs to a datetime.date object. Raises ValueError for unsupported formats. ```python from datetime import date, datetime from tefas.crawler import _parse_date # String input print(_parse_date("2025-04-15")) # datetime.date(2025, 4, 15) # datetime input (time component is stripped) print(_parse_date(datetime(2025, 4, 15, 12, 30))) # datetime.date(2025, 4, 15) # date input (pass-through) print(_parse_date(date(2025, 4, 15))) # datetime.date(2025, 4, 15) # Bad format raises ValueError try: _parse_date("15-04-2025") except ValueError as e: print(e) # Date string format is incorrect. It should be `YYYY-MM-DD` ``` -------------------------------- ### Deserialize TEFAS API Data with InfoSchema Source: https://context7.com/burakyilmaz321/tefas-crawler/llms.txt Use InfoSchema to map raw JSON keys from the TEFAS API to clean Python field names. Unknown keys are excluded by default. Supports bulk deserialization with `many=True`. ```python from tefas.schema import InfoSchema, BreakdownSchema schema = InfoSchema() # Inspect available fields print(list(schema.fields.keys())) # ['date', 'code', 'title', 'price', 'category_rank', 'category_total'] # Deserialize a raw API response row manually raw_row = { "tarih": "2025-04-01", "fonKodu": "YAC", "fonUnvan": "Yapı Kredi Varlık Yönetimi Fonu", "fiyat": 1.3112, "kategoriDerece": 5, "kategoriFonSay": 80, } result = schema.load(raw_row) print(result) # {'date': datetime.date(2025, 4, 1), 'code': 'YAC', # 'title': 'Yapı Kredi Varlık Yönetimi Fonu', 'price': 1.3112, # 'category_rank': 5, 'category_total': 80} # Unknown keys are silently excluded (Meta: unknown = EXCLUDE) raw_with_extras = {**raw_row, "bilinmeyen": "ignored"} clean = schema.load(raw_with_extras) print("bilinmeyen" in clean) # False # Bulk deserialization (many=True) bulk_schema = InfoSchema(many=True) rows = bulk_schema.load([raw_row, raw_row]) print(len(rows)) # 2 # BreakdownSchema is a no-op stub — loads nothing, errors on nothing breakdown = BreakdownSchema() print(breakdown.load({"anything": 123})) # {} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.