In this short tutorial, you'll see how to download after-hours and pre-market stock prices using Python. Whether you're building algorithmic trading strategies, monitoring extended-hours volatility, or analyzing earnings announcements, accessing pre-market and post-market data is essential for comprehensive market analysis.

Extended trading hours (4:00 AM - 9:30 AM pre-market and 4:00 PM - 8:00 PM after-hours EST) often show significant price movements that regular market data misses.

1. Get After-Hours Data with yfinance (Simple Method)

The yfinance library provides the easiest way to download extended-hours price data by setting the prepost=True parameter in the download function.

import yfinance as yf
from datetime import date, timedelta

today = date.today()
week_ago = today - timedelta(days=7)

tesla = yf.download('TSLA', start=week_ago, end=today, interval='1m', prepost=True)

print(f"Total data points: {len(tesla)}")
print(f"\nLast 5 extended-hours prices:\n{tesla[['Close', 'Volume']].tail()}")
print(f"\nAfter-hours average volume: {tesla['Volume'].mean():.0f}")

Output Result:

Total data points: 3250

Last 5 extended-hours prices:
                     Close    Volume
Datetime                           
2026-02-13 19:56:00  245.32   12450
2026-02-13 19:57:00  245.28    8920
2026-02-13 19:58:00  245.35   11200
2026-02-13 19:59:00  245.40   15680
2026-02-13 20:00:00  245.38    9340

After-hours average volume: 8542

How it works: The prepost=True flag includes pre-market (4:00-9:30 AM) and after-hours (4:00-8:00 PM) trading data. The interval='1m' provides minute-by-minute granularity for detailed analysis of extended-hours price action.

2. Get Real-Time Pre-Market and After-Market Prices via API

For real-time extended-hours quotes, use the Yahoo Finance API directly with the requests library to get the latest pre-market or after-hours price.

import requests
from datetime import datetime

symbol = "NVDA"
url = f"https://query1.finance.yahoo.com/v8/finance/chart/{symbol}"

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'}
params = {"interval": "1m", "range": "1d", "prepost": "true"}

response = requests.get(url, params=params, headers=headers)
data = response.json()
result = data["chart"]["result"][0]

timestamps = result["timestamp"]
quotes = result["indicators"]["quote"][0]
last_price = quotes["close"][-1]
last_time = datetime.fromtimestamp(timestamps[-1])

print(f"Symbol: {symbol}")
print(f"Last extended-hours price: ${last_price:.2f}")
print(f"Timestamp: {last_time.strftime('%Y-%m-%d %H:%M:%S')}")
print(f"Market status: {'After-hours' if last_time.hour >= 16 else 'Pre-market'}")

Output Result:

Symbol: NVDA
Last extended-hours price: $738.45
Timestamp: 2026-02-13 19:59:00
Market status: After-hours

Real-world application: This method is perfect for live trading dashboards, price alerts, and automated trading bots that need real-time extended-hours quotes without delays.

Common Use Cases

Earnings Trading: Monitor after-hours price reactions to earnings announcements

Gap Analysis: Identify pre-market gaps for day trading strategies

News Trading: Track extended-hours volatility during breaking news

International Markets: Catch overnight price movements from Asian/European markets

Liquidity Analysis: Compare extended-hours volume to regular session

Errors

If you face the following message:

Status Code: 429
Error Message: Edge: Too Many Requests

check this article: How to Fix Yahoo Finance API 429 Too Many Requests Error

If you face warning or incosistent price results from yahoo finance check:

YF.download() has changed argument auto_adjust default to True

then you can use this article to understand the changes:

Understanding yfinance auto_adjust=True: What Changed and How to Fix It