boj-api 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- boj_api-0.1.0/.gitattributes +2 -0
- boj_api-0.1.0/.github/workflows/tests.yml +54 -0
- boj_api-0.1.0/.gitignore +44 -0
- boj_api-0.1.0/LICENSE +21 -0
- boj_api-0.1.0/PKG-INFO +195 -0
- boj_api-0.1.0/README.md +156 -0
- boj_api-0.1.0/pyproject.toml +105 -0
- boj_api-0.1.0/scripts/live_validation.py +213 -0
- boj_api-0.1.0/setup.cfg +4 -0
- boj_api-0.1.0/src/boj_api/__init__.py +68 -0
- boj_api-0.1.0/src/boj_api/client.py +786 -0
- boj_api-0.1.0/src/boj_api/constants.py +128 -0
- boj_api-0.1.0/src/boj_api/enums.py +144 -0
- boj_api-0.1.0/src/boj_api/exceptions.py +95 -0
- boj_api-0.1.0/src/boj_api/models.py +242 -0
- boj_api-0.1.0/src/boj_api/py.typed +0 -0
- boj_api-0.1.0/src/boj_api.egg-info/PKG-INFO +195 -0
- boj_api-0.1.0/src/boj_api.egg-info/SOURCES.txt +24 -0
- boj_api-0.1.0/src/boj_api.egg-info/dependency_links.txt +1 -0
- boj_api-0.1.0/src/boj_api.egg-info/requires.txt +9 -0
- boj_api-0.1.0/src/boj_api.egg-info/top_level.txt +1 -0
- boj_api-0.1.0/tests/conftest.py +284 -0
- boj_api-0.1.0/tests/test_client.py +798 -0
- boj_api-0.1.0/tests/test_enums.py +103 -0
- boj_api-0.1.0/tests/test_exceptions.py +113 -0
- boj_api-0.1.0/tests/test_models.py +177 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
name: Tests
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
strategy:
|
|
16
|
+
fail-fast: false
|
|
17
|
+
matrix:
|
|
18
|
+
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
|
|
19
|
+
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
|
|
23
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
24
|
+
uses: actions/setup-python@v5
|
|
25
|
+
with:
|
|
26
|
+
python-version: ${{ matrix.python-version }}
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: |
|
|
30
|
+
python -m pip install --upgrade pip
|
|
31
|
+
pip install -e ".[dev]"
|
|
32
|
+
|
|
33
|
+
- name: Lint with ruff
|
|
34
|
+
run: |
|
|
35
|
+
ruff check src/ tests/
|
|
36
|
+
|
|
37
|
+
- name: Format check with ruff
|
|
38
|
+
run: |
|
|
39
|
+
ruff format --check src/ tests/
|
|
40
|
+
|
|
41
|
+
- name: Type check with mypy
|
|
42
|
+
run: |
|
|
43
|
+
mypy src/
|
|
44
|
+
|
|
45
|
+
- name: Run tests with pytest
|
|
46
|
+
run: |
|
|
47
|
+
pytest --cov=boj_api --cov-report=term-missing --cov-report=xml
|
|
48
|
+
|
|
49
|
+
- name: Upload coverage
|
|
50
|
+
if: matrix.python-version == '3.12'
|
|
51
|
+
uses: actions/upload-artifact@v4
|
|
52
|
+
with:
|
|
53
|
+
name: coverage-report
|
|
54
|
+
path: coverage.xml
|
boj_api-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Distribution / packaging
|
|
7
|
+
build/
|
|
8
|
+
dist/
|
|
9
|
+
*.egg-info/
|
|
10
|
+
*.egg
|
|
11
|
+
src/*.egg-info/
|
|
12
|
+
|
|
13
|
+
# Virtual environments
|
|
14
|
+
.venv/
|
|
15
|
+
venv/
|
|
16
|
+
ENV/
|
|
17
|
+
|
|
18
|
+
# IDE / editor
|
|
19
|
+
.vscode/
|
|
20
|
+
.idea/
|
|
21
|
+
*.swp
|
|
22
|
+
*.swo
|
|
23
|
+
*~
|
|
24
|
+
|
|
25
|
+
# Type checker
|
|
26
|
+
.mypy_cache/
|
|
27
|
+
.pytype/
|
|
28
|
+
|
|
29
|
+
# Testing
|
|
30
|
+
.pytest_cache/
|
|
31
|
+
htmlcov/
|
|
32
|
+
.coverage
|
|
33
|
+
.coverage.*
|
|
34
|
+
coverage.xml
|
|
35
|
+
|
|
36
|
+
# Ruff
|
|
37
|
+
.ruff_cache/
|
|
38
|
+
|
|
39
|
+
# OS
|
|
40
|
+
.DS_Store
|
|
41
|
+
Thumbs.db
|
|
42
|
+
|
|
43
|
+
# Jupyter
|
|
44
|
+
.ipynb_checkpoints/
|
boj_api-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kenta Aratani
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
boj_api-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: boj-api
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A production-ready Python client for the Bank of Japan (BOJ) Time-Series Statistics Search Site API.
|
|
5
|
+
Author: Kenta Aratani
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/YenAle-FT-Gmail/BOJ_API_Python
|
|
8
|
+
Project-URL: Repository, https://github.com/YenAle-FT-Gmail/BOJ_API_Python
|
|
9
|
+
Project-URL: Issues, https://github.com/YenAle-FT-Gmail/BOJ_API_Python/issues
|
|
10
|
+
Keywords: boj,bank-of-japan,statistics,api,time-series,economics,finance
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
25
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.8
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Requires-Dist: requests>=2.28.0
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
33
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
34
|
+
Requires-Dist: ruff>=0.4.0; extra == "dev"
|
|
35
|
+
Requires-Dist: mypy>=1.0; extra == "dev"
|
|
36
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
37
|
+
Requires-Dist: types-requests>=2.28.0; extra == "dev"
|
|
38
|
+
Dynamic: license-file
|
|
39
|
+
|
|
40
|
+
# boj-api
|
|
41
|
+
|
|
42
|
+
A production-ready Python client for the **Bank of Japan (BOJ) Time-Series Statistics Search Site API**.
|
|
43
|
+
|
|
44
|
+
This library provides a clean, typed, and well-documented interface to all three BOJ statistical data APIs:
|
|
45
|
+
|
|
46
|
+
| API | Method | Description |
|
|
47
|
+
|-----|--------|-------------|
|
|
48
|
+
| Code API | `get_data_by_code()` | Fetch time-series data by series codes |
|
|
49
|
+
| Layer API | `get_data_by_layer()` | Fetch time-series data by hierarchy/layer |
|
|
50
|
+
| Metadata API | `get_metadata()` | Fetch database metadata (series names, units, layers, etc.) |
|
|
51
|
+
|
|
52
|
+
> **Credit:** This library uses the Bank of Japan Time-Series Statistics Search Site API.
|
|
53
|
+
> The content is not guaranteed by the Bank of Japan.
|
|
54
|
+
>
|
|
55
|
+
> 「このサービスは、日本銀行時系列統計データ検索サイトのAPI機能を使用しています。
|
|
56
|
+
> サービスの内容は日本銀行によって保証されたものではありません。」
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pip install boj-api
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Quick Start
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from boj_api import BOJClient, Database, Frequency
|
|
68
|
+
|
|
69
|
+
client = BOJClient()
|
|
70
|
+
|
|
71
|
+
# Fetch exchange rate data (Code API)
|
|
72
|
+
response = client.get_data_by_code(
|
|
73
|
+
db=Database.FM08,
|
|
74
|
+
code=["FXERD09", "FXERD02"],
|
|
75
|
+
start_date="202401",
|
|
76
|
+
end_date="202412",
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
for series in response.series:
|
|
80
|
+
print(f"{series.name_jp}: {len(series.observations)} observations")
|
|
81
|
+
|
|
82
|
+
# Fetch data by layer hierarchy (Layer API)
|
|
83
|
+
response = client.get_data_by_layer(
|
|
84
|
+
db=Database.BP01,
|
|
85
|
+
frequency=Frequency.MONTHLY,
|
|
86
|
+
layer=[1, 1, 1],
|
|
87
|
+
start_date="202504",
|
|
88
|
+
end_date="202509",
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
# Fetch metadata for a database (Metadata API)
|
|
92
|
+
metadata = client.get_metadata(db=Database.FM08)
|
|
93
|
+
for entry in metadata.entries:
|
|
94
|
+
print(f"{entry.series_code}: {entry.name_jp}")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Auto-Pagination
|
|
98
|
+
|
|
99
|
+
The BOJ API limits results to 250 series / 60,000 data points per request.
|
|
100
|
+
`BOJClient` handles pagination automatically:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
# Automatically follows NEXTPOSITION until all data is fetched
|
|
104
|
+
all_data = client.get_data_by_code(
|
|
105
|
+
db=Database.CO,
|
|
106
|
+
code=series_codes, # can exceed 250
|
|
107
|
+
auto_paginate=True,
|
|
108
|
+
)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Databases
|
|
112
|
+
|
|
113
|
+
All BOJ database identifiers are available as the `Database` enum:
|
|
114
|
+
|
|
115
|
+
| Enum | DB Name | Description |
|
|
116
|
+
|------|---------|-------------|
|
|
117
|
+
| `Database.IR01` | IR01 | Base discount/loan rates |
|
|
118
|
+
| `Database.FM01` | FM01 | Uncollateralized overnight call rate |
|
|
119
|
+
| `Database.FM08` | FM08 | Foreign exchange rates |
|
|
120
|
+
| `Database.CO` | CO | Tankan survey |
|
|
121
|
+
| `Database.FF` | FF | Flow of funds |
|
|
122
|
+
| ... | ... | See `boj_api.enums.Database` for full list |
|
|
123
|
+
|
|
124
|
+
## Frequency Types
|
|
125
|
+
|
|
126
|
+
| Enum | Code | Description |
|
|
127
|
+
|------|------|-------------|
|
|
128
|
+
| `Frequency.CALENDAR_YEAR` | CY | Calendar year |
|
|
129
|
+
| `Frequency.FISCAL_YEAR` | FY | Fiscal year |
|
|
130
|
+
| `Frequency.SEMI_ANNUAL_CY` | CH | Semi-annual (calendar) |
|
|
131
|
+
| `Frequency.SEMI_ANNUAL_FY` | FH | Semi-annual (fiscal) |
|
|
132
|
+
| `Frequency.QUARTERLY` | Q | Quarterly |
|
|
133
|
+
| `Frequency.MONTHLY` | M | Monthly |
|
|
134
|
+
| `Frequency.WEEKLY` | W | Weekly |
|
|
135
|
+
| `Frequency.DAILY` | D | Daily |
|
|
136
|
+
|
|
137
|
+
## API Reference
|
|
138
|
+
|
|
139
|
+
### `BOJClient`
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
BOJClient(
|
|
143
|
+
lang: Language = Language.JP,
|
|
144
|
+
format: Format = Format.JSON,
|
|
145
|
+
timeout: float = 30.0,
|
|
146
|
+
max_retries: int = 3,
|
|
147
|
+
retry_delay: float = 1.0,
|
|
148
|
+
)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Error Handling
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
from boj_api import BOJClient, BOJAPIError, InvalidParameterError
|
|
155
|
+
|
|
156
|
+
client = BOJClient()
|
|
157
|
+
try:
|
|
158
|
+
data = client.get_data_by_code(db="INVALID", code=["X"])
|
|
159
|
+
except InvalidParameterError as e:
|
|
160
|
+
print(f"Bad request: {e.message_id} - {e.message}")
|
|
161
|
+
except BOJAPIError as e:
|
|
162
|
+
print(f"API error: {e}")
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Development
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
# Clone the repository
|
|
169
|
+
git clone https://github.com/YenAle-FT-Gmail/BOJ_API_Python.git
|
|
170
|
+
cd BOJ_API_Python
|
|
171
|
+
|
|
172
|
+
# Install in development mode
|
|
173
|
+
pip install -e ".[dev]"
|
|
174
|
+
|
|
175
|
+
# Run tests
|
|
176
|
+
pytest
|
|
177
|
+
|
|
178
|
+
# Lint & format
|
|
179
|
+
ruff check src/ tests/
|
|
180
|
+
ruff format src/ tests/
|
|
181
|
+
|
|
182
|
+
# Type check
|
|
183
|
+
mypy src/
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## License
|
|
187
|
+
|
|
188
|
+
MIT License. See [LICENSE](LICENSE) for details.
|
|
189
|
+
|
|
190
|
+
## Links
|
|
191
|
+
|
|
192
|
+
- [BOJ API Announcement (2026-02-18)](https://www.boj.or.jp/statistics/outline/notice_2026/not260218a.htm)
|
|
193
|
+
- [API Manual (PDF)](https://www.stat-search.boj.or.jp/info/api_manual.pdf)
|
|
194
|
+
- [API Usage Notice (PDF)](https://www.stat-search.boj.or.jp/info/api_notice.pdf)
|
|
195
|
+
- [BOJ Time-Series Statistics Search Site](https://www.stat-search.boj.or.jp/index.html)
|
boj_api-0.1.0/README.md
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
# boj-api
|
|
2
|
+
|
|
3
|
+
A production-ready Python client for the **Bank of Japan (BOJ) Time-Series Statistics Search Site API**.
|
|
4
|
+
|
|
5
|
+
This library provides a clean, typed, and well-documented interface to all three BOJ statistical data APIs:
|
|
6
|
+
|
|
7
|
+
| API | Method | Description |
|
|
8
|
+
|-----|--------|-------------|
|
|
9
|
+
| Code API | `get_data_by_code()` | Fetch time-series data by series codes |
|
|
10
|
+
| Layer API | `get_data_by_layer()` | Fetch time-series data by hierarchy/layer |
|
|
11
|
+
| Metadata API | `get_metadata()` | Fetch database metadata (series names, units, layers, etc.) |
|
|
12
|
+
|
|
13
|
+
> **Credit:** This library uses the Bank of Japan Time-Series Statistics Search Site API.
|
|
14
|
+
> The content is not guaranteed by the Bank of Japan.
|
|
15
|
+
>
|
|
16
|
+
> 「このサービスは、日本銀行時系列統計データ検索サイトのAPI機能を使用しています。
|
|
17
|
+
> サービスの内容は日本銀行によって保証されたものではありません。」
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install boj-api
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from boj_api import BOJClient, Database, Frequency
|
|
29
|
+
|
|
30
|
+
client = BOJClient()
|
|
31
|
+
|
|
32
|
+
# Fetch exchange rate data (Code API)
|
|
33
|
+
response = client.get_data_by_code(
|
|
34
|
+
db=Database.FM08,
|
|
35
|
+
code=["FXERD09", "FXERD02"],
|
|
36
|
+
start_date="202401",
|
|
37
|
+
end_date="202412",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
for series in response.series:
|
|
41
|
+
print(f"{series.name_jp}: {len(series.observations)} observations")
|
|
42
|
+
|
|
43
|
+
# Fetch data by layer hierarchy (Layer API)
|
|
44
|
+
response = client.get_data_by_layer(
|
|
45
|
+
db=Database.BP01,
|
|
46
|
+
frequency=Frequency.MONTHLY,
|
|
47
|
+
layer=[1, 1, 1],
|
|
48
|
+
start_date="202504",
|
|
49
|
+
end_date="202509",
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
# Fetch metadata for a database (Metadata API)
|
|
53
|
+
metadata = client.get_metadata(db=Database.FM08)
|
|
54
|
+
for entry in metadata.entries:
|
|
55
|
+
print(f"{entry.series_code}: {entry.name_jp}")
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Auto-Pagination
|
|
59
|
+
|
|
60
|
+
The BOJ API limits results to 250 series / 60,000 data points per request.
|
|
61
|
+
`BOJClient` handles pagination automatically:
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
# Automatically follows NEXTPOSITION until all data is fetched
|
|
65
|
+
all_data = client.get_data_by_code(
|
|
66
|
+
db=Database.CO,
|
|
67
|
+
code=series_codes, # can exceed 250
|
|
68
|
+
auto_paginate=True,
|
|
69
|
+
)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Databases
|
|
73
|
+
|
|
74
|
+
All BOJ database identifiers are available as the `Database` enum:
|
|
75
|
+
|
|
76
|
+
| Enum | DB Name | Description |
|
|
77
|
+
|------|---------|-------------|
|
|
78
|
+
| `Database.IR01` | IR01 | Base discount/loan rates |
|
|
79
|
+
| `Database.FM01` | FM01 | Uncollateralized overnight call rate |
|
|
80
|
+
| `Database.FM08` | FM08 | Foreign exchange rates |
|
|
81
|
+
| `Database.CO` | CO | Tankan survey |
|
|
82
|
+
| `Database.FF` | FF | Flow of funds |
|
|
83
|
+
| ... | ... | See `boj_api.enums.Database` for full list |
|
|
84
|
+
|
|
85
|
+
## Frequency Types
|
|
86
|
+
|
|
87
|
+
| Enum | Code | Description |
|
|
88
|
+
|------|------|-------------|
|
|
89
|
+
| `Frequency.CALENDAR_YEAR` | CY | Calendar year |
|
|
90
|
+
| `Frequency.FISCAL_YEAR` | FY | Fiscal year |
|
|
91
|
+
| `Frequency.SEMI_ANNUAL_CY` | CH | Semi-annual (calendar) |
|
|
92
|
+
| `Frequency.SEMI_ANNUAL_FY` | FH | Semi-annual (fiscal) |
|
|
93
|
+
| `Frequency.QUARTERLY` | Q | Quarterly |
|
|
94
|
+
| `Frequency.MONTHLY` | M | Monthly |
|
|
95
|
+
| `Frequency.WEEKLY` | W | Weekly |
|
|
96
|
+
| `Frequency.DAILY` | D | Daily |
|
|
97
|
+
|
|
98
|
+
## API Reference
|
|
99
|
+
|
|
100
|
+
### `BOJClient`
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
BOJClient(
|
|
104
|
+
lang: Language = Language.JP,
|
|
105
|
+
format: Format = Format.JSON,
|
|
106
|
+
timeout: float = 30.0,
|
|
107
|
+
max_retries: int = 3,
|
|
108
|
+
retry_delay: float = 1.0,
|
|
109
|
+
)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Error Handling
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from boj_api import BOJClient, BOJAPIError, InvalidParameterError
|
|
116
|
+
|
|
117
|
+
client = BOJClient()
|
|
118
|
+
try:
|
|
119
|
+
data = client.get_data_by_code(db="INVALID", code=["X"])
|
|
120
|
+
except InvalidParameterError as e:
|
|
121
|
+
print(f"Bad request: {e.message_id} - {e.message}")
|
|
122
|
+
except BOJAPIError as e:
|
|
123
|
+
print(f"API error: {e}")
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Development
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Clone the repository
|
|
130
|
+
git clone https://github.com/YenAle-FT-Gmail/BOJ_API_Python.git
|
|
131
|
+
cd BOJ_API_Python
|
|
132
|
+
|
|
133
|
+
# Install in development mode
|
|
134
|
+
pip install -e ".[dev]"
|
|
135
|
+
|
|
136
|
+
# Run tests
|
|
137
|
+
pytest
|
|
138
|
+
|
|
139
|
+
# Lint & format
|
|
140
|
+
ruff check src/ tests/
|
|
141
|
+
ruff format src/ tests/
|
|
142
|
+
|
|
143
|
+
# Type check
|
|
144
|
+
mypy src/
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
MIT License. See [LICENSE](LICENSE) for details.
|
|
150
|
+
|
|
151
|
+
## Links
|
|
152
|
+
|
|
153
|
+
- [BOJ API Announcement (2026-02-18)](https://www.boj.or.jp/statistics/outline/notice_2026/not260218a.htm)
|
|
154
|
+
- [API Manual (PDF)](https://www.stat-search.boj.or.jp/info/api_manual.pdf)
|
|
155
|
+
- [API Usage Notice (PDF)](https://www.stat-search.boj.or.jp/info/api_notice.pdf)
|
|
156
|
+
- [BOJ Time-Series Statistics Search Site](https://www.stat-search.boj.or.jp/index.html)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0", "setuptools-scm>=8.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "boj-api"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A production-ready Python client for the Bank of Japan (BOJ) Time-Series Statistics Search Site API."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { text = "MIT" }
|
|
11
|
+
requires-python = ">=3.8"
|
|
12
|
+
authors = [{ name = "Kenta Aratani" }]
|
|
13
|
+
keywords = [
|
|
14
|
+
"boj",
|
|
15
|
+
"bank-of-japan",
|
|
16
|
+
"statistics",
|
|
17
|
+
"api",
|
|
18
|
+
"time-series",
|
|
19
|
+
"economics",
|
|
20
|
+
"finance",
|
|
21
|
+
]
|
|
22
|
+
classifiers = [
|
|
23
|
+
"Development Status :: 4 - Beta",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"Intended Audience :: Financial and Insurance Industry",
|
|
26
|
+
"Intended Audience :: Science/Research",
|
|
27
|
+
"License :: OSI Approved :: MIT License",
|
|
28
|
+
"Operating System :: OS Independent",
|
|
29
|
+
"Programming Language :: Python :: 3",
|
|
30
|
+
"Programming Language :: Python :: 3.8",
|
|
31
|
+
"Programming Language :: Python :: 3.9",
|
|
32
|
+
"Programming Language :: Python :: 3.10",
|
|
33
|
+
"Programming Language :: Python :: 3.11",
|
|
34
|
+
"Programming Language :: Python :: 3.12",
|
|
35
|
+
"Programming Language :: Python :: 3.13",
|
|
36
|
+
"Topic :: Office/Business :: Financial",
|
|
37
|
+
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
38
|
+
"Typing :: Typed",
|
|
39
|
+
]
|
|
40
|
+
dependencies = ["requests>=2.28.0"]
|
|
41
|
+
|
|
42
|
+
[project.optional-dependencies]
|
|
43
|
+
dev = [
|
|
44
|
+
"pytest>=7.0",
|
|
45
|
+
"pytest-cov>=4.0",
|
|
46
|
+
"ruff>=0.4.0",
|
|
47
|
+
"mypy>=1.0",
|
|
48
|
+
"build>=1.0",
|
|
49
|
+
"types-requests>=2.28.0",
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
[project.urls]
|
|
53
|
+
Homepage = "https://github.com/YenAle-FT-Gmail/BOJ_API_Python"
|
|
54
|
+
Repository = "https://github.com/YenAle-FT-Gmail/BOJ_API_Python"
|
|
55
|
+
Issues = "https://github.com/YenAle-FT-Gmail/BOJ_API_Python/issues"
|
|
56
|
+
|
|
57
|
+
[tool.setuptools.packages.find]
|
|
58
|
+
where = ["src"]
|
|
59
|
+
|
|
60
|
+
[tool.ruff]
|
|
61
|
+
target-version = "py38"
|
|
62
|
+
line-length = 100
|
|
63
|
+
src = ["src", "tests"]
|
|
64
|
+
|
|
65
|
+
[tool.ruff.lint]
|
|
66
|
+
select = [
|
|
67
|
+
"E", # pycodestyle errors
|
|
68
|
+
"W", # pycodestyle warnings
|
|
69
|
+
"F", # pyflakes
|
|
70
|
+
"I", # isort
|
|
71
|
+
"N", # pep8-naming
|
|
72
|
+
"UP", # pyupgrade
|
|
73
|
+
"B", # flake8-bugbear
|
|
74
|
+
"SIM", # flake8-simplify
|
|
75
|
+
"TCH", # flake8-type-checking
|
|
76
|
+
"RUF", # ruff-specific rules
|
|
77
|
+
]
|
|
78
|
+
ignore = [
|
|
79
|
+
"UP007", # Use X | Y for union types (not available in 3.8/3.9)
|
|
80
|
+
]
|
|
81
|
+
|
|
82
|
+
[tool.ruff.lint.per-file-ignores]
|
|
83
|
+
# Japanese text legitimately uses fullwidth characters
|
|
84
|
+
"src/boj_api/constants.py" = ["RUF001"]
|
|
85
|
+
"tests/conftest.py" = ["RUF001"]
|
|
86
|
+
|
|
87
|
+
[tool.ruff.lint.isort]
|
|
88
|
+
known-first-party = ["boj_api"]
|
|
89
|
+
|
|
90
|
+
[tool.mypy]
|
|
91
|
+
python_version = "3.8"
|
|
92
|
+
strict = true
|
|
93
|
+
warn_return_any = true
|
|
94
|
+
warn_unused_configs = true
|
|
95
|
+
disallow_untyped_defs = true
|
|
96
|
+
|
|
97
|
+
[tool.pytest.ini_options]
|
|
98
|
+
testpaths = ["tests"]
|
|
99
|
+
addopts = [
|
|
100
|
+
"--strict-markers",
|
|
101
|
+
"--tb=short",
|
|
102
|
+
"-v",
|
|
103
|
+
"--cov=boj_api",
|
|
104
|
+
"--cov-report=term-missing",
|
|
105
|
+
]
|