Fetch live and historical stock prices for Indian and American exchanges.
Project description
jyapystock
A Python library to fetch live and historical prices for Indian and American stocks.
Status Badges
Features
- Live price and historical price support with timestamp and % change data
- Indian (NSE) and American (NYSE/NASDAQ) stocks
- Multiple data sources: yfinance, NASDAQ, NSE (for India), Alpha Vantage (optional API key)
- Auto-fallback: tries available sources in order based on country and API key availability
- Country support:
IndiaandUSAwith automatic symbol variant detection (e.g.,.NS,.BOfor Indian stocks)
Installation
pip install jyapystock
Installation for Development
To install locally for development:
# Install editable for development
pip install -e .
# Or install for local use
pip install .
For development and CI reproducibility, install pinned dev dependencies:
pip install -r requirements-dev.txt
Usage
Basic Usage - USA Stocks
from jyapystock import StockPriceProvider
# Using yfinance (default)
provider = StockPriceProvider(country="USA")
result = provider.get_live_price("AAPL")
# Returns: {'timestamp': '2025-12-24T00:00:00-05:00', 'price': 273.81, 'change_percent': 0.53}
Indian Stocks with NSE
from jyapystock import StockPriceProvider
# Using NSE (National Stock Exchange)
provider = StockPriceProvider(country="India", source="nse")
result = provider.get_live_price("SBIN")
# Returns: {'timestamp': '24-Dec-2025 16:00:00', 'price': 968.85, 'change_percent': -0.31}
# Using yfinance for India (auto-tries .NS and .BO variants)
provider = StockPriceProvider(country="India")
result = provider.get_live_price("RELIANCE")
Historical Data
# Get historical prices
hist = provider.get_historical_price("AAPL", "2023-01-01", "2023-01-31")
# Returns list of records with date/open/high/low/close/volume
Using NASDAQ Provider
provider = StockPriceProvider(country="USA", source="nasdaq")
result = provider.get_live_price("AAPL")
Using Alpha Vantage (requires API key)
provider = StockPriceProvider(
country="USA",
source="alphavantage",
alpha_vantage_api_key="YOUR_API_KEY"
)
result = provider.get_live_price("AAPL")
Supported Sources
- yfinance: Free, supports most global stocks (USA & India)
- NASDAQ: Free, USA stocks only
- NSE: Free, Indian stocks only (via National Stock Exchange)
- Alpha Vantage: Free tier with limits, requires API key, supports global stocks
- NYSE: Free, USA stocks only
Testing
python -m unittest discover tests
# Run provider-specific tests
PROVIDER=yfinance python -m unittest discover tests
PROVIDER=nse python -m unittest discover tests
PROVIDER=nasdaq python -m unittest discover tests
PROVIDER=alphavantage python -m unittest discover tests
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
jyapystock-0.3.0.tar.gz
(13.9 kB
view details)
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 jyapystock-0.3.0.tar.gz.
File metadata
- Download URL: jyapystock-0.3.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9eaac45ceb134e9d98253b7e03b6c80402ff6fad24d83f793d89bf499ae1bf1
|
|
| MD5 |
527991aa226b7e6fe97242c65b66b570
|
|
| BLAKE2b-256 |
2caaf6183f6e794aa82a569efde756f3de4e3c3a8f46a4d83bb68b4bfcb5e4c3
|
File details
Details for the file jyapystock-0.3.0-py3-none-any.whl.
File metadata
- Download URL: jyapystock-0.3.0-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b044da4369d33090bc613c0facf6fe386e00cbf8fb58cdf56ed656e903a2e7ef
|
|
| MD5 |
c59dc8cca92635cb259f2190cbd0e6de
|
|
| BLAKE2b-256 |
f14d7ae97474001691a43d6f2443effd5b87c4324e242a0ee9d451151d4723ba
|