I am looking to retrieve historical data like P/E ratio, earnings, book value etc as well as stock price. I'd like to go through a whole bunch of stocks programmatically or to possibly select historical stocks based on valuation rules.
I found a few python packages to download historical stock prices from Yahoo like yahoo-finance and also this guide to downloading historical prices with the browser. But I could not find anything to download historical valuation data.
I am aware of Survivorship Bias problem with the stocks that affects these free services but I can't afford a paid one right now.