Skip to main content

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 = 2015
end_year = 2020
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/

You can override base URLs by modifying the constants in metadata_utils.py (if implemented).

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_bls_api-0.1.1.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_bls_api-0.1.1-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file py_bls_api-0.1.1.tar.gz.

File metadata

  • Download URL: py_bls_api-0.1.1.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for py_bls_api-0.1.1.tar.gz
Algorithm Hash digest
SHA256 623e44df5c14d836b69454d19994adb78eab56b189280675fcd75b33e8ed617a
MD5 7147dee5a0ae1eb0971b97e4df476d0b
BLAKE2b-256 447514f42b1f5dd3b7b70a1bd6d78f889d9c60fd06bf72a3e549f361bdfbab3a

See more details on using hashes here.

File details

Details for the file py_bls_api-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: py_bls_api-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for py_bls_api-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3aee7ac97afa7067e16330c6df2c9c807c39fd906734646898584d0b8fc6131d
MD5 def0f095d6e44e11da47cd433f71f272
BLAKE2b-256 bb0472c76b46daa4a9b046d9e62f50f0366078fa05e40e7b970e2eeef8fab4a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page