Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pyhoo

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pyhoo

Yet another unofficial Yahoo Finance API, but with concurrent requests

  • 0.1.3
  • PyPI
  • Socket score

Maintainers
1

Pyhoo

Code style: black Checked with mypy Build Status codecov

Yet another unofficial Yahoo Finance API library but with concurrent requests.

Index

  1. Installation
  2. Usage
  3. Troubleshooting
  4. Contributing

Installation

Pyhoo requires Python >= 3.8

pip install pyhoo

Usage

Pyhoo is simple:

import pyhoo

tickers = ['FB', 'AAPL', 'AMZN', 'GOOGL']
start = '2020-02-01'
end = '2020-11-02'

stock_prices = pyhoo.get('chart', tickers, start=start, end=end, granularity="1d")
financial_reports = pyhoo.get('fundamentals', tickers, start=start, end=end)
options = pyhoo.get('options', tickers, strikeMax=400.0)

The result of pyhoo.get is a formatted pandas.DataFrame (here for stock prices):

timestamphighlowvolumeopencloseadjclosecurrencysymbolexchangeNameinstrumentTyperegularMarketPrice...
01580481000208.69201.0631359900208.43201.91201.91USDFBNMSEQUITY286.95...
11580740200205.14202.515510500203.44204.19204.19USDFBNMSEQUITY286.95...
21580826600210.6205.219628900206.62209.83209.83USDFBNMSEQUITY286.95...
31580913000212.73208.7112538200212.51210.11210.11USDFBNMSEQUITY286.95...
41580999400211.19209.3410567500210.47210.85210.85USDFBNMSEQUITY286.95...
5.......................................

Pyhoo is fast, it uses concurrency to fire multiple requests at the same time. You can request all the tickers of the S&P500 in one shot.

Pyhoo is still in development, feel free to add more endpoints thanks to the Config object !

Currently, it supports three endpoints:

  1. chart, for OHLC data, basically stock prices
  2. fundamentals, for financial data about the firm, see the list of available reports
  3. options, for detailed information on each call and put at each strike on specific tickers

Troubleshooting

If running from a Jupyter Notebook, you may encounter the following error:

RuntimeError: asyncio.run() cannot be called from a running event loop

This is because Jupyter Notebooks are running themselves in an event loop, and it is a known issue with asyncio.run.

There is a workaround, a bit hacky but gets the job done, using nest_asyncio.

pip install nest_asyncio

Then in the Notebook, before calling pyhoo.get:

import nest_asyncio
nest_asyncio.apply()

And you should be ok !

Contributing

Contributions are welcome !

Pyhoo uses poetry as package manager. You can find the installation instructions here.

It is recommended to install the virtual environment in the project folder if you use VSCode, to help the linter resolve imports:

poetry config virtualenvs.path --unset
poetry config virtualenvs.in-project true

Once Poetry is configured, you can install required dependencies with:

poetry install

The CI enforces strict typing, linting and coverage.

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc