A structured Python interface for retrieving and validating market data using yfinance
Project description
py-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:
- Exchanges: Map exchanges (e.g.,
IBIS,AEB) to Yahoo suffixes (.DE,.AS). - Price Validation: Verify tickers against a known target price with strict 1% tolerance.
- Date Validation: Validate prices on specific historical dates.
- Exchanges: Map exchanges (e.g.,
- Typer CLI: Optional command-line interface for lookup and history.
Installation
# Basic installation
uv pip install py-yfinance
# With CLI support
uv pip install "py-yfinance[cli]"
Usage
As a Library
from py_yfinance.source import YFinanceDataSource
from pydantic_market_data.models import SecurityCriteria
source = YFinanceDataSource()
# 1. Simple Lookup by Symbol
criteria = SecurityCriteria(symbol="AAPL", preferred_exchanges=["NASDAQ"])
result = source.resolve(criteria)
print(result)
# Symbol(ticker='AAPL', name='Apple Inc.', exchange='NMS', currency='USD', ...)
# 2. Strict Validation using Date & Price
# Useful for verifying ISIN mappings or ensuring data quality
criteria = SecurityCriteria(
isin="NL0010273215",
target_date="2025-12-15",
target_price=923.4 # Validates against history with 1% tolerance
)
match = source.resolve(criteria)
if match:
print(f"Verified: {match.ticker}")
else:
print("Validation failed: Price mismatch or symbol not found")
CLI Usage
Requires [cli] extra.
Lookup
Resolve a security by Symbol or ISIN.
# Basic Lookup
uv run py-yfinance lookup --symbol AAPL
# ISIN Lookup with Strict Validation
# Verifies that NL0010273215 commanded a price of ~923.4 on 2025-12-15
uv run py-yfinance lookup --isin NL0010273215 --date 2025-12-15 --price 923.4
History
Fetch historical candles.
uv run py-yfinance history AAPL --period 5d
Development
This project uses uv for dependency management.
# Sync dependencies
uv sync --extra cli
# Run Tests
uv run pytest
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_yfinance-0.1.0.tar.gz.
File metadata
- Download URL: py_yfinance-0.1.0.tar.gz
- Upload date:
- Size: 79.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47845fe0b8257c1b415345617bdeec72f34ca3b665718f654ee9fdbdeacf580d
|
|
| MD5 |
166b32e18921b4c906e92aafe9eb8c99
|
|
| BLAKE2b-256 |
c726348361d06f2d6bf312aed20b43701283e5112a3719bc3fd55321a05f0e30
|
File details
Details for the file py_yfinance-0.1.0-py3-none-any.whl.
File metadata
- Download URL: py_yfinance-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc261fd7b9d688dd0d773474422305dddf0d3c88c340352e7f84324f1f9608d9
|
|
| MD5 |
262aa33aeb1f7fee29c9d3d7d05867af
|
|
| BLAKE2b-256 |
5a7c458608b425bbad68e37cba4d1c71329687f88259710d6f4d7b2f92562a19
|