pykrx: KRX Data Scraper

1.2.7 · active · verified Fri Apr 17

pykrx is a Python library for scraping data from the Korea Exchange (KRX) and related financial data sources (e.g., Naver Finance). It provides functions to retrieve stock prices, market capitalization, OHLCV data, ETF, and bond information. The library is actively maintained with frequent updates to adapt to changes in upstream data sources and API policies. The current version is 1.2.7.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to fetch historical OHLCV data for a specific stock and market capitalization data for KOSPI using `pykrx`.

from pykrx import stock
from datetime import datetime, timedelta

# Get today's date and 30 days ago
today = datetime.now().strftime('%Y%m%d')
start_date = (datetime.now() - timedelta(days=30)).strftime('%Y%m%d')

# Example: Get OHLCV data for Samsung Electronics (ticker: 005930) for the last 30 days
df = stock.get_market_ohlcv_by_date(start_date, today, "005930")

print(f"OHLCV data for 005930 from {start_date} to {today}:")
print(df.head())

# Example: Get market cap data for KOSPI on a specific date
df_cap = stock.get_market_cap_by_date("20231026", "KOSPI")
print(f"\nMarket cap data for KOSPI on 20231026:")
print(df_cap.head())

view raw JSON →