This repository contains Python files that facilitate the extraction of data from the BLS (Bureau of Labor Statistics) and BEA (Bureau of Economic Analysis) databases using their respective APIs. The provided Python scripts allow you to establish a connection with the databases and retrieve the desired data for further analysis or processing.
Required Python libraries: 'requests', 'json', 'pandas'
The BLSdata file provides a Python function BLSData that connect to the BLS database using its API. It provides methods to authenticate, query data, and retrieve the results in a structured format.
To use the BLS API, follow these steps:
- Obtain your BLS API key from the BLS API Registration page. In the file, copy your API key to the variable bls_key as default.
- Go to BLS website to find the Series ID.
- Implement your desired data query by adding seriesID, startYr and endYr in the BLSdata function.
- Run the bls_api.py file to execute your query and retrieve the data from the BLS database.
The BEAdata file provides a Python function BEAData that enables connecting to the BEA database using its API. It offers methods to authenticate, query data, and obtain the results in a structured format.
To utilize the BEA API, follow these steps:
- Obtain your BEA API key from the BEA Data API page. In the file, copy your API key to the variable api_key as default.
- Go to BEA NIPA Tables to find the table name.
- Implement your desired data query by adding tablename, frequency and year in the BEAdata function.
- Execute your query and retrieve the data from the BEA database.
The repository includes example usages of both the BLS and BEA API connections in the example_usage.py file. You can refer to this file to understand how to retrieve data from the respective databases.