Getting Started
Try it Online
No installation needed - try pykabutan directly in Google Colab:
Installation
Install pykabutan using pip:
Or with uv:
Basic Usage
Import the library
Get stock information
Create a Ticker object with a stock code:
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:
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:
List available 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
- Ticker Guide - Detailed ticker usage
- Search Guide - Advanced search options
- API Reference - Complete API documentation