okama-macro
Installation · Quick start · Available series · Data quality · Documentation · Contributing
Normalized CPI inflation and central-bank rate series for Python, built for the okama project and available as a standalone package.
okama-macro consolidates official macroeconomic data clients behind one
installable package, a shared HTTP/DataFrame layer, and a consistent public API.
Highlights
- One API — discover series with
list_series()and fetch them withget(). - Consistent output — every public series uses decimal fractions, an
ascending
DatetimeIndex, float values, and a stable series name. - Broad coverage — CPI and policy-rate series across the United States, Hong Kong, India, China, the United Kingdom, Israel, and the euro area.
- Raw-source access — use the underlying clients when source-native units and shapes are required.
- Source-aware transport — shared retries, proxy support, secret redaction, and compatibility handling for sources with specialized TLS or User-Agent requirements.
Installation
python -m pip install okama-macro
Requires Python ≥ 3.11. Runs on both pandas 2.x and 3.x.
Quick start
from okama_macro import get, list_series
# Discover the supported public keys.
keys = list_series()
# Fetch a normalized rate series for a date window.
deposit_rate = get(
"EU_DFR.RATE",
first_date="2024-01-01",
last_date="2024-12-31",
)
# Monthly m/m inflation as a decimal fraction:
us_inflation = get("USD.INFL", first_date="2024-01-01")
Each get() call returns a pandas.Series. For example, a 3.62% rate is
represented as 0.0362, not 3.62.
USD.INFLandUS_EFFR.RATErequire a FRED API key in theFRED_API_KEYenvironment variable.
Data contract
Every series returned by get() obeys the same contract, so callers never
special-case a source:
- Decimal fractions — m/m inflation
0.0042, a rate0.0525(never percent, never an index level). - CPI series are monthly, stamped on the first of the month, derived from
the source's index via
pct_change()(base-invariant). - Rate series normally carry observations only — no padding. Forward-fill
to a daily grid on the consumer side if you need one.
UK_BR.RATEis the documented exception: the Bank of England source publishes change dates, and the client safely forward-fills them into a daily series. - Ascending
DatetimeIndex,floatdtype, andSeries.name == key.
get() raises ValueError for an unknown key (listing the known ones);
list_series() returns the available keys, sorted.
Available series
| Key | Series | Country | Source module |
|---|---|---|---|
USD.INFL |
US CPI, m/m | United States | fred (FRED CPIAUCNS) |
US_EFFR.RATE |
US Federal Funds rate | United States | fred (FRED DFF) |
HKD.INFL |
Hong Kong Composite CPI, m/m | Hong Kong | censtatd (HK C&SD) |
HK_BR.RATE |
HKMA Discount Window Base Rate | Hong Kong | hkma |
INR.INFL |
India General CPI, m/m | India | mospi (MOSPI) |
IND_RBI.RATE |
RBI policy repo rate | India | bis (history) + rbi (same-day tail) |
CNY.INFL |
China CPI, m/m | China | nbsc (NBS China) |
CHN_LPR1.RATE |
China one-year Loan Prime Rate | China | cfets |
CHN_LPR5.RATE |
China five-year Loan Prime Rate | China | cfets |
GBP.INFL |
UK CPIH, m/m | United Kingdom | ons (UK ONS) |
UK_BR.RATE |
Bank of England Bank Rate | United Kingdom | boe |
ILS.INFL |
Israel CPI, m/m | Israel | boi (Bank of Israel) |
ISR_IR.RATE |
Bank of Israel policy rate | Israel | boi |
EU_MRO.RATE |
ECB main refinancing operations rate | Euro area | ecb |
EU_MLR.RATE |
ECB marginal lending facility rate | Euro area | ecb |
EU_DFR.RATE |
ECB deposit facility rate | Euro area | ecb |
Raw source clients
Each source also exposes its raw client under okama_macro.sources.*, returning
data as the agency publishes it (CPI index levels, rates in percent) — use
these only if you need the unnormalised series; prefer get() otherwise.
from okama_macro.sources import (
bis, boe, boi, censtatd, cfets, ecb, fred, hkma, mospi, nbsc, ons, rbi
)
hkma.get_base_rate() # percent, daily
censtatd.get_composite_cpi() # CPI index level, monthly
Configuration (environment)
| Variable | Needed for | Notes |
|---|---|---|
FRED_API_KEY |
USD.INFL, US_EFFR.RATE |
Free key from FRED; kept out of logs. |
PROXY_HOST, PROXY_PORT |
bis, mospi, rbi |
Optional outbound HTTP proxy. |
PROXY_USER, PROXY_PASS |
— | Optional proxy credentials. |
Data provenance and limitations
- Public series are fetched from the publishers named in the table above and
normalized by
okama_macro.registry; raw clients preserve source-native units and shapes. - Publishers can revise historical observations, change endpoint behavior, or publish on different schedules. Results therefore reflect the data available from the upstream source at request time.
- Historical depth and observation frequency are source-specific. Do not assume that every country or rate has the same start date or update cadence.
- Malformed and unexpectedly empty upstream responses fail loudly. The registry does not silently replace one publisher with another unless composition is an explicit, documented rule.
- For audit-sensitive use, compare critical observations with the original publisher and consult the recorded data-quality audits below.
Data quality
Material parser changes and newly consumed series are checked against independent sources when a comparable mirror exists. The recorded audits describe the comparison method, coverage, and known limitations:
Architecture
okama_macro/
├── __init__.py # public API: get(), list_series()
├── registry.py # key -> normalised Series (the contract)
├── _http.py # shared Session: retry/back-off, proxy, browser UA,
│ # legacy-TLS, secret redaction
├── _frame.py # DataFrame/Series shaping helpers
└── sources/ # one client per source (bis, boe, boi, censtatd, cfets,
# ecb, fred, hkma, mospi, nbsc, ons, rbi)
Two layers: thin sources (data as published, on the shared _http) and a
registry that normalises each key to the contract above.
The package replaces separate per-source clients and duplicated modules that previously lived across the okama ecosystem. The rationale and migration history are tracked in mbk-dev/okama-API#41.
Contributing
Set up a local development checkout with Poetry:
git clone https://github.com/mbk-dev/okama-macro.git
cd okama-macro
poetry install
poetry run pytest -q
poetry run ruff check .
poetry build
CI runs the suite and lint on Python 3.11, 3.12, 3.13 and 3.14. Keep executable
changes covered by tests and do not commit poetry.lock; the full development
workflow is documented in
CONTRIBUTING.md.
License
okama-macro is distributed under the
MIT License.
Release files for okama-macro 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| okama_macro-0.1.4.tar.gz | 37.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| okama_macro-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 89.0 kB
Release files / okama_macro-0.1.4.tar.gz
| Download URL | okama_macro-0.1.4.tar.gz |
|---|---|
| Size | 37.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
36bede31622799d3dd6bc18fc98e908d6ee858c43b54e88802e6e88cd6773609
|
|
BLAKE2b-256 checksum How to use checksums |
09f8227d352ef7ae7bd2fa5c164a32f4f19abd1cf62e8e49cd81294becfd198e
|
| 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 Sep 28, 2026.
Transparency logRelease files / okama_macro-0.1.4-py3-none-any.whl
| Download URL | okama_macro-0.1.4-py3-none-any.whl |
|---|---|
| Size | 51.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8540eda8fd9c2f885b847e509aae02b03359f748fb44ad55fe08910dc4d35cb9
|
|
BLAKE2b-256 checksum How to use checksums |
7e60432f1d9701dd4c2c32070835ca506c94e4a3464c47c2900382ebfd0e86e7
|
| 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 Sep 28, 2026.
Transparency log