yf.Ticker("MSFT").info doesn't provide information about "industry" and "sector", any idea of other commands to get this in python using yfinance API?

I used to use this to get info about a ticker:

tx = yf.Ticker("MSFT")  
indst=tx.info.get('industry')
sect=tx.info.get('sector')
st=tx.info.get('state')
            

However, none of these (‘industry’,‘sector’,‘state’) exist anymore in the tx.info object. Is there another way to get this info about a given ticker using yahoo finance API in python?

I’ve tried other commands as tx.fast_info and tx.get_history_metadata() and none include info related to ‘industry’,‘sector’.

It looks like the yfinance library has undergone some changes, and certain fields like industry, sector, and state may not be available directly in the tx.info dictionary anymore. However, you can still retrieve this information by accessing the relevant attributes in a different way.

Here are a few alternatives to get the industry, sector, and state information using the Yahoo Finance API in Python:

1. Using the info Attribute

Although the attributes may have changed, you can still check what data is available in the info dictionary. Here’s how to inspect it:

import yfinance as yf

tx = yf.Ticker("MSFT")
print(tx.info)  # This will display all available information

After running this, look through the output to see if industry, sector, or any similar fields have been renamed or are present under different keys.

2. Accessing Specific Attributes

If industry, sector, and state are missing, you can try accessing other related fields that might provide similar information. Here’s an example of how to do that:

import yfinance as yf

tx = yf.Ticker("MSFT")

# Check available fields
info = tx.info

# Attempt to retrieve sector and industry
sector = info.get('sector', 'N/A')
industry = info.get('industry', 'N/A')

print(f"Sector: {sector}")
print(f"Industry: {industry}")

3. Using yfinance’s get_data Method

You can also try using yfinance to retrieve historical data and metadata, although it may not include the sector or industry directly:

historical_data = tx.history(period="1d")
print(historical_data)

4. Fallback: Using Alternative Libraries or APIs

If you can’t find the required information using yfinance, consider using other financial data libraries or APIs. For example:

  • Alpha Vantage: Requires an API key but provides extensive financial data.
  • Finnhub: Another alternative with an API key requirement.

Summary

To retrieve the latest information about a ticker like Microsoft, inspect the output of tx.info to see the current available fields. If necessary, explore other financial data libraries that might provide the needed details.

Let me know if you need further assistance with any specific library or API!