Skip to main content

econchile

PyPI version Python versions CI

Chilean macroeconomic data (Banco Central de Chile) for Python.

econchile is a thin, practical client for the BCCh SIE REST web service. It downloads official series (UF, USD, TPM, IPC_VAR, IPC_INDEX, IMACEC, PIB), parses them into clean, typed data, and keeps a local SQLite cache so repeat queries are instant and your scripts survive API outages.

Install

pip install econchile

Requires Python 3.10+. To install from source instead:

git clone https://github.com/cristobal-almendra/econchile.git
cd econchile
pip install -e .

Authentication

Request a free API token from the BCCh statistics database (SIE), see the official API documentation.

export BCCH_TOKEN="your-token-here"

Windows PowerShell:

$env:BCCH_TOKEN="your-token-here"

The library reads BCCH_TOKEN from the environment — it does not load .env files itself. The token is required for v0.1.

Quickstart

from econchile import BcchClient, Series

client = BcchClient()

# Last 3 months of the UF (daily)
result = client.get(Series.UF, "2024-01-01", "2024-03-31")

for obs in result.observations:
    print(obs.date, obs.value)

Dates are always YYYY-MM-DD. Missing observations have value=None.

The two clients

Client Strategy Best for
BcchClient Cache-first — serves from the local cache when fresh, hits the API only on a miss Interactive use, repeated queries
OfflineClient API-first — always tries the API, falls back to the cache when it fails Cron jobs and scripts that must not crash
from econchile.offline import OfflineClient

client = OfflineClient()
result = client.get(Series.USD, "2024-01-01", "2024-03-31")  # falls back to previously cached results when the API is unavailable

Available series (v0.1)

Series BCCh code Frequency Meaning
Series.UF F073.UFF.PRE.Z.D daily Unidad de Fomento
Series.USD F073.TCO.PRE.Z.D daily Nominal exchange rate (CLP/USD)
Series.TPM F022.TPM.TIN.D001.NO.Z.D daily Monetary policy rate
Series.IPC_VAR F074.IPC.VAR.Z.Z.C.M monthly CPI, month-over-month change
Series.IPC_INDEX F074.IPC.IND.Z.2023.C.M monthly CPI general index (base 2023=100)
Series.IMACEC F032.IMC.IND.Z.Z.EP18.Z.Z.0.M monthly Economic activity index (base 2018=100)
Series.PIB F032.PIB.FLU.R.CLP.EP18.Z.Z.0.T quarterly GDP, chained volumes (base 2018)

More series are planned. Use client.list_series() for the full catalog and client.search("ipc") to find series by keyword:

hits = client.search("ipc")     # matches name, code, Spanish and English titles
for meta in hits:
    print(meta.series_id, meta.spanish_title)

Gotchas

  • Date format: pass YYYY-MM-DD to get(); the library converts the API's native DD-MM-YYYY for you.
  • Missing data: the BCCh API marks gaps as "ND". These become value=None, not zeros or exceptions, check for None before using a value.
  • Representations: IPC_VAR is a monthly % change, IPC_INDEX is a base-2023 index. Same variable, different meaning.
  • Cache freshness: cached results are reused for 24 hours by default; configure via ttl_seconds on BcchClient(...) or OfflineClient(...) (the cache lives at ~/.econchile/cache.db).
  • Errors: unknown series raise KeyError, malformed dates raise ValueError, API failures raise BcchApiError and BcchOfflineError when the offline fallback is also exhausted. No token? Both clients construct fine without one — the token is only needed when the API is actually called: BcchClient cache hits work, and OfflineClient serves cached data (a missing token is treated as an API failure, so the cache fallback applies).
  • Token with special characters: BCCh API tokens may contain / characters. The library URL-encodes them automatically via urllib.parse.urlencode (/%2F), so you can paste the token as-is. Only if you build request URLs by hand (e.g. curl) do you need to encode it yourself — urllib.parse.quote(token) — otherwise the BCCh API rejects the request.

API

  • BcchClient.get(series, desde, hasta, use_cache=True) — fetch a series over a date range; returns a SeriesResult.
  • OfflineClient.get(series, desde, hasta) — same, but API-first with cache fallback.
  • BcchClient.search(keyword) — case- and accent-insensitive catalog search → list[SeriesMeta].
  • BcchClient.list_series() — all series metadata → list[SeriesMeta].
  • BcchClient.clear_cache() — empty the local cache (returns the number of rows removed).

A SeriesResult has:

  • series — the Series member
  • observations — list of Observation(date: str, value: float | None)
  • fetched_at — timestamp (UTC)
  • source"api", "cache", or "partial"
  • metadata — series info (titles, frequency, representation)

Development

pip install -e . && pip install pytest
python -m pytest tests/

License

MIT

Release files for econchile 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for econchile 0.1.3
File Size Uploaded
econchile-0.1.3.tar.gz 42.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for econchile 0.1.3
File Interpreter ABI Platform
econchile-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 67.6 kB

Release files / econchile-0.1.3.tar.gz

Download URL econchile-0.1.3.tar.gz
Size 42.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bdd844a382f4a80c255b17df1ac97432710684a231a12879fd2a13c76d0ce931
BLAKE2b-256 checksum
How to use checksums
56f3d1e369612aa0d91339f0eb9cd2cbebf49353e84093db129c0bf2f332c79e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.

Transparency log

Release files / econchile-0.1.3-py3-none-any.whl

Download URL econchile-0.1.3-py3-none-any.whl
Size 25.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b76f3360102e3f0dc3a6e7fb361e66b0f77d0b7f96bdb9a965ae1ba486ce5c5f
BLAKE2b-256 checksum
How to use checksums
37c1edcf00d0feb651f20b7042a20d4d8e8e6ecff288a7e77a0bcc4c490da360
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page