Access millions of economic time series with just pip install datasetiq
pip install datasetiqRequires Python 3.9+. Automatically installs pandas and requests.
import datasetiq as iq
# Set your API key (one-time setup)
iq.set_api_key("your_api_key_here")
# Get data as pandas DataFrame
df = iq.get("FRED/CPIAUCSL")
# Display first few rows
print(df.head())
# Basic analysis
latest = df.iloc[-1]
print(f"Latest CPI: {latest['value']} on {latest['date']}")
# Calculate year-over-year inflation
df['yoy_inflation'] = df['value'].pct_change(12) * 100
print(df.tail())β Free Tier Includes:
iq.get()Fetch time series data as a pandas DataFrame.
| Parameter | Type | Description |
|---|---|---|
series_id | str | Series ID (e.g., "FRED/CPIAUCSL", "WB/USA/GDP") |
start | str (optional) | Start date (YYYY-MM-DD) - Requires API key |
end | str (optional) | End date (YYYY-MM-DD) - Requires API key |
Basic usage:
import datasetiq as iq
# Get all available data
df = iq.get("FRED/CPIAUCSL")
print(df.shape) # (100, 2) in anonymous mode, full history with API keyDate range filtering (requires API key):
# Get data for specific date range
df = iq.get("FRED/CPIAUCSL", start="2020-01-01", end="2023-12-31")
print(df.shape) # (~48, 2) - monthly data for 4 yearsRecent data only:
# Get data from 2020 onwards
df = iq.get("FRED/CPIAUCSL", start="2020-01-01")
print(df.tail())iq.set_api_key()Set your DataSetIQ API key for authenticated requests.
import datasetiq as iq
# Set API key (one-time per session)
iq.set_api_key("dsiq_1234567890abcdef")
# Or use environment variable
import os
iq.set_api_key(os.getenv("DATASETIQ_API_KEY"))iq.search()Search for datasets using natural language. Requires API key.
Basic search:
import datasetiq as iq
iq.set_api_key("your_api_key")
# Search for datasets
results = iq.search("inflation united states")
# Results is a pandas DataFrame
print(results[['title', 'provider', 'series_id']].head())
# Get the top result
best_match = results.iloc[0]
df = iq.get(best_match['series_id'])Search with filters:
# Search with provider filter
results = iq.search("gdp growth", provider="FRED", limit=10)
# Search by frequency
results = iq.search("unemployment rate", frequency="monthly")iq.get_metadata()Get detailed metadata about a time series.
import datasetiq as iq
# Get metadata (works in anonymous mode too)
metadata = iq.get_metadata("FRED/CPIAUCSL")
print(f"Title: {metadata['title']}")
print(f"Description: {metadata['description']}")
print(f"Frequency: {metadata['frequency']}")
print(f"Units: {metadata['units']}")
print(f"Last Updated: {metadata['lastUpdated']}")
print(f"Source: {metadata['source']}")import datasetiq as iq
import matplotlib.pyplot as plt
iq.set_api_key("your_api_key")
# Get CPI data
cpi = iq.get("FRED/CPIAUCSL", start="2000-01-01")
# Calculate year-over-year inflation
cpi['yoy_inflation'] = cpi['value'].pct_change(12) * 100
# Plot
plt.figure(figsize=(12, 6))
plt.plot(cpi['date'], cpi['yoy_inflation'])
plt.title('US Inflation Rate (Year-over-Year)')
plt.xlabel('Date')
plt.ylabel('Inflation (%)')
plt.grid(True, alpha=0.3)
plt.show()
# Recent inflation
recent = cpi.tail()
print(recent[['date', 'yoy_inflation']])import datasetiq as iq
import pandas as pd
iq.set_api_key("your_api_key")
# Get multiple related series
unemployment = iq.get("FRED/UNRATE", start="2010-01-01")
inflation = iq.get("FRED/CPIAUCSL", start="2010-01-01")
# Merge on date
merged = pd.merge(
unemployment.rename(columns={'value': 'unemployment'}),
inflation.rename(columns={'value': 'cpi'}),
on='date'
)
# Calculate inflation rate
merged['inflation'] = merged['cpi'].pct_change(12) * 100
# Correlation analysis
corr = merged[['unemployment', 'inflation']].corr()
print("Correlation between unemployment and inflation:")
print(corr)import datasetiq as iq
iq.set_api_key("your_api_key")
# Get data
df = iq.get("FRED/CPIAUCSL", start="2020-01-01")
# Export to CSV
df.to_csv("cpi_data.csv", index=False)
print(f"Exported {len(df)} observations to cpi_data.csv")
# Or Excel
df.to_excel("cpi_data.xlsx", index=False, sheet_name="CPI")import datasetiq as iq
import pandas as pd
iq.set_api_key("your_api_key")
# Search for GDP indicators
results = iq.search("gdp growth quarterly", limit=5)
# Fetch all series and combine
all_data = {}
for _, row in results.iterrows():
series_id = row['series_id']
title = row['title']
try:
df = iq.get(series_id, start="2020-01-01")
all_data[title] = df.set_index('date')['value']
except Exception as e:
print(f"Failed to fetch {series_id}: {e}")
# Combine into one DataFrame
combined = pd.DataFrame(all_data)
print(combined.head())
combined.to_csv("gdp_indicators.csv")import datasetiq as iq
iq.set_api_key("your_api_key")
try:
df = iq.get("FRED/INVALID_SERIES")
except iq.SeriesNotFoundError as e:
print(f"Series not found: {e}")
except iq.RateLimitError as e:
print(f"Rate limit exceeded: {e}")
print("Try upgrading your plan or wait a moment")
except iq.AuthenticationError as e:
print(f"Invalid API key: {e}")
except Exception as e:
print(f"Unexpected error: {e}")SeriesNotFoundError: Series ID doesn't existRateLimitError: Exceeded requests per minute (5 anonymous, 25 free, 100+ paid)AuthenticationError: Invalid or missing API key$0/mo
$29/mo
$99$49/mo
$399$199/mo
Anonymous mode (no API key): 5 req/min, latest 100 observations only
All paid plans include 14-day free trial β’ Cancel anytime