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"

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")  # survives API outages

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.
  • 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.1

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.1
File Size Uploaded
econchile-0.1.1.tar.gz 39.9 kB Details

Built distribution (wheel)

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

Total release size: 64.6 kB

Release files / econchile-0.1.1.tar.gz

Download URL econchile-0.1.1.tar.gz
Size 39.9 kB
Tags Source
SHA-256 checksum
How to use checksums
c0e60f9aab2a985b84e2b13e50930273ca2f433d90adb4e6caeb1d8f7ef85294
BLAKE2b-256 checksum
How to use checksums
c7c9bdab90aa63fcd3e9fd247e86b440c56bd228182ab1f5826cec073a573f02
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 7, 2026.

Transparency log

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

Download URL econchile-0.1.1-py3-none-any.whl
Size 24.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b00ae15a436dc7446702c4a18267fd70fc94b7b80042a25e2343d4c3eb754d6
BLAKE2b-256 checksum
How to use checksums
6c9ecdf2f522f20d74d4bb06cbd889217f3a562481c38420b12cac3871b117ef
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 7, 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

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.1 This release

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