A Python wrapper for the U.S. Bureau of Labor Statistics (BLS) API
Project description
py-bls-api
A Python wrapper for the Bureau of Labor Statistics (BLS) API, providing easy access to select surveys, metadata, data previews, series metadata, popular series IDs, and time series data.
Features
- List available BLS surveys (
get_surveys) - Fetch survey metadata (
get_survey_metadata) - Preview data structure for a survey (
get_data_preview) - Retrieve series ID metadata as a DataFrame (
get_seriesid_metadata) - Get popular series IDs for a survey (
get_popular_seriesids) - Download time series data (
get_bls_data)
Installation
Install directly from PyPI:
pip install py-bls-api
Or install from GitHub (latest development version):
pip install git+https://github.com/coding-with-chris/py-bls-api.git
Quick Start
First, import the package:
from py_bls_api import (
get_surveys,
get_survey_metadata,
get_data_preview,
get_seriesid_metadata,
get_popular_seriesids,
get_bls_data
)
1. List all surveys
surveys = get_surveys()
print(surveys)
# e.g., {'IP': 'Industrial Production', 'CU': 'Consumer Price Index', ...}
2. Fetch survey metadata
meta = get_survey_metadata("CU")
print(meta.keys())
# e.g., ['survey_name', 'survey_abbreviation', 'series', 'data_preview']
3. Preview data for a survey
df_preview = get_data_preview("IP")
print(df_preview.head())
4. Retrieve series metadata
df_series_meta = get_seriesid_metadata("CU")
print(df_series_meta.head())
5. Get popular series IDs
# Requires a BLS API registration key
api_key = "YOUR_API_KEY_HERE"
popular_ids = get_popular_seriesids("CU", api_key)
print(popular_ids)
6. Download time series data
series_ids = ["CUUR0000SA0"] # e.g., CPI-All Urban Consumers
start_year = 2020
end_year = 2024
api_key = "YOUR_API_KEY_HERE"
# Returns a tuple: (data_df, log_df)
data_df, log_df = get_bls_data(series_ids, start_year, end_year, api_key)
print(data_df.head())
print(log_df)
Configuration
By default, metadata files are fetched from GitHub Pages:
https://coding-with-chris.github.io/py-bls-api/metadata/
Requirements
- Python 3.6+
- pandas >= 1.3.0
- requests >= 2.25.0
Contributing
Not looking for contributions at this time. However, feedback and suggestions are always welcome!
Please feel free to open an issue if you find bugs or have ideas for improvements.
License
This project is released under a Non-Commercial, No-Derivatives license. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_bls_api-0.1.2.tar.gz.
File metadata
- Download URL: py_bls_api-0.1.2.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8f6bb0ebd5e1bcef45d128ad07537aaab13c651a028aaec800dedab8187f869
|
|
| MD5 |
e30842f5701a93aacbe5c3fedda15776
|
|
| BLAKE2b-256 |
8477778ae135d2b3d6b24bb0079fccd663c29cb4b6f49a55d9d18dfcfae2f7c0
|
File details
Details for the file py_bls_api-0.1.2-py3-none-any.whl.
File metadata
- Download URL: py_bls_api-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48a76c8a5ab665b33980efdcb9caa54a3a64c27722598615ab852bcaf32b4aac
|
|
| MD5 |
524c6e7c3d0388c282e2871fcff99d2a
|
|
| BLAKE2b-256 |
1c699029f3e37391150ad85a20a0cef27b61fd453ee69b800efa758514acc6c8
|