Usage Guide
We will walk through the basic usage of the LLM-ready API, including how to set up the API, make requests, and handle responses using the Python library, kFinance, which we built to streamline interaction with the LLM-ready API. You can always query the API directly or using your programming language of choice. In this guide, we’ll cover setup, basic usage, and integration with leading LLMs using code generation and function calling.
To get started with the LLM-ready API, we recommend using the example Playground Notebooks (opens in a new tab) to explore the API, Python library, and LLM integrations.
Setup
Before you begin, make sure you have access to the LLM-ready API, your refresh token or public/private key ready, and Python 3.10.0 or greater installed.
To install the Python library, use pip from your Terminal.
pip install https://kfinance.kensho.com/static/kensho_finance.tar.gz
To update the version:
pip install --force-reinstall https://kfinance.kensho.com/static/kensho_finance.tar.gz
For details on the library, see the Python Library page.
Basic Usage
The LLM-ready API organizes data around a Ticker object. The Ticker object represents the combination of the company, the security, and the specific instance of the security trading on an exchange. Below is a example of how to retrieve information using the Ticker object:
from kensho_finance.kfinance import Client
# Authenticate with one of the three methods below
client = Client()
client = Client(refresh_token="your_refresh_token_here")
client = Client(client_id="your_client_id_here", private_key="your_private_key_here")
# Instantiate a company's ticker object
microsoft = client.ticker("MSFT")
# Basic company information
microsoft.info
# Microsoft quarterly income statement
microsoft.income_statement(period_type="quarterly", start_year=2022, start_quarter=4, end_year=2024, end_quarter=1)
# Microsoft historical prices aggregated over a week
microsoft.history(start_date="2024-01-01", end_date="2024-07-01", periodicity="week")```
For complete list of functions, see the Python Library page.