{"id":7226,"library":"finnhub-python","title":"Finnhub Python API Client","description":"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.","status":"active","version":"2.4.27","language":"en","source_language":"en","source_url":"https://github.com/Finnhub-Stock-API/finnhub-python","tags":["financial data","stocks","forex","cryptocurrency","API client"],"install":[{"cmd":"pip install finnhub-python","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"The Client class is typically accessed directly as an attribute of the imported 'finnhub' module, not imported directly from the package.","wrong":"from finnhub import Client","symbol":"Client","correct":"import finnhub\nfinnhub_client = finnhub.Client(api_key=os.environ.get('FINNHUB_API_KEY', ''))"}],"quickstart":{"code":"import finnhub\nimport os\n\n# Get API key from environment variable for security\nfinnhub_api_key = os.environ.get('FINNHUB_API_KEY', 'YOUR_FREE_API_KEY_HERE')\n\n# Setup client\nfinnhub_client = finnhub.Client(api_key=finnhub_api_key)\n\n# Fetch real-time stock quote for Apple Inc.\nquote = finnhub_client.quote('AAPL')\nprint(\"AAPL Quote:\", quote)\n\n# Fetch company profile for Apple Inc.\ncompany_profile = finnhub_client.company_profile2(symbol='AAPL')\nprint(\"AAPL Company Profile:\", company_profile)","lang":"python","description":"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."},"warnings":[{"fix":"Refer to the CHANGELOG on GitHub and update your code to align with the new API patterns for `finnhub.Client` and data access methods. Many return values are now more directly consumable by pandas DataFrames.","message":"Version 2.0.0 introduced significant changes, simplifying library usage and making return data more compatible with data analysis libraries like pandas. Code written for version 1.x.x will likely break.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Rename your script file to anything other than `finnhub.py` (e.g., `my_finnhub_app.py`) to avoid conflicts with the installed library's module name.","message":"Naming your Python script 'finnhub.py' will lead to a circular import error: 'AttributeError: partially initialized module 'finnhub' has no attribute 'Client''.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement exponential backoff and retry logic for API calls to handle rate limits gracefully. For 'access denied' errors, check the Finnhub API documentation to confirm if the requested endpoint requires a premium subscription, or verify your API key and plan details.","message":"Free tier API keys often have strict rate limits (e.g., 60 calls/minute) and may not have access to all resources. Exceeding limits results in '429 Too Many Requests', and attempting to access premium data will return 'You don't have access to this resource.'.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that the Finnhub API domain (`api.finnhub.io`) is whitelisted on your hosting provider. Contact your hosting support if necessary to confirm and enable access.","message":"When deploying applications using `finnhub-python` on certain hosting platforms (e.g., PythonAnywhere), you might encounter '403 Forbidden' errors due to proxy restrictions.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Rename your Python script file to something unique, like `stock_data_fetcher.py`, to resolve the naming conflict.","cause":"The Python script attempting to import `finnhub` is itself named `finnhub.py`, causing Python to import the local file instead of the installed library.","error":"AttributeError: partially initialized module 'finnhub' has no attribute 'Client' (most likely due to a circular import)"},{"fix":"Verify your Finnhub API key and its associated subscription plan. Consult the Finnhub API documentation to confirm the required subscription tier for the specific endpoint you are trying to use.","cause":"Attempting to access a Finnhub API endpoint or data type that is not included in your current subscription plan (e.g., trying to fetch premium data with a free API key).","error":"{'error': \"You don't have access to this resource.\"}"},{"fix":"First, check your internet connection. If the issue persists, ensure your API key is valid and you're not exceeding rate limits. If running in a restricted environment, check firewall rules or ensure the `api.finnhub.io` domain is whitelisted.","cause":"This error typically indicates network issues, a very aggressive rate limit being hit repeatedly without backoff, or firewall/proxy blocking the outbound connection.","error":"HTTPSConnectionPool(host='api.finnhub.io', port=443): Max retries exceeded with url: /api/v1/..."},{"fix":"Double-check your Finnhub API key in your dashboard (`finnhub.io/dashboard`). Ensure there are no extra spaces or characters. If using environment variables, confirm it's loaded correctly.","cause":"The API key provided to the `finnhub.Client` is incorrect, expired, or has leading/trailing whitespace.","error":"{'error': 'The API key is invalid.'}"}]}