""" Basic example — fetch a few series and print the latest values. Run from the bls/ directory: python3 examples/basic_pull.py """ import sys, os sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) from config import BLS_API_KEY from bls_client import BLSClient from bls_client.queries import employment, prices, wages client = BLSClient(BLS_API_KEY) # ── Single series ──────────────────────────────────────────────────────────── print("=== National Nonfarm Payrolls ===") result = client.fetch_latest(employment.nonfarm_payrolls(), years=1) for sid, s in result.items(): obs = client.latest_obs(s) print(f" {obs['periodName']} {obs['year']}: {float(obs['value']):,.0f} thousand jobs") # ── Named dict pull ────────────────────────────────────────────────────────── print("\n=== CPI Dashboard (latest month) ===") results = client.fetch_named(prices.cpi_dashboard(), 2025, 2026) for label, s in results.items(): obs = client.latest_obs(s) if obs: print(f" {label:<30} {obs['value']:>8} ({obs['periodName']} {obs['year']})") # ── DC region unemployment ─────────────────────────────────────────────────── print("\n=== DC Region Unemployment Rates ===") results = client.fetch_named(employment.dc_region_unemployment(), 2025, 2026) for label, s in results.items(): obs = client.latest_obs(s) if obs: print(f" {label:<20} {obs['value']}% ({obs['periodName']} {obs['year']})") # ── Flatten to rows ────────────────────────────────────────────────────────── print("\n=== Raw rows (first 3) ===") result = client.fetch_latest(employment.nonfarm_payrolls(), years=1, catalog=True) rows = client.to_rows(result) for row in rows[:3]: print(f" {row}")