> ## Documentation Index
> Fetch the complete documentation index at: https://langchain.idochub.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Google Finance

This notebook goes over how to use the Google Finance Tool to get information from the Google Finance page.

To get an SerpApi key key, sign up at: [serpapi.com/users/sign\_up](https://serpapi.com/users/sign_up).

To use the tool with LangChain install following packages

```python theme={null}
%pip install -qU google-search-results langchain-community
```

```output theme={null}
Note: you may need to restart the kernel to use updated packages.
```

Then set the environment variable SERPAPI\_API\_KEY to your SerpApi key or pass the key in as a argument to the wrapper serp\_api\_key="your secret key".

```python theme={null}
import os

os.environ["SERPAPI_API_KEY"] = ""
```

```python theme={null}
from langchain_community.tools.google_finance import GoogleFinanceQueryRun
from langchain_community.utilities.google_finance import GoogleFinanceAPIWrapper

tool = GoogleFinanceQueryRun(api_wrapper=GoogleFinanceAPIWrapper())
```

```python theme={null}
tool.run("Google")
```

```output theme={null}
'\nQuery: Google\nstock: GOOGL:NASDAQ\nprice: $159.96\npercentage: 0.94\nmovement: Up\nus: price = 42210.57, movement = Down\neurope: price = 23638.56, movement = Up\nasia: price = 38183.26, movement = Up\n'
```

In order to create an agent that uses the Google Finance tool install LangGraph

```python theme={null}
%pip install -qU langgraph langchain-openai
```

```output theme={null}
Note: you may need to restart the kernel to use updated packages.
```

and use the `create_agent` functionality to initialize a ReAct agent. You will also need to set up your OPEN\_API\_KEY (visit [platform.openai.com](https://platform.openai.com)) in order to access OpenAI's chat models.

```python theme={null}
import os

os.environ["OPENAI_API_KEY"] = ""
os.environ["SERP_API_KEY"] = ""
```

```python theme={null}
from langchain.chat_models import init_chat_model

llm = init_chat_model("gpt-4o-mini", model_provider="openai")
```

```python theme={null}
from langchain_community.agent_toolkits.load_tools import load_tools

tools = load_tools(["google-scholar", "google-finance"], llm=llm)
```

```python theme={null}
from langchain.agents import create_agent

agent = create_agent(llm, tools)

events = agent.stream(
    {"messages": [("user", "What is Google's stock?")]},
    stream_mode="values",
)
for event in events:
    event["messages"][-1].pretty_print()
```

```output theme={null}
================================ Human Message =================================

What is Google's stock?
================================== Ai Message ==================================
Tool Calls:
  google_finance (call_8m0txCtxNuQaAv9UlomPhSA1)
 Call ID: call_8m0txCtxNuQaAv9UlomPhSA1
  Args:
    query: Google
================================= Tool Message =================================
Name: google_finance


Query: Google
stock: GOOGL:NASDAQ
price: $159.96
percentage: 0.94
movement: Up
us: price = 42210.57, movement = Down
europe: price = 23638.56, movement = Up
asia: price = 38183.26, movement = Up

================================== Ai Message ==================================

Google's stock, listed as GOOGL on NASDAQ, is currently priced at $159.96, with a movement up by 0.94%.
```

```python theme={null}
```
