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.
Badges (overall + provider status):
Features
- Live price and historical price support
- Indian (NSE/BSE) and American (NYSE/NASDAQ) stocks
- Multiple data sources: yfinance (default), Alpha Vantage (optional)
- Multiple data sources: yfinance, Alpha Vantage (optional)
- Auto-fallback: if
sourceis not provided (or set toNoneor'auto'), the provider will try available free sources in order:yfinancefirst, thenAlpha Vantageif an API key is available. - Auto-fallback: if
sourceis not provided (or set toNoneor'auto'), the provider will try available free sources in order:yfinancefirst, thenAlpha Vantageif an API key is available. - Country:
StockPriceProvidernow requires acountryargument. Supported values:India,USA.- For
India, when usingyfinancethe provider will try symbol variants in this order when the symbol has no exchange suffix:SYMBOL.NS,SYMBOL.BO, thenSYMBOL.
- For
Installation
pip install -r requirements.txt
Installing as a library (recommended)
This project is intended to be used as a Python library. To install locally (editable/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
from jyapystock.stock_price_provider import StockPriceProvider
provider = StockPriceProvider(country="USA", source="yfinance")
hist = provider.get_historical_price("AAPL", "2023-01-01", "2023-01-31")
from jyapystock.stock_price_provider import StockPriceProvider
provider = StockPriceProvider(country="India", source="yfinance")
price_in = provider.get_live_price("RELIANCE")
hist = provider.get_historical_price("RELIANCE", "2023-01-01", "2023-01-31")
# Using Alpha Vantage (requires API key)
# Auto mode (recommended): omit `source` or set `source=None` / `source='auto'`.
provider_av = StockPriceProvider(country="USA", source="alphavantage", alpha_vantage_api_key="YOUR_API_KEY")
price_av = provider_av.get_live_price("AAPL")
hist_av = provider_av.get_historical_price("AAPL", "2023-01-01", "2023-01-31")
Note: start and end parameters accepted by get_historical_price may be either string dates (e.g. "2023-01-01") or datetime objects. All providers normalize these inputs internally.
Supported Sources
- yfinance: Free, supports most global stocks
- Alpha Vantage: Free tier, requires API key, supports global stocks
- Polygon.io, IEX Cloud: Paid, US stocks (not implemented yet)
Testing
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
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.2.0.tar.gz.
File metadata
- Download URL: jyapystock-0.2.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e8f070467f0de3a210e5160dfbe8383a7456d3c162010bcbd953b9abeba1ae4
|
|
| MD5 |
93bdb54333f27d45f6ba9fdbf7dde530
|
|
| BLAKE2b-256 |
00ef7959146ffe20afb6158f08a6accb5894d5878f95e8ad8f0a1be6bc77a1ea
|
File details
Details for the file jyapystock-0.2.0-py3-none-any.whl.
File metadata
- Download URL: jyapystock-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.3 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 |
20020eac4c81434394ae71d2b43c11da99dcc25bf95c473e82f5ea9184df8b7d
|
|
| MD5 |
a99b4168b00d44cbd0a8357a42f37ba0
|
|
| BLAKE2b-256 |
0d020cb0fa448d6efdecdc693aafe4d31c1a23ca7b6923977e0ce8648a58ac1b
|