Remove cached data, either all of it or only the part you specify.

The Finance Toolkit never clears the cache on its own. A cache can represent a large amount of downloaded data and a meaningful part of an API quota, so discarding it is always an explicit action. Even a change in the cache’s own internal structure only produces a warning pointing at this method rather than removing anything.

Because the cache is stored per source, per dataset and per entity, removal can be narrowed instead of wholesale. Clearing a single stale ticker, or everything retrieved from one provider, leaves the rest of the cache intact.

Clear Cache in Python

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call clear_cache as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(["AAPL", "MSFT"], api_key="FINANCIAL_MODELING_PREP_KEY")

# Remove only the price history of a single ticker
toolkit.clear_cache(source="YahooFinance", ticker="AAPL")

# Remove everything retrieved from the OECD
toolkit.clear_cache(source="OECD")

# Remove the entire cache
toolkit.clear_cache(confirm=True)

Parameters

clear_cache accepts the following parameters.

ParameterTypeDescriptionExample
sourcestr | NoneOnly remove data from this source, for example “FinancialModelingPrep”, “YahooFinance”, “OECD”, “FRED” or “GlobalMacroDatabase”. These match the names used by enforce_source. Defaults to None, which matches every source."YahooFinance"
datasetstr | NoneOnly remove this dataset within the source, for example “historical”, “intraday” or “statements”. Defaults to None, which matches every dataset."historical"
tickerstr | NoneOnly remove this entity, for example “AAPL” or a country code for macroeconomic data. Defaults to None, which matches every entity."AAPL"
confirmboolRequired to be True when no source, dataset or ticker is given, since that removes the entire cache. Defaults to False.True
Share