Skip to content

Getting Started

Try it Online

No installation needed - try pykabutan directly in Google Colab:

Open In Colab

Installation

Install pykabutan using pip:

pip install pykabutan

Or with uv:

uv add pykabutan

Basic Usage

Import the library

import pykabutan as pk

Get stock information

Create a Ticker object with a stock code:

ticker = pk.Ticker("7203")  # Toyota Motor Corporation

Access the company profile:

profile = ticker.profile

print(profile.name)      # トヨタ自動車
print(profile.market)    # 東証P
print(profile.industry)  # 輸送用機器
print(profile.per)       # Price-to-earnings ratio
print(profile.pbr)       # Price-to-book ratio

Get historical prices

# Last 30 days
df = ticker.history(period="30d")

# Last 90 days, weekly data
df = ticker.history(period="90d", interval="week")

# Explicit date range
df = ticker.history(start="2024-01-01", end="2024-12-31")

The returned DataFrame is indexed by an ascending date DatetimeIndex and contains:

Column Description
open Opening price
high High price
low Low price
close Closing price
change Price change from previous day
percent_change Price change (%) from previous day
volume Trading volume

Because the index is a DatetimeIndex, you can slice by date directly:

df.loc["2024-06"]  # every row in June 2024

Search for stocks

Search by industry:

# Get all electronics companies
results = pk.search_by_industry("電気機器")

for t in results[:5]:
    print(f"{t.code}: {t.profile.name}")

Search by theme:

# Search for AI-related stocks (use Japanese terms)
results = pk.search_by_theme("人工知能")

List available industries:

industries = pk.list_industries()
print(industries)

Configuration

Configure request behavior:

# Set timeout (seconds)
pk.config.timeout = 60

# Set delay between requests (seconds)
pk.config.request_delay = 1.0

# Reset to defaults
pk.config.reset()

Error Handling

from pykabutan import TickerNotFoundError

try:
    ticker = pk.Ticker("9999999")
    profile = ticker.profile
except TickerNotFoundError as e:
    print(f"Ticker not found: {e.code}")

Next Steps