Skip to main content

pykrx-openapi

KRX(한국거래소) OpenAPI를 위한 Python 래퍼

주요 기능

  • KRX OpenAPI 지원
  • 자동 데이터 타입 변환 (문자열을 int/float/datetime으로)
  • 속도 제한 (기본값: , 설정 가능)

설치

pip install pykrx-openapi

또는 uv 사용:

uv pip install pykrx-openapi

시작하기 전에

시작하기 전에, KRX OpenAPI 키를 발급받았나요? KRX OpenAPI 이용 방법을 참조하세요.

키 뿐 아니라 각 API에 대해서도 "API 이용 신청"을 해야 합니다.

이 과정이 어려운 분들은 KRX OpenAPI 따라하기 문서를 참고하세요.

빠른 시작

from pykrx_openapi import KRXOpenAPI

# API 키로 초기화
client = KRXOpenAPI(api_key="your-api-key")

# 또는 환경 변수 사용: KRX_OPENAPI_KEY
import os
os.environ["KRX_OPENAPI_KEY"] = "your-api-key"
client = KRXOpenAPI()

# KOSPI 일별 거래 데이터 조회
data = client.get_kospi_daily_trade(bas_dd="20260101")
print(data)

API 목록

지수 (idx) - 5개 엔드포인트

  • get_krx_daily_trade() - KRX 시리즈 일별시세정보
  • get_kospi_daily_trade() - KOSPI 시리즈 일별시세정보
  • get_kosdaq_daily_trade() - KOSDAQ 시리즈 일별시세정보
  • get_bond_index_daily_trade() - 채권지수 시세정보
  • get_derivative_index_daily_trade() - 파생상품지수 시세정보

주식 (sto) - 8개 엔드포인트

  • get_stock_daily_trade() - 유가증권 일별매매정보
  • get_kosdaq_stock_daily_trade() - 코스닥 일별매매정보
  • get_konex_daily_trade() - 코넥스 일별매매정보
  • get_stock_warrant_daily_trade() - 신주인수권증권 일별매매정보
  • get_short_covering_daily_trade() - 신주인수권증서 일별매매정보
  • get_stock_base_info() - 유가증권 종목기본정보
  • get_kosdaq_stock_base_info() - 코스닥 종목기본정보
  • get_konex_base_info() - 코넥스 종목기본정보

ETP (etp) - 3개 엔드포인트

  • get_etf_daily_trade() - ETF 일별매매정보
  • get_etn_daily_trade() - ETN 일별매매정보
  • get_elw_daily_trade() - ELW 일별매매정보

채권 (bon) - 3개 엔드포인트

  • get_kts_bond_daily_trade() - 국채전문유통시장 일별매매정보
  • get_bond_daily_trade() - 일반채권시장 일별매매정보
  • get_small_bond_daily_trade() - 소액채권시장 일별매매정보

파생상품 (drv) - 6개 엔드포인트

  • get_futures_daily_trade() - 선물 일별매매정보 (주식선물外)
  • get_kospi_stock_futures_daily_trade() - 주식선물(유가) 일별매매정보
  • get_kosdaq_stock_futures_daily_trade() - 주식선물(코스닥) 일별매매정보
  • get_options_daily_trade() - 옵션 일별매매정보 (주식옵션外)
  • get_kospi_stock_options_daily_trade() - 주식옵션(유가) 일별매매정보
  • get_kosdaq_stock_options_daily_trade() - 주식옵션(코스닥) 일별매매정보

일반시장 (gen) - 3개 엔드포인트

  • get_oil_daily_trade() - 석유시장 일별매매정보
  • get_gold_daily_trade() - 금시장 일별매매정보
  • get_emissions_daily_trade() - 배출권 시장 일별매매정보

ESG (esg) - 3개 엔드포인트

  • get_sri_bond_info() - 사회책임투자채권 정보
  • get_esg_etp_info() - ESG 증권상품
  • get_esg_index_info() - ESG 지수

설정

client = KRXOpenAPI(
    api_key="your-key",      # API 키 (또는 KRX_OPENAPI_KEY 환경 변수 사용)
    rate_limit=10,            # 기간당 최대 요청 수 (기본값: 10)
    per_seconds=1,            # 시간 기간(초) (기본값: 1)
    timeout=30,               # 요청 타임아웃(초) (기본값: 30)
    debug=False               # 디버그 로깅 활성화 (기본값: False)
)

에러 처리

from pykrx_openapi import (
    KRXOpenAPI,
    KRXAuthenticationError,
    KRXInvalidDateError,
    KRXNetworkError
)

try:
    client = KRXOpenAPI()
    data = client.get_kospi_daily_trade("20240101")
except KRXAuthenticationError:
    print("유효하지 않은 API 키입니다")
except KRXInvalidDateError:
    print("날짜는 YYYYMMDD 형식이어야 합니다")
except KRXNetworkError as e:
    print(f"네트워크 오류: {e}")

개발

# 저장소 클론
git clone https://github.com/raccoonyy/pykrx-openapi.git
cd pykrx-openapi

# uv로 의존성 설치
uv sync --dev

# 테스트 실행
uv run pytest

# 커버리지와 함께 테스트 실행
uv run pytest --cov

# 린터 실행
uv run ruff check src/ tests/

라이선스

MIT 라이선스 - 자세한 내용은 LICENSE 파일을 참조하세요

기여

기여를 환영합니다! Pull Request를 자유롭게 제출해 주세요.

Release files for pykrx-openapi 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pykrx-openapi 0.1.1
File Size Uploaded
pykrx_openapi-0.1.1.tar.gz 16.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for pykrx-openapi 0.1.1
File Interpreter ABI Platform
pykrx_openapi-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 16.1 MB

Release files / pykrx_openapi-0.1.1.tar.gz

Download URL pykrx_openapi-0.1.1.tar.gz
Size 16.1 MB
Tags Source
SHA-256 checksum
How to use checksums
891c89ddbc1a8e99044f3201b868bb7530b3e38453096834169615588c79ed06
BLAKE2b-256 checksum
How to use checksums
9a2d893d9a77ac2e66e2c7dcdebe046e991a162b7a026942f8b2d0b4d5f84656
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 20, 2026.

Transparency log

Release files / pykrx_openapi-0.1.1-py3-none-any.whl

Download URL pykrx_openapi-0.1.1-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd2a65224645db0fbec2d173ed4140d1bb25040a0a8de5aee3500ebd35114718
BLAKE2b-256 checksum
How to use checksums
49b3ae37e596307591f6305d89573103d21766337ffb4b65bdf681e9331c792b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jan 20, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page