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.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file boj_ts_api-0.2.0.tar.gz.
File metadata
- Download URL: boj_ts_api-0.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee1665d8cd53ac8ae690e7f4e986b9a0ae043ecc1f4b4da8c94ce39e210208cd
|
|
| MD5 |
3c9ae76c9b25d221ed0531ecbd46087f
|
|
| BLAKE2b-256 |
a2aef659760476b91756c70ddd145fc212619087ea81ae52827ec00c58eb4ca3
|
File details
Details for the file boj_ts_api-0.2.0-py3-none-any.whl.
File metadata
- Download URL: boj_ts_api-0.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6efc36725467daa4b855fd464397618e551bf472c86443fa8cbb18e14746dc4e
|
|
| MD5 |
5606206190cb603ad11104e222788983
|
|
| BLAKE2b-256 |
cd9cfaf2f0de56a6242a0321099ba0f9499eaa1ba2944183173ac10e9910c5e5
|