Skip to main content

Generic Python client for the Bank of Japan Time-Series Statistics API

Project description

boj-ts-api

Generic Python client for the Bank of Japan Time-Series Statistics API.

PyPI License: MIT Python 3.10+

Low-level, typed wrapper around the three BOJ API endpoints. For a beginner-friendly interface with domain wrappers and enum-driven filtering, see pyboj.

Installation

pip install boj-ts-api

Usage

Fetch Data by Series Code

from boj_ts_api import Client, Lang

with Client(lang=Lang.EN) as client:
    resp = client.get_data_code(
        db="CO",
        code="TK99F1000601GCQ01000",
        start_date="202401",
        end_date="202404",
    )
    for series in resp.RESULTSET:
        print(series.SERIES_CODE, series.VALUES.VALUES)

Auto-Pagination

with Client(lang=Lang.EN) as client:
    for series in client.iter_data_code(db="CO", code="TK99F1000601GCQ01000"):
        print(series.SERIES_CODE, len(series.VALUES.SURVEY_DATES), "data points")

Fetch Data by Layer

from boj_ts_api import Client, Frequency, Lang

with Client(lang=Lang.EN) as client:
    resp = client.get_data_layer(db="FM08", frequency=Frequency.D, layer="1,1")
    for series in resp.RESULTSET:
        print(series.SERIES_CODE, series.VALUES.VALUES[:5])

Metadata

with Client(lang=Lang.EN) as client:
    meta = client.get_metadata(db="FM08")
    for rec in meta.RESULTSET[:3]:
        print(rec.SERIES_CODE, rec.FREQUENCY, rec.NAME_OF_TIME_SERIES)

Async Client

import asyncio
from boj_ts_api import AsyncClient, Lang

async def main():
    async with AsyncClient(lang=Lang.EN) as client:
        resp = await client.get_data_code(db="CO", code="TK99F1000601GCQ01000")
        print(resp.RESULTSET[0].SERIES_CODE)

asyncio.run(main())

CSV Output

with Client(lang=Lang.EN) as client:
    csv_text = client.get_data_code_csv(db="CO", code="TK99F1000601GCQ01000")
    print(csv_text)

API Surface

Method Description
get_data_code() Fetch time-series data by series code(s)
iter_data_code() Auto-paginating iterator over series results
get_data_code_csv() Fetch data as raw CSV text
get_data_layer() Fetch data by hierarchy layer
iter_data_layer() Auto-paginating iterator for layer data
get_data_layer_csv() Fetch layer data as raw CSV text
get_metadata() Fetch series metadata for a database
get_metadata_csv() Fetch metadata as raw CSV text

Both Client (sync) and AsyncClient (async) expose the same methods.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

boj_ts_api-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

boj_ts_api-0.1.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file boj_ts_api-0.1.0.tar.gz.

File metadata

  • Download URL: boj_ts_api-0.1.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for boj_ts_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 680e3f3f1b4f6834d9606ac8137a6356269e0c29a829df44fe99b699319ba3de
MD5 8ad0d618bc19b52014b9ca6ed113bdd2
BLAKE2b-256 33727e212fdb6dd47ca4d62965157075472c7f274e8392ef14b8ef22ecf27daf

See more details on using hashes here.

File details

Details for the file boj_ts_api-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: boj_ts_api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for boj_ts_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d142e4e4c75834ec98fbd23d035c38524aeacbdf144aeff0de89abf5689f1487
MD5 61036d5cd17db35e5a731de1f11a3887
BLAKE2b-256 d5e65faf73951d1c712c821f77ba8fa47e6967351ea4dc9f8ec419749a92181a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page