Skip to main content

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

CI

yfinance tests Alpha Vantage tests NASDAQ tests NYSE tests NSE tests BSE tests

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: India and USA with automatic symbol variant detection (e.g., .NS, .BO for 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

Project details


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.4.3.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jyapystock-0.4.3-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file jyapystock-0.4.3.tar.gz.

File metadata

  • Download URL: jyapystock-0.4.3.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for jyapystock-0.4.3.tar.gz
Algorithm Hash digest
SHA256 bbee9eac19a6af02c91513513541becde51c4cbf886c7d71cef35f0e29108653
MD5 df69504b812c0f273c2d894cc93bdd3a
BLAKE2b-256 fcd3d93d095eb0877349ed8fec8940d5175be4dbf3f008005020fa819587b207

See more details on using hashes here.

File details

Details for the file jyapystock-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: jyapystock-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for jyapystock-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0729c751b9a132508dbb7a1f683ca84b5124addac0d1eaf0ccdc1347d5a9306b
MD5 0be2d03f63be58bcfb0f575efa2a6f79
BLAKE2b-256 f0cb9a6478e082ee43e68b4d0db72c81d57c2f33867791e745d8ee129a1dda1f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page