Skip to content

andrewrgarcia/bcrpy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

120 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

BCRP Logo

bcrpy

Python client for accessing and analyzing macroeconomic data from the Banco Central de Reserva del PerΓΊ (BCRP).


πŸ“Š What is BCRP Data?

The BCRP provides a public API with hundreds of economic time series, including:

  • Inflation (IPC)
  • GDP and economic activity
  • Interest rates
  • Monetary aggregates
  • External sector indicators

Official API: πŸ‘‰ https://estadisticas.bcrp.gob.pe/estadisticas/series/ayuda/api

Explore data: πŸ‘‰ https://estadisticas.bcrp.gob.pe/estadisticas/series/


⚑ Overview

bcrpy is a lightweight data access layer for BCRP macroeconomic data.

It provides:

  • Simple Python interface (get, large_get)
  • Parallel data fetching
  • Built-in caching (disk + SQLite)
  • Metadata exploration tools
  • Clean pandas output

πŸš€ Installation (UV recommended)

git clone https://github.com/andrewrgarcia/bcrpy
cd bcrpy
uv sync

⚑ Quick Start

from bcrpy import get

df = get(
    codes=["PN01288PM"],  # inflation
    start="2020-01",
    end="2023-01"
)

print(df.head())

πŸ”₯ Large Requests (Parallel)

from bcrpy import large_get

df = large_get(
    codes=["PN01288PM", "PN01289PM", "PN00015MM"],
    start="2010-01",
    end="2023-01",
    chunk_size=2,
    workers=4
)

🧠 Metadata Tools

from bcrpy import Marco

m = Marco()
m.get_metadata()

tools = m.tools()

tools.query("PN01288PM")
tools.wordsearch("inflacion")

πŸ“ Cache System

Data is cached automatically:

.bcrpy_cache/
β”œβ”€β”€ cache_<hash>.bcrfile
β”œβ”€β”€ cache_<hash>.meta
β”œβ”€β”€ large_cache_<hash>.bcrfile

Features:

  • Automatic reuse
  • Hash-based isolation (no collisions)
  • Optional SQLite backend

βš™οΈ Configuration

get(..., forget=True)     # ignore cache
large_get(..., workers=2) # control parallelism

πŸ§ͺ Testing

Run all tests:

uv run pytest -v

🧱 Architecture

bcrpy/
β”œβ”€β”€ _fetcher.py     # core data retrieval
β”œβ”€β”€ _http.py        # HTTP + retry logic
β”œβ”€β”€ _metadata.py    # metadata handling
β”œβ”€β”€ tools.py        # search / query tools
β”œβ”€β”€ utils.py        # IO + helpers

🎯 Design Principles

  • Minimal dependencies
  • Explicit behavior (no hidden magic)
  • Reproducibility via caching
  • Separation of concerns (data vs tools)

πŸ“Œ Notes

  • No API key required (public BCRP API)
  • Network-dependent (uses official endpoint)
  • Designed for research and modeling workflows

πŸ“„ License

MIT

About

Un cliente API para el Banco Central de Reserva del Peru (BCRP)

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages