Finnhub Python API Client

2.4.27 · active · verified Thu Apr 16

finnhub-python is the official Python client for the Finnhub API, providing institutional-grade financial data. This includes real-time stock prices, global fundamentals, global ETF holdings, and alternative data. The library is actively maintained, with regular updates and a current version of 2.4.27, offering a comprehensive interface for financial market data access.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Finnhub client using an API key from an environment variable and fetch basic stock data such as a real-time quote and company profile for Apple Inc. Make sure to replace 'YOUR_FREE_API_KEY_HERE' with a valid Finnhub API key or set the FINNHUB_API_KEY environment variable.

import finnhub
import os

# Get API key from environment variable for security
finnhub_api_key = os.environ.get('FINNHUB_API_KEY', 'YOUR_FREE_API_KEY_HERE')

# Setup client
finnhub_client = finnhub.Client(api_key=finnhub_api_key)

# Fetch real-time stock quote for Apple Inc.
quote = finnhub_client.quote('AAPL')
print("AAPL Quote:", quote)

# Fetch company profile for Apple Inc.
company_profile = finnhub_client.company_profile2(symbol='AAPL')
print("AAPL Company Profile:", company_profile)

view raw JSON →