Published yfinance-pl to PyPI
Table of Contents
Overview
I published yfinance-pl to PyPI. It’s a stock data retrieval library that wraps yfinance-rs for Python with enhanced type safety. Unlike the traditional yfinance, it returns pl.DataFrame instead of pd.DataFrame.
Why I Created This
Recently, I’ve had opportunities to use Polars as an alternative to Pandas, and it’s gradually gaining adoption as modern libraries add Polars support. Polars is a high-performance DataFrame library built in Rust, offering benefits like faster speed and lower memory consumption compared to Pandas. For handling large-scale data analysis and Polars-only processing pipelines, I believed that having yfinance—the gateway to stock analysis—natively support Polars would enable smoother analysis and a better developer experience. I wanted users who prefer analyzing with Polars to do so without worrying about whether they’re dealing with Polars DataFrames or Pandas DataFrames. That’s why I wrapped yfinance-rs with enhanced type safety to implement yfinance-pl.
Features
yfinance-Compatible API
You can fetch stock data using the same API as yfinance. Existing code using yfinance can be migrated with minimal changes.
import yfinance_pl as yf
ticker = yf.Ticker("AAPL")
history = ticker.history(period="1mo")Rust Backend
It wraps yfinance-rs with PyO3, so data fetching is executed in Rust.
Type-Safe API
The period and interval parameters use Literal types, enabling IDE autocompletion.
# period accepts: "1d", "5d", "1mo", "3mo", "6mo", "1y", "2y", "5y", "10y", "ytd", "max"
# interval accepts: "1m", "2m", "5m", "15m", "30m", "60m", "90m", "1h", "1d", "5d", "1wk", "1mo", "3mo"
history = ticker.history(period="1mo", interval="1d")Additionally, return values like TickerInfo, FastInfo, and CalendarInfo have TypedDict definitions, so dictionary keys are also autocompleted in your IDE.
Comparison with yfinance
| Item | yfinance | yfinance-pl |
|---|---|---|
| DataFrame Type | pd.DataFrame | pl.DataFrame |
| Backend | Python | Rust (yfinance-rs) |
| Series Type | pd.Series | pl.DataFrame |
| Type Hints | Partial | Supported |
Supported Features
yfinance-pl supports the following features:
| Category | Property/Method | Return Type |
|---|---|---|
| Price History | history() | pl.DataFrame |
| Company Info | info, fast_info, calendar | dict |
| Dividends & Splits | dividends, splits, actions, capital_gains | pl.DataFrame |
| Financial Statements | income_stmt, balance_sheet, cashflow | pl.DataFrame |
| Quarterly Financials | quarterly_income_stmt, quarterly_balance_sheet, quarterly_cashflow | pl.DataFrame |
| Shareholder Info | major_holders, institutional_holders, mutualfund_holders | pl.DataFrame |
| Insider | insider_transactions, insider_roster_holders | pl.DataFrame |
| Analyst | recommendations, upgrades_downgrades | pl.DataFrame |
| Options | options, option_chain() | list[str], OptionChain |
Usage Examples
Fetching Price History
import yfinance_pl as yf
ticker = yf.Ticker("AAPL")
# Daily data for the last month
history = ticker.history(period="1mo", interval="1d")
print(history)Output example:
shape: (21, 7)
┌─────────────────────────┬────────────┬────────────┬────────────┬────────────┬──────────────┬───────────┐
│ date ┆ open ┆ high ┆ low ┆ close ┆ volume ┆ dividends │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ datetime[ns, UTC] ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ i64 ┆ f64 │
╞═════════════════════════╪════════════╪════════════╪════════════╪════════════╪══════════════╪═══════════╡
│ 2024-10-28 00:00:00 UTC ┆ 233.160004 ┆ 234.729996 ┆ 232.550003 ┆ 233.399994 ┆ 23819200 ┆ 0.0 │
│ ... ┆ ... ┆ ... ┆ ... ┆ ... ┆ ... ┆ ... │
└─────────────────────────┴────────────┴────────────┴────────────┴────────────┴──────────────┴───────────┘Fetching Financial Statements
# Income Statement
income = ticker.income_stmt
print(income)
# Balance Sheet
balance = ticker.balance_sheet
print(balance)
# Cash Flow Statement
cashflow = ticker.cashflow
print(cashflow)Fetching Option Chains
# Get available expiration dates
dates = ticker.options
print(dates)
# Get option chain for a specific expiration date
chain = ticker.option_chain("2024-12-20")
print(chain.calls) # Call options
print(chain.puts) # Put optionsInstallation
It’s uploaded to PyPI, so you can install it with pip. You can also use uv.
pip install yfinance-plOr:
uv add yfinance-plFuture Updates
I plan to update yfinance-pl alongside updates to yfinance-rs. If there are improvements on the Python side, like the type safety enhancements, I’ll implement those as well.
Links
- PyPI: https://pypi.org/project/yfinance-pl/
- GitHub: https://github.com/rmc8/yfinance-pl
- Documentation: https://yfinance-pl.rmc-8.com
![[Python Stock Analysis] Calculating and Visualizing Ichimoku Cloud with Polars](https://b.rmc-8.com/img/2025/12/02/00541cf97f979f588ad2cad0ac6d6d7f.png)
![[Stock Analysis with Python] Weekly and Monthly Charts with Bollinger Bands to Understand Price Volatility](https://b.rmc-8.com/img/2025/12/01/0218c7e535f81400a91a9ad80357a034.png)
![[Stock Analysis with Python] Detecting Moving Averages and Golden Cross Using Modern Libraries](https://b.rmc-8.com/img/2025/12/01/5383d87b9096bc828d358edd077fef67.png)
![[Python] Automatically Record Sleep Time to Toggl](https://pub-21c8df4785a6478092d6eb23a55a5c42.r2.dev/img/eyecatch/garmin_toggl.webp)


Loading comments...