Lately, I've been using Breadth.app's excellent SPX breadth indicator to get a feel for where we are in the market's breadth cycle (thanks to San's prior recommendation).
Unfortunately, seeing as how the site loads in Chinese and has a link to an English version that only appears sporadically, it wasn't immediately clear to me exactly how their market breadth score was calculated. Thankfully, it turns out that calculating market breadth is really easy, and after a bit of trial and error I was able to replicate Breadth.app's numbers on my own and from scratch in Python.
The notebook in this repo demonstrates how write some Python functions that'll generate the same market breadth graph that you'll find on the breadth.app website. This might be useful if (a) you'd like to learn how to do this from scratch, and or (b) you're interested in experimenting with using a different baseline like the 50 day EMA (Breadth.app uses the 20 day SMA).
Breadth.app was originally created by @lonecapital and as best as I can tell, uses a codebase written by hk-lei and kentio. The site also incorporates design work done by jchang274 and tianyuan09. With the exception of the Wikipedia scraping function, which I borrow directly from hk-lei, all of the code that follows below is my own creation.
Nonetheless, the authors' repo was a crucial reference that helped me confirm, generally-speaking, what steps are necesssary to generate SPX market breadth data from scratch. Their work clued me in to the fact that the TA-Lib library makes it easy to calculate SMAs, EMAs, etc., and that yfinance makes for a user-friendly and free way to download the market data for all SPX stocks.