Skip to main content

Employ America tools for pulling and graphing U.S. macroeconomic data.

Project description

MacroTools

A Python package for pulling, caching, and graphing U.S. macroeconomic data. Built at Employ America.

MacroTools makes it easy to download flat files from the BLS, BEA, and regional Federal Reserve surveys, and to produce publication-ready time series charts with a consistent visual style.

Installation

pip install macrotools

For FRED/ALFRED support:

pip install macrotools[fred]

Quick start

import macrotools as mt
import matplotlib.pyplot as plt

# Pull household survey data (cached automatically for 7 days)
data = mt.pull_data('ln')

# Plot prime-age employment rate
fig = mt.tsgraph(
    data['LNS12300060'] / 100,
    format_info={
        'title': 'Prime-Age Employment Rate',
        'xlim': ('2019-01', '2025-06'),
        'ylim': (0.76, 0.82),
        'yticksize': 0.01,
        'ydecimals': 0,
        'ytickformat': 'pctg',
    }
)
plt.show()

Features

Data access

pull_data(source) downloads and caches full flat files. pull_bls_series() extracts individual series by code.

Supported sources:

Source Description
ln Household survey (CPS) labor force statistics
ce Establishment survey (CES) statistics
jt Job Openings and Labor Turnover Survey (JOLTS)
cu CPI — All Urban Consumers
pc PPI — Industry Data
wp PPI — Commodity Data
ei Import/Export Price Indices
cx Consumer Expenditures
tu Time Use Survey
nipa-pce NIPA Personal Consumption Expenditures
stclaims State-level unemployment claims
ny-mfg, ny-svc NY Fed Empire Manufacturing & Services
philly-mfg, philly-nonmfg Philadelphia Fed surveys
richmond-mfg, richmond-nonmfg Richmond Fed surveys
dallas-mfg, dallas-svc, dallas-retail Dallas Fed surveys
kc-mfg, kc-svc Kansas City Fed surveys

BLS sources require an email address. MacroTools will prompt you the first time and store it locally in ~/.macrodata_credentials/.

With the optional fredapi dependency, alfred_as_reported() pulls historical vintage data from ALFRED.

Graphing

tsgraph() wraps matplotlib with EA house styling (colors, fonts, layout). It supports:

  • Single and multi-series plots
  • Dual y-axes
  • Customizable axis limits, tick formatting, labels, and legends
  • Percentage and decimal tick formats
  • Subtitles, shading, and reference lines
  • Saving directly to PNG

Pass data as a Series, DataFrame, or dict of series. Formatting is controlled via the format_info dict — see help(mt.tsgraph) for the full list of options.

Time series utilities

  • cagr(data, lag, ma) — Compounded annual growth rates with optional moving-average smoothing.
  • rebase(data, baseperiod, basevalue) — Reindex series to a base period (single date or date range).

Credential setup

BLS email: Required for BLS data. Set once with mt.store_email('you@example.com') or pass email= to pull_data().

FRED API key: Required for alfred_as_reported(). Register at FRED, then mt.store_fred_api_key('your-key') or set the FRED_API_KEY environment variable.

Credentials are stored in ~/.macrodata_credentials/credentials.json. Cached data lives in ~/.macrodata_cache/ with a 7-day TTL.

Examples

See the example notebook for detailed usage with output.

License

MIT

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

macrotools-0.2.0.tar.gz (688.1 kB view details)

Uploaded Source

Built Distribution

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

macrotools-0.2.0-py3-none-any.whl (702.6 kB view details)

Uploaded Python 3

File details

Details for the file macrotools-0.2.0.tar.gz.

File metadata

  • Download URL: macrotools-0.2.0.tar.gz
  • Upload date:
  • Size: 688.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for macrotools-0.2.0.tar.gz
Algorithm Hash digest
SHA256 cf7b9ba3399fe32008ef23a45b1edef747e03e4290a746fb1746e0ca2d67b939
MD5 a375803a5e12bdbf7a846556d5d4386b
BLAKE2b-256 fa38e51d055e9d001962a2e05e8e6b153b0e1138b5e788ef847375b05d98a0b4

See more details on using hashes here.

File details

Details for the file macrotools-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: macrotools-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 702.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for macrotools-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4287e7e113de276611eda58591ef51e1a3082468934f4dbdc9cb20f32e3d2259
MD5 0edf77979dcec5247e81e09e0c43e49c
BLAKE2b-256 a1664ef1270662268533f1101cf311d5967ab1a4fc0de8593673110db63948fa

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