Skip to main content

jyapystock

A Python library to fetch live and historical prices for Indian, American, and European stocks.

Status Badges

CI

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

Features

  • Live price and historical price support with timestamp and % change data
  • Indian (NSE/BSE), American (NYSE/NASDAQ), and European (Xetra/Euronext) 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, USA, and Europe with automatic symbol variant detection (e.g., .NS/.BO for Indian stocks, .DE/.PA/.AS/.BR/.LS for European stocks)

Installation

pip install jyapystock

Installation for Development

Dependencies are locked with Poetry (poetry.lock) for CI reproducibility:

pip install poetry
poetry install --extras dev

This installs the package in editable mode along with dev tools (pytest, pytest-cov, flake8). Run commands inside the managed environment with poetry run, e.g. poetry run pytest.

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")

European Stocks with Xetra/Euronext

from jyapystock import StockPriceProvider

# Using yfinance for a specific exchange
provider = StockPriceProvider(country="europe", exchange="xetr")
result = provider.get_live_price("SAP")
# Resolves to SAP.DE

provider = StockPriceProvider(country="europe", exchange="xpar")
result = provider.get_live_price("MC")
# Resolves to MC.PA

# No exchange given -- tries every suffix (.DE, .PA, .AS, .BR, .LS) until one resolves
provider = StockPriceProvider(country="europe")
result = provider.get_live_price("SAP")

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 & Europe)
  • 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 dependencies (see Installation for Development)

poetry install --extras dev

Run tests

poetry run python -m unittest discover tests

# Run provider-specific tests
PROVIDER=yfinance poetry run python -m unittest discover tests
PROVIDER=nse poetry run python -m unittest discover tests
PROVIDER=bse poetry run python -m unittest discover tests
PROVIDER=nasdaq poetry run python -m unittest discover tests
PROVIDER=alphavantage poetry run python -m unittest discover tests

License

MIT

Metadata

Release files for jyapystock 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jyapystock 0.5.0
File Size Uploaded
jyapystock-0.5.0.tar.gz 17.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jyapystock 0.5.0
File Interpreter ABI Platform
jyapystock-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.5 kB

Release files / jyapystock-0.5.0.tar.gz

Download URL jyapystock-0.5.0.tar.gz
Size 17.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f4029fd862bdcebb97d86a9b074b61b76afb8daf74700f8d46572d397250661d
BLAKE2b-256 checksum
How to use checksums
9ab1218b41355eeb11fea9020fb69011e1088addd7cd4bb9bbe3de7f63a57509
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.5.0-py3-none-any.whl

Download URL jyapystock-0.5.0-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b149dec20fff8e292cc4edb30d9d869695bbfd5ab468694d335f6165d9a3d9da
BLAKE2b-256 checksum
How to use checksums
b1629c4e0a66b6e139cb697de3df07cc0f4193330c8f433214ebe0f1eea8e00e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Release history Release notifications | RSS feed

0.5.1

2 release files

This release

0.5.0 This release

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page