BEA API Python package
raw JSON → 0.2.0 verified Sat May 09 auth: no python
A Python wrapper for the U.S. Bureau of Economic Analysis (BEA) API. Version 0.2.0 provides programmatic access to BEA data such as GDP and regional statistics. Released periodically; currently in early active development.
pip install beaapi Common errors
error TypeError: BEAAPI() takes no arguments ↓
cause Instantiating BEAAPI without arguments when the constructor expects an API key.
fix
Use BEAAPI(api_key) with your API key.
error AttributeError: module 'beaapi' has no attribute 'get_data' ↓
cause Calling get_data directly on the module instead of on an instance.
fix
Create an instance first: api = BEAAPI(key); api.get_data(params).
Warnings
breaking The API key must be provided as a parameter to the BEAAPI constructor; there is no environment variable autoloading. ↓
fix Always pass the API key explicitly: BEAAPI(api_key) or set an environment variable and load it manually.
gotcha The get_data method expects a flat dictionary of params, not nested. Common mistake: including parameters inside an extra dict. ↓
fix Pass params as a single dictionary with keys like 'UserID', 'Method', etc.
deprecated The older pattern BEAAPI().get_data() without explicit API key is deprecated in favor of passing key to constructor. ↓
fix Switch to BEAAPI(api_key).get_data(params).
Imports
- BEAAPI
from beaapi import BEAAPI
Quickstart
from beaapi import BEAAPI
import os
api_key = os.environ.get('BEA_API_KEY', '')
if not api_key:
raise ValueError("Set BEA_API_KEY environment variable")
bea = BEAAPI(api_key)
params = {
'UserID': api_key,
'Method': 'GetDataSetList',
'ResultFormat': 'JSON'
}
response = bea.get_data(params)
print(response)