Quandl Python API Client
The `quandl` Python library provides a convenient interface for accessing financial, economic, and alternative datasets from Nasdaq Data Link (formerly Quandl). It allows users to fetch data as Pandas DataFrames or NumPy arrays, facilitating data analysis and integration into quantitative workflows. The library is actively maintained, with the current version being 3.7.0, and new features and fixes are released regularly.
Common errors
-
ImportError: No module named Quandl
cause The Python package name for Quandl is all lowercase (`quandl`). Attempting to import it with a capitalized 'Q' will fail.fixChange the import statement to `import quandl` (all lowercase). -
ValueError: The Quandl API key must be provided.
cause You are attempting to access a dataset that requires authentication or have exceeded anonymous call limits without providing a valid API key.fixSet your API key using `quandl.ApiConfig.api_key = 'YOUR_API_KEY'` before making data requests. Ensure 'YOUR_API_KEY' is replaced with your actual key from Nasdaq Data Link. -
quandl.errors.quandl_error.QuandlError: (Status 403) Something went wrong. Please try again.
cause This error typically indicates that your API key is invalid, has expired, or you do not have sufficient permissions (e.g., subscription level) to access the requested dataset, or you have exceeded your rate limits.fixVerify your API key is correct and active. Check your Nasdaq Data Link account for subscription status and daily call limits. Some datasets require paid subscriptions. If the key is correct, try accessing a free dataset like `WIKI/GOOGL` to isolate the problem. -
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
cause This often occurs when the Quandl API returns an unexpected non-JSON response (e.g., an HTML error page or an empty response) instead of valid JSON data, usually due to an underlying API issue, rate limiting, or an invalid request.fixCheck the full error message for a `QuandlError` status code (e.g., 403, 500). Ensure your API key is valid, your request parameters are correct, and you are not exceeding rate limits. Temporarily enabling verbose logging might reveal the actual HTTP response body.
Warnings
- breaking Support for Python 3.3 was removed in `quandl` version 3.4.0. Users on Python 3.3 or older must upgrade their Python environment to at least 3.4 (though >=3.6 is now required by the latest package) to use `quandl` versions 3.4.0 and newer.
- gotcha An API key is critical for most practical uses of Quandl. Anonymous users are severely rate-limited (e.g., 50 calls per day). Without a valid API key configured, you will quickly hit limits or fail to access many datasets, receiving 403 Forbidden or similar errors.
- gotcha Quandl was acquired by Nasdaq and is now known as Nasdaq Data Link. While the `quandl` Python library still functions to access their data, new users should be aware of the rebranding and seek dataset codes on the Nasdaq Data Link website.
- gotcha SSL certificate verification was enabled by default in v3.4.8. If you are operating in an environment with custom SSL certificates or proxies, you might encounter SSL errors.
- gotcha The `authtoken.p` file, previously used to persist API keys locally, can be a security concern if not properly managed or if the working directory changes. The recommended modern approach is to set the API key programmatically or via environment variables.
Install
-
pip install quandl
Imports
- quandl
import Quandl
import quandl
- ApiConfig
import quandl quandl.ApiConfig.api_key = 'YOUR_API_KEY'
Quickstart
import quandl
import os
# Your Quandl API Key, stored as an environment variable for security
API_KEY = os.environ.get('QUANDL_API_KEY', 'YOUR_API_KEY_HERE')
if API_KEY == 'YOUR_API_KEY_HERE':
print("WARNING: Please set the QUANDL_API_KEY environment variable or replace 'YOUR_API_KEY_HERE' with your actual key.")
# For demonstration, proceed with limited anonymous access or raise an error
# raise ValueError("Quandl API Key not configured.")
quandl.ApiConfig.api_key = API_KEY
try:
# Fetching historical stock data for Apple from the WIKI database (now deprecated/archived, but good example)
# For current data, find up-to-date codes on Nasdaq Data Link website
data = quandl.get("WIKI/AAPL", start_date="2015-01-01", end_date="2015-12-31")
print(data.head())
except quandl.QuandlError as e:
print(f"Error fetching data: {e}")
print("Ensure your API key is correct and you have access to the requested dataset.")