Skip to main content

yahoo-finance-async

A simple Python async API wrapper for the deprecated (but currently still working) Yahoo Finance API.

Although the Yahoo Finance API has officially been closed down, it does still work and it provides a free access to a vast number of stocks.

Warning - The Yahoo Finance API could be removed or shut down at any point. You use this package at your own risk.

Why async?

There are many Yahoo Finance API libraries available on PyPi which use synchronous functions. There do not seem to be async functions available yet (as far as I could find). I needed an async version for a simple project to collect candle data (OHLC) for various stocks.

Endpoints available

Note that currently this API wrapper does not cover all the Yahoo Finance endpoints. In fact currently it only covers:

  • Collecting the OHLC (candlestick) data for stocks on Yahoo Finance

Getting started

Install from PyPi using

pip install yahoo-finance-async

Note that you import it into your module with underscores import yahoo_finance_async

This library has a simple class called OHLC which has a simple class method (actually an async coroutine) called fetch() which will fetch and parse the candle (OHLC) data.

You need to await the response of this coroutine.

For example to fetch this historical data for the stock AAPL:

    import asyncio

    from yahoo_finance_async import OHLC

    async def main():
        
        result = await OHLC.fetch(symbol='AAPL')
        # Do something with the result

    asyncio.run(main())

The returned result is a dictionary with two parts:

  1. candles - these are list of candle dictionary objects. For example:
    # result['candles'] gives ...

    [
        {
            "datetime": datetime.datetime(2020, 4, 1, 0, 0),
            "open": 235.3,
            "high": 245.667,
            "low": 213.33,
            "close": 233.5,
            "volume": 23
        },
        { ... },
        { ... }
    ]
  1. meta - this is the information about the symbol and timing that is returned by the Yahoo API which can be used for error checking. For example confirming you got the right symbol and time intervals

Additional parameters

Additional parameters can be passed to the OHLC.fetch() class method

    from yahoo_finance_async import OHLC, Interval, History

    # Fetch weekly candles for the last year
    await OHLC('AAPL', interval=Interval.WEEK, history=History.YEAR)

    # Fetch hourly candles for the last five days
    await OHLC('AAPL', interval=Interval.HOUR, history=History.FIVE_DAYS)

The Interval and History objects are Enums which show which time periods are available on the API.

Example notebook

To see a live example you can look at the attached notebook

Rate limits

Be careful and kind to the Yahoo Finance API and don't hit it too hard.

Contributing

Currently this API is focused just on the OHLC candle data. If you wish to contribute and extend the functionality please do. Comments, suggestions and pull requests are welcome.

Developers should clone the GitHub repo, and then install the development dependencies in the requirement-dev.txt file. Run all tests with pytest.

If you do contribute please also keep tests and documentation up to date. Thanks.

Release Notes

  • 0.1.2 - Fix to stop processing when None values are received from the API when parsing candles
  • 0.1.3 - Revised fix to the None values from API when parsing. Now the API will drop candles that cannot be parsed but will raise a Python warning message when this happens.

Metadata

Release files for yahoo_finance_async 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yahoo_finance_async 0.1.4
File Size Uploaded
yahoo_finance_async-0.1.4.tar.gz 10.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yahoo_finance_async 0.1.4
File Interpreter ABI Platform
yahoo_finance_async-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 16.7 kB

Release files / yahoo_finance_async-0.1.4.tar.gz

Download URL yahoo_finance_async-0.1.4.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
25147a042cc47847399f17162e22223c075040b64ec4c8d83190c8154475a7f8
BLAKE2b-256 checksum
How to use checksums
99d6e988af9151ec613f0cf884cba219119f6be3df103407101e2b23f57b08b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release files / yahoo_finance_async-0.1.4-py3-none-any.whl

Download URL yahoo_finance_async-0.1.4-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
944cf015d885b08d65531f2248f79341f9a446eafc7090aadc7151c2b03db3da
BLAKE2b-256 checksum
How to use checksums
0aec372f973873e77b2f87c90df03bad9149882e386257bc35ad88fb9edf1d35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.32.3

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page