Skip to the content.

Build a dividend stock screener in Python

In this tutorial you will build a dividend screener. It reads 20 stocks in one request and keeps those with a dividend yield of at least 2.5% and a payout ratio of at most 80%. For each one it prints yield, payout ratio, P/E, price and the ex-dividend date. It uses Yahoo Finance Turbo and about 50 lines of Python. Not investment advice.

What you need: Python 3.8+, pip install requests, and a free RapidAPI key.

1. Subscribe to the free plan

  1. Open the Yahoo Finance Turbo on RapidAPI and subscribe to the free Basic plan (20 requests a month).
  2. Copy your X-RapidAPI-Key and export it:
export RAPIDAPI_KEY=your_key

2. A small helper to call the API

The helper sends your key, retries rate limits (HTTP 429) and server errors (5xx) with a growing wait, and stops with the API’s error message on anything else.

"""Screen a watchlist for dividend stocks by yield, payout ratio and valuation.

Uses Yahoo Finance Turbo on RapidAPI:
https://rapidapi.com/apiwren-apiwren-default/api/yahoo-finance-turbo
"""
import os, sys, time
from datetime import datetime, timezone
import requests

HOST = "yahoo-finance-turbo.p.rapidapi.com"
HEADERS = {"X-RapidAPI-Key": os.environ["RAPIDAPI_KEY"], "X-RapidAPI-Host": HOST}


def get(path, **params):
    """GET one endpoint. Retries rate limits (429) and server errors (5xx)."""
    for attempt in range(4):
        r = requests.get(f"https://{HOST}{path}", headers=HEADERS, params=params, timeout=90)
        retry = r.status_code == 429 or r.status_code in range(500, 600)
        if retry and attempt != 3:
            time.sleep(float(r.headers.get("Retry-After") or 2 ** (attempt + 1)))
            continue
        if not r.ok:
            sys.exit(f"HTTP {r.status_code}: {r.text[:300]}")
        body = r.json()
        if isinstance(body, dict) and body.get("success") is False:
            sys.exit(f"API error: {body.get('error')}")
        return body

3. Set the watchlist and rules

Up to 20 symbols per request, and two rules you can change.

WATCHLIST = ["KO", "PEP", "JNJ", "PG", "XOM", "CVX", "VZ", "T", "MO", "PFE",
             "IBM", "MMM", "O", "ABBV", "HD", "MCD", "KMB", "CSCO", "TXN", "WMT"]
MIN_YIELD, MAX_PAYOUT = 0.025, 0.80

4. Screen

/market/v2/get-quotes returns each quote with a quoteSummary.summaryDetail block that holds dividendYield, payoutRatio, trailingPE and exDividendDate.

def quotes(symbols):
    body = get("/market/v2/get-quotes", symbols=",".join(symbols), region="US")
    return body["quoteResponse"]["result"]


def row(q):
    d = q["quoteSummary"]["summaryDetail"]
    raw = lambda k: (d.get(k) or {}).get("raw") if isinstance(d.get(k), dict) else d.get(k)
    ex = raw("exDividendDate")
    return {"symbol": q["symbol"], "name": q.get("shortName", ""), "price": q["regularMarketPrice"],
            "yield": raw("dividendYield") or 0, "payout": raw("payoutRatio") or 0, "pe": raw("trailingPE"),
            "ex_date": datetime.fromtimestamp(ex, timezone.utc).date() if ex else None}


def main():
    rows = [row(q) for q in quotes(WATCHLIST)]
    keep = [r for r in rows if r["yield"] == max(r["yield"], MIN_YIELD) and r["payout"] == min(r["payout"], MAX_PAYOUT)]
    keep.sort(key=lambda r: r["yield"], reverse=True)
    print(f"{len(keep)} of {len(rows)} pass: yield at least {MIN_YIELD:.1%}, payout at most {MAX_PAYOUT:.0%}")
    print("symbol   yield  payout     P/E    price  ex-dividend  name")
    for r in keep:
        pe = f"{r['pe']:7.1f}" if r["pe"] else "      -"
        print(f"{r['symbol'].ljust(7)}{r['yield']:6.2%}{r['payout']:8.0%} {pe}{r['price']:9.2f}  "
              f"{str(r['ex_date']).ljust(11)}  {r['name'][:28]}")


if __name__ == "__main__":
    main()

5. Run it

python yahoo_dividend_screener.py

Real output from a run on 2026-11-28:

9 of 20 pass: yield at least 2.5%, payout at most 80%
symbol   yield  payout     P/E    price  ex-dividend  name
VZ      5.95%     72%    12.1    47.54  2026-10-09   Verizon Communications Inc.
T       4.78%     59%    12.4    23.21  2026-10-09   AT&T Inc.
PEP     4.09%     73%    18.2   144.60  2026-12-04   Pepsico, Inc.
CVX     3.35%     52%    15.6   212.45  2026-11-18   Chevron Corporation
MCD     2.73%     59%    22.4   282.62  2026-12-01   McDonald's Corporation
IBM     2.72%     58%    21.2   248.08  2026-11-10   International Business Machi
XOM     2.67%     42%    16.5   160.18  2026-11-16   ExxonMobil Holdings Corporat
HD      2.57%     65%    25.1   362.15  2026-12-03   Home Depot, Inc. (The)
PG      2.52%     65%    26.0   172.86  2026-10-23   Procter & Gamble Company (Th

The complete script is in examples/yahoo_dividend_screener.py.

Tips

Next steps