Financial data library for prices and index constituents
Project description
Y-Not-Finance
A comprehensive Python library for fetching financial data, combining Yahoo Finance price data with stock index constituents from multiple sources.
Features
๐ Prices Module
- Multi-ticker concurrent fetching - Fetch data for multiple stocks simultaneously
- Automatic retry with exponential backoff - Resilient to API rate limits
- Flexible intervals - Support for intraday (1m, 5m, 15m, 30m, 1h) and daily+ (1d, 1wk, 1mo) data
- Multiple fields - Open, High, Low, Close, Volume, Adjusted Close
- Date range filtering - Easy-to-use range strings like "1mo", "3mo", "1y"
๐ข Constituents Module
- Multiple indexes - S&P 500, NASDAQ, Dow Jones, TSX, and market cap tiers
- Unified API - Single function to access all data sources
- Company names included - Get both ticker symbols and full company names
- Automatic pagination - Handles large datasets seamlessly
Installation
pip install -e .
Or install from requirements:
pip install -r requirements.txt
Quick Start
Fetch Price Data
from y_not_finance import YahooFinanceClient
# Initialize the client
client = YahooFinanceClient()
# Single ticker
df = client.get_prices("AAPL", range_str="1mo")
# Multiple tickers
df = client.get_prices(["AAPL", "MSFT", "GOOGL"], range_str="3mo", fields="close")
# Multiple fields
df = client.get_prices(
["AAPL", "MSFT"],
range_str="1y",
interval="1d",
fields=["open", "high", "low", "close", "volume"]
)
Fetch Index Constituents
from y_not_finance import get_constituents
# Get S&P 500 constituents
tickers, description = get_constituents("^SPX", info=True)
# Get TSX constituents
tickers, description = get_constituents("^GSPTSE", include_benchmark=True)
# Get mega cap stocks
tickers, description = get_constituents("megacaps")
Combined Usage
from y_not_finance import YahooFinanceClient, get_constituents
# Get index constituents
sp500_tickers, _ = get_constituents("^SPX")
# Fetch prices for all constituents
client = YahooFinanceClient()
df = client.get_prices(
list(sp500_tickers.keys()),
range_str="1mo",
fields="adjclose"
)
Package Structure
y_not_finance/
โโโ __init__.py # Main package API
โ
โโโ prices/ # Price data module
โ โโโ __init__.py
โ โโโ client.py # YahooFinanceClient class
โ โโโ fetcher.py # HTTP request handling
โ โโโ parser.py # JSON parsing logic
โ โโโ processor.py # DataFrame processing
โ โโโ utils.py # Utility functions
โ โโโ constants.py # Configuration constants
โ
โโโ constituents/ # Index constituents module
โโโ __init__.py
โโโ client.py # get_constituents() function
โโโ config.py # Index configurations
โโโ utils.py # Validation utilities
โโโ scrapers/ # Data source scrapers
โโโ __init__.py
โโโ stock_analysis.py # StockAnalysis.com scraper
โโโ tsx.py # Globe and Mail TSX scraper
See PACKAGE_STRUCTURE.md for detailed structure documentation.
Documentation
- QUICK_REFERENCE.md - Common tasks and examples
- ARCHITECTURE.md - System architecture overview
- PACKAGE_STRUCTURE.md - Package layout details
Supported Indexes
| Key | Index Name | Source |
|---|---|---|
| ^SPX | S&P 500 Index | StockAnalysis.com |
| ^DJI | Dow Jones Industrial Average | StockAnalysis.com |
| ^IXIC | NASDAQ Composite | StockAnalysis.com |
| ^GSPTSE | S&P/TSX Composite (Canada) | Globe and Mail |
| megacaps | Mega Cap Stocks | StockAnalysis.com |
| largecaps | Large Cap Stocks | StockAnalysis.com |
| midcaps | Mid Cap Stocks | StockAnalysis.com |
| smallcaps | Small Cap Stocks | StockAnalysis.com |
| microcaps | Micro Cap Stocks | StockAnalysis.com |
| nanocaps | Nano Cap Stocks | StockAnalysis.com |
Examples
See the examples/ directory for comprehensive usage examples:
combined_usage.py- Complete demonstration of all featuresbasic_usage.py- Simple price fetchingfinancial_analysis.py- Analysis workflowsdata_export.py- Export to CSV/Excel
Run an example:
python examples/combined_usage.py
Requirements
- Python 3.8+
- numpy
- pandas
- requests
Optional:
- pyarrow (for Parquet export in examples)
See requirements.txt for complete dependencies.
License
See LICENSE file for details.
Changelog
Version 1.0.0
- Complete restructure into modular package
- Separated prices and constituents into submodules
- Improved code organization following best practices
- Added comprehensive documentation
- Enhanced error handling and logging
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 y_not_finance-1.0.0.tar.gz.
File metadata
- Download URL: y_not_finance-1.0.0.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5082c1cc42e870c7ef9f072ce0d32a5fe6fa8c7cebe4e7858a3c01bb80699faa
|
|
| MD5 |
11492218518d1ee89a81704898d91a62
|
|
| BLAKE2b-256 |
e2d619aec160fcba630622540bb4713ba74be60b631209b8a5345a585ee3dfcc
|
File details
Details for the file y_not_finance-1.0.0-py3-none-any.whl.
File metadata
- Download URL: y_not_finance-1.0.0-py3-none-any.whl
- Upload date:
- Size: 18.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c2082078f9520879a39b1dec70c5ab09ebed878af78f7cdf434eade14133f18
|
|
| MD5 |
5586f263107fc151afb77b5fb6db8eba
|
|
| BLAKE2b-256 |
37c76720126b48fe19850903439b8ee10262aac75093231dbcefc6209f8e05f1
|