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")
Multiple Providers with Fallback
You can specify multiple sources as a list. The provider will try them in order until one returns data:
# Try NSE first, then fall back to yfinance for Indian stocks
provider = StockPriceProvider(country="India", source=["nse", "yfinance"])
result = provider.get_live_price("RELIANCE")
# Try NASDAQ first, then NASDAQ, then yfinance for USA stocks
provider = StockPriceProvider(country="USA", source=["nasdaq", "yfinance"])
result = provider.get_live_price("AAPL")
# Try BSE for historical data, fall back to yfinance
provider = StockPriceProvider(country="India", source=["bse", "yfinance"])
hist = provider.get_historical_price("NSDL", "2025-12-01", "2025-12-31")
You can also pass a single provider as a string:
# Equivalent to source=["bse"]
provider = StockPriceProvider(country="India", source="bse")
result = provider.get_live_price("NSDL")
Supported Sources
- yfinance: Free, supports most global stocks (USA & India)
- NASDAQ: Free, USA stocks only
- NYSE: Free, USA stocks only
- NSE: Free, Indian stocks only (via National Stock Exchange)
- BSE: Free, Indian stocks only (via Bombay Stock Exchange)
- Alpha Vantage: Free tier with limits, requires API key, supports global stocks
Testing
Install library in editable mode
pip install -e .
Run tests
python -m unittest discover tests
# Run provider-specific tests
PROVIDER=yfinance python -m unittest discover tests
PROVIDER=nse python -m unittest discover tests
PROVIDER=bse python -m unittest discover tests
PROVIDER=nasdaq python -m unittest discover tests
PROVIDER=alphavantage python -m unittest discover tests
License
MIT
Metadata
Release files for jyapystock 0.4.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| jyapystock-0.4.6.tar.gz | 16.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| jyapystock-0.4.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.1 kB
Release files / jyapystock-0.4.6.tar.gz
| Download URL | jyapystock-0.4.6.tar.gz |
|---|---|
| Size | 16.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c22cd283b49fdf39a4f46981470d80b287a02c59f3af0a4e1549881c770c5055
|
|
BLAKE2b-256 checksum How to use checksums |
f753f0188dec408307d3105873e81e90108b726e58e9ab11463684527579d211
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.4
|
Release files / jyapystock-0.4.6-py3-none-any.whl
| Download URL | jyapystock-0.4.6-py3-none-any.whl |
|---|---|
| Size | 17.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a723148109e0d504c95ecb647d55fbf8bb32916a9706d7e5fda4b018aa6b7bef
|
|
BLAKE2b-256 checksum How to use checksums |
e3f8bd9ce62ee23a3361d02bb6a7ef8e50626f7fdbfb515c7839b272659af034
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.4
|