Quandl Python API Client

3.7.0 · active · verified Thu Apr 16

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import the `quandl` library, configure your API key (preferably via environment variable), and fetch a sample dataset. Data is returned as a Pandas DataFrame, making it easy to inspect and manipulate. An API key is essential for most practical uses beyond very limited anonymous calls.

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.")

view raw JSON →