yfinance
A structured Python interface for retrieving and validating market data using yfinance.
Implements the DataSource protocol from pydantic-market-data to provide type-safe security resolution and historical data fetching.
Features
- Protocol-Oriented: Implements
DataSourceinterface. - Security Resolution: Resolve ISINs and Symbols to valid
yfinancetickers. - Validation:
- Price Validation: Verify tickers against daily high/low range.
- Date Validation: Validate prices on specific historical dates.
- CLI: Optional command-line interface for lookup and history.
Installation
uv pip install py-yfinance
Usage
As a Library
from py_yfinance import YFinanceDataSource
from pydantic_market_data.models import PriceOnDate, SecurityQuery
source = YFinanceDataSource()
# 1. Simple lookup by symbol
result = source.resolve(SecurityQuery(symbol="AAPL"))
print(result.symbol, result.price)
# 2. Strict validation by date and price
# Useful for verifying ISIN mappings or ensuring data quality
query = SecurityQuery(
isin="NL0010273215",
price_on=PriceOnDate(date="2025-12-15", price=923.4),
)
match = source.resolve(query)
if match:
print(f"Verified: {match.symbol}")
else:
print("Validation failed: price mismatch or symbol not found")
Dates accept YYYY-MM-DD, YYYY/MM/DD or YYYYMMDD; any other string raises ValidationError.
CLI Usage
Lookup
Resolve a security by symbol or ISIN.
# Basic lookup
uv run yfinance lookup --symbol AAPL
# ISIN lookup with strict validation
# Verifies that NL0010273215 traded near 923.4 on 2025-12-15
uv run yfinance lookup --isin NL0010273215 --date 2025-12-15 --price 923.4
History
Fetch daily candles.
uv run yfinance history --symbol AAPL --period 5d
Search
uv run yfinance search tesla
Output is a JSON envelope when stdout is not a terminal; pass --format plain for text. Run uv run yfinance <command> --schema for a command's input and output schema.
Development
This project uses uv for dependency management.
# Sync dependencies
uv sync
# Run Tests
uv run pytest
License
MIT
Metadata
Release files for py-yfinance 0.4.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| py_yfinance-0.4.3.tar.gz | 17.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| py_yfinance-0.4.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.3 kB
Release files / py_yfinance-0.4.3.tar.gz
| Download URL | py_yfinance-0.4.3.tar.gz |
|---|---|
| Size | 17.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30ed0b9db09796c06cd6fc004786059c635b7e4fd11995c074ba6a110ce52169
|
|
BLAKE2b-256 checksum How to use checksums |
567e8ae72ce8c3723fa03d41d627fe5b0500c399f872acd7dfcb1082c744e5db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / py_yfinance-0.4.3-py3-none-any.whl
| Download URL | py_yfinance-0.4.3-py3-none-any.whl |
|---|---|
| Size | 10.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
04981cfb29ffeb0c159674ab056418c9d7c7aa825fbc45965e0c67516094fd8d
|
|
BLAKE2b-256 checksum How to use checksums |
12a513a52dc82e0ce3e2151a82bcbb69b03cbc8df3e212a78ac436b77bfa9450
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.12.22 {"installer":{"name":"uv","version":"0.12.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|