ecos-reader 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.
Files changed (38) hide show
  1. ecos_reader-0.1.0/.gitignore +152 -0
  2. ecos_reader-0.1.0/.pre-commit-config.yaml +23 -0
  3. ecos_reader-0.1.0/API_SPEC.md +69 -0
  4. ecos_reader-0.1.0/LICENSE +21 -0
  5. ecos_reader-0.1.0/PKG-INFO +286 -0
  6. ecos_reader-0.1.0/README.md +248 -0
  7. ecos_reader-0.1.0/ROADMAP.md +903 -0
  8. ecos_reader-0.1.0/examples/basic_usage.py +142 -0
  9. ecos_reader-0.1.0/examples/macro_dashboard.py +176 -0
  10. ecos_reader-0.1.0/pyproject.toml +105 -0
  11. ecos_reader-0.1.0/src/ecos/__init__.py +109 -0
  12. ecos_reader-0.1.0/src/ecos/cache.py +212 -0
  13. ecos_reader-0.1.0/src/ecos/client.py +394 -0
  14. ecos_reader-0.1.0/src/ecos/config.py +148 -0
  15. ecos_reader-0.1.0/src/ecos/constants.py +155 -0
  16. ecos_reader-0.1.0/src/ecos/exceptions.py +73 -0
  17. ecos_reader-0.1.0/src/ecos/indicators/__init__.py +29 -0
  18. ecos_reader-0.1.0/src/ecos/indicators/growth.py +186 -0
  19. ecos_reader-0.1.0/src/ecos/indicators/interest_rate.py +226 -0
  20. ecos_reader-0.1.0/src/ecos/indicators/money.py +173 -0
  21. ecos_reader-0.1.0/src/ecos/indicators/prices.py +206 -0
  22. ecos_reader-0.1.0/src/ecos/logging.py +205 -0
  23. ecos_reader-0.1.0/src/ecos/metrics.py +247 -0
  24. ecos_reader-0.1.0/src/ecos/parser.py +197 -0
  25. ecos_reader-0.1.0/src/ecos/py.typed +0 -0
  26. ecos_reader-0.1.0/src/ecos/types.py +84 -0
  27. ecos_reader-0.1.0/tests/__init__.py +1 -0
  28. ecos_reader-0.1.0/tests/conftest.py +195 -0
  29. ecos_reader-0.1.0/tests/indicators/__init__.py +1 -0
  30. ecos_reader-0.1.0/tests/indicators/test_growth.py +117 -0
  31. ecos_reader-0.1.0/tests/indicators/test_interest_rate.py +131 -0
  32. ecos_reader-0.1.0/tests/indicators/test_money.py +137 -0
  33. ecos_reader-0.1.0/tests/indicators/test_prices.py +98 -0
  34. ecos_reader-0.1.0/tests/test_cache.py +140 -0
  35. ecos_reader-0.1.0/tests/test_client.py +229 -0
  36. ecos_reader-0.1.0/tests/test_config.py +93 -0
  37. ecos_reader-0.1.0/tests/test_parser.py +188 -0
  38. ecos_reader-0.1.0/uv.lock +1018 -0
@@ -0,0 +1,152 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ *.manifest
31
+ *.spec
32
+
33
+ # Installer logs
34
+ pip-log.txt
35
+ pip-delete-this-directory.txt
36
+
37
+ # Unit test / coverage reports
38
+ htmlcov/
39
+ .tox/
40
+ .nox/
41
+ .coverage
42
+ .coverage.*
43
+ .cache/
44
+ nosetests.xml
45
+ coverage.xml
46
+ *.cover
47
+ *.py,cover
48
+ .hypothesis/
49
+ .pytest_cache/
50
+
51
+ # Translations
52
+ *.mo
53
+ *.pot
54
+
55
+ # Django stuff:
56
+ *.log
57
+ local_settings.py
58
+ db.sqlite3
59
+ db.sqlite3-journal
60
+
61
+ # Flask stuff:
62
+ instance/
63
+ .webassets-cache
64
+
65
+ # Scrapy stuff:
66
+ .scrapy
67
+
68
+ # Sphinx documentation
69
+ docs/_build/
70
+
71
+ # PyBuilder
72
+ .pybuilder/
73
+ target/
74
+
75
+ # Jupyter Notebook
76
+ .ipynb_checkpoints/
77
+
78
+ # IPython
79
+ profile_default/
80
+ ipython_config.py
81
+
82
+ # pyenv
83
+ .python-version
84
+
85
+ # pipenv
86
+ Pipfile.lock
87
+
88
+ # PEP 582
89
+ __pypackages__/
90
+
91
+ # Celery stuff
92
+ celerybeat-schedule
93
+ celerybeat.pid
94
+
95
+ # SageMath parsed files
96
+ *.sage.py
97
+
98
+ # Environments
99
+ .env*
100
+ !.env.example
101
+ !.env.sample
102
+ .venv
103
+ env/
104
+ venv/
105
+ ENV/
106
+ env.bak/
107
+ venv.bak/
108
+
109
+ # Spyder project settings
110
+ .spyderproject
111
+ .spyproject
112
+
113
+ # Rope project settings
114
+ .ropeproject
115
+
116
+ # mkdocs documentation
117
+ /site
118
+
119
+ # mypy
120
+ .mypy_cache/
121
+ .dmypy.json
122
+ dmypy.json
123
+
124
+ # ruff
125
+ .ruff_cache/
126
+
127
+ # pyright
128
+ .pyright/
129
+
130
+ # Pyre type checker
131
+ .pyre/
132
+
133
+ # pytype static type analyzer
134
+ .pytype/
135
+
136
+ # Cython debug symbols
137
+ cython_debug/
138
+
139
+ # IDE
140
+ .idea/
141
+ .vscode/
142
+ .cursor/
143
+ *.swp
144
+ *.swo
145
+ *~
146
+
147
+ # OS
148
+ .DS_Store
149
+ Thumbs.db
150
+
151
+ # Project specific
152
+ *.bak
@@ -0,0 +1,23 @@
1
+ repos:
2
+ - repo: https://github.com/pre-commit/pre-commit-hooks
3
+ rev: v4.5.0
4
+ hooks:
5
+ - id: trailing-whitespace
6
+ - id: end-of-file-fixer
7
+ - id: check-yaml
8
+ - id: check-toml
9
+ - id: check-merge-conflict
10
+ - id: check-added-large-files
11
+
12
+ - repo: https://github.com/astral-sh/ruff-pre-commit
13
+ rev: v0.1.6
14
+ hooks:
15
+ - id: ruff
16
+ args: [--fix]
17
+ - id: ruff-format
18
+
19
+ - repo: https://github.com/pre-commit/mirrors-mypy
20
+ rev: v1.7.1
21
+ hooks:
22
+ - id: mypy
23
+ additional_dependencies: [types-requests]
@@ -0,0 +1,69 @@
1
+
2
+ ## 상세주소
3
+
4
+ * [https://ecos.bok.or.kr/api/](https://ecos.bok.or.kr/api/)
5
+
6
+ ---
7
+
8
+ ## 요청인자
9
+
10
+ | 항목명(국문) | 필수여부 | 샘플데이터 | 항목설명 |
11
+ | ------- | ---- | ----------------- | ------------------------ |
12
+ | 서비스명 | Y | StatisticItemList | API 서비스명 |
13
+ | 인증키 | Y | sample | 한국은행에서 발급받은 오픈API 인증키 |
14
+ | 요청유형 | Y | xml | 결과값의 파일 형식 - xml, json |
15
+ | 언어구분 | Y | kr | 결과값의 언어 - kr(국문), en(영문) |
16
+ | 요청시작건수 | Y | 1 | 전체 결과값 중 시작 번호 |
17
+ | 요청종료건수 | Y | 10 | 전체 결과값 중 끝 번호 |
18
+ | 통계표코드 | Y | 601Y002 | 통계표코드 |
19
+
20
+ ---
21
+
22
+ ## 출력값
23
+
24
+ | 항목명(국문) | 항목명(영문) | 항목크기 | 샘플데이터 | 항목설명 |
25
+ | -------- | ----------- | ---- | ------------------------ | -------- |
26
+ | 통계표코드 | STAT_CODE | 8 | 601Y002 | 통계표코드 |
27
+ | 통계명 | STAT_NAME | 200 | 7.5.2. 지역별 소비유형별 개인 신용카드 | 통계명 |
28
+ | 항목그룹코드 | GRP_CODE | 20 | Group1 | 통계항목그룹코드 |
29
+ | 항목그룹명 | GRP_NAME | 60 | 지역코드 | 통계항목그룹명 |
30
+ | 통계항목코드 | ITEM_CODE | 20 | A | 통계항목코드 |
31
+ | 통계항목명 | ITEM_NAME | 200 | 서울 | 통계항목명 |
32
+ | 상위통계항목코드 | P_ITEM_CODE | 8 | null | 상위통계항목코드 |
33
+ | 상위통계항목명 | P_ITEM_NAME | 200 | null | 상위통계항목명 |
34
+ | 주기 | CYCLE | 2 | M | 주기(월) |
35
+ | 수록시작일자 | START_TIME | 8 | 200912 | 수록시작일자 |
36
+ | 수록종료일자 | END_TIME | 8 | 202112 | 수록종료일자 |
37
+ | 자료수 | DATA_CNT | 22 | 145 | 자료수 |
38
+ | 단위 | UNIT_NAME | 200 | 십억원 | 단위 |
39
+ | 가중치 | WEIGHT | 22 | null | 가중치 |
40
+
41
+ ---
42
+
43
+ ## OpenAPI 테스트
44
+
45
+ * **테스트 URL**
46
+
47
+ ```
48
+ https://ecos.bok.or.kr/api/StatisticItemList/sample/xml/kr/1/10/043Y070/
49
+ ```
50
+ * `sample` 위치에 **인증키 값**을 입력
51
+
52
+ ---
53
+
54
+ ## OpenAPI 메세지
55
+
56
+ | 타입 | 코드 | 설명 |
57
+ | -- | --- | ---------------------------------------------------- |
58
+ | 정보 | 100 | 인증키가 유효하지 않습니다. 인증키를 확인하십시오! 인증키가 없는 경우 인증키를 신청하십시오! |
59
+ | 정보 | 200 | 해당하는 데이터가 없습니다. |
60
+ | 에러 | 100 | 필수 값이 누락되어 있습니다. 필수 값을 확인하십시오! |
61
+ | 에러 | 101 | 주기와 다른 형식의 날짜 형식입니다. |
62
+ | 에러 | 200 | 파일타입 값이 누락 혹은 유효하지 않습니다. |
63
+ | 에러 | 300 | 조회건수 값이 누락되어 있습니다. |
64
+ | 에러 | 301 | 조회건수 값의 타입이 유효하지 않습니다. 정수를 입력하세요. |
65
+ | 에러 | 400 | 검색범위가 적정범위를 초과하여 60초 TIMEOUT이 발생하였습니다. |
66
+ | 에러 | 500 | 서버 오류입니다. 해당 서비스를 찾을 수 없습니다. |
67
+ | 에러 | 600 | DB Connection 오류입니다. |
68
+ | 에러 | 601 | SQL 오류입니다. |
69
+ | 에러 | 602 | 과도한 OpenAPI 호출로 이용이 제한되었습니다. |
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025
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.
@@ -0,0 +1,286 @@
1
+ Metadata-Version: 2.4
2
+ Name: ecos-reader
3
+ Version: 0.1.0
4
+ Summary: 한국은행 ECOS Open API Python 클라이언트
5
+ Project-URL: Homepage, https://github.com/yeonguk/ecos-reader
6
+ Project-URL: Documentation, https://github.com/yeonguk/ecos-reader#readme
7
+ Project-URL: Repository, https://github.com/yeonguk/ecos-reader
8
+ Project-URL: Issues, https://github.com/yeonguk/ecos-reader/issues
9
+ Author: yeonguk
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: api,bok,economy,ecos,finance,korea,macro
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Financial and Insurance Industry
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Office/Business :: Financial
24
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.10
27
+ Requires-Dist: pandas>=2.0.0
28
+ Requires-Dist: python-dotenv>=1.0.0
29
+ Requires-Dist: requests>=2.28.0
30
+ Provides-Extra: dev
31
+ Requires-Dist: mypy>=1.0.0; extra == 'dev'
32
+ Requires-Dist: pre-commit>=3.0.0; extra == 'dev'
33
+ Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
34
+ Requires-Dist: pytest>=7.0.0; extra == 'dev'
35
+ Requires-Dist: responses>=0.23.0; extra == 'dev'
36
+ Requires-Dist: ruff>=0.1.0; extra == 'dev'
37
+ Description-Content-Type: text/markdown
38
+
39
+ # ecos-reader
40
+ **한국은행 ECOS Open API Python 클라이언트**
41
+
42
+ 한국은행 ECOS Open API를 Python에서 쉽고 일관된 방식으로 사용할 수 있는 라이브러리입니다.
43
+
44
+
45
+ ## 설치
46
+
47
+ ```bash
48
+ pip install ecos-reader
49
+ ```
50
+
51
+ 또는 개발 버전 설치:
52
+
53
+ ```bash
54
+ git clone https://github.com/choo121600/ecos-reader.git
55
+ cd ecos-reader
56
+ pip install -e ".[dev]"
57
+ ```
58
+
59
+ ## API 키 설정
60
+
61
+ ECOS API를 사용하려면 한국은행에서 발급받은 API 키가 필요합니다.
62
+
63
+ [API 키 신청하기](https://ecos.bok.or.kr/api/)
64
+
65
+ ### 방법 1: 환경 변수 (권장)
66
+
67
+ ```bash
68
+ export ECOS_API_KEY="your_api_key"
69
+ ```
70
+
71
+ 또는 `.env` 파일 생성:
72
+
73
+ ```
74
+ ECOS_API_KEY=your_api_key
75
+ ```
76
+
77
+ > 참고: v0.1.0부터는 라이브러리 import 시점에 `.env`를 자동으로 로드하지 않습니다.
78
+ > `.env`를 사용하려면 아래처럼 `ecos.load_env()`를 한 번 호출하세요.
79
+
80
+ ```python
81
+ import ecos
82
+
83
+ ecos.load_env() # .env 로드 (명시적)
84
+ ```
85
+
86
+ ### 방법 2: 코드에서 직접 설정
87
+
88
+ ```python
89
+ import ecos
90
+
91
+ ecos.set_api_key("your_api_key")
92
+ ```
93
+
94
+ ## 빠른 시작
95
+
96
+ ```python
97
+ import ecos
98
+
99
+ # 한국은행 기준금리 조회
100
+ df = ecos.get_base_rate()
101
+ print(df)
102
+ # date value unit
103
+ # 0 2024-01-01 3.50 %
104
+ # 1 2024-02-01 3.50 %
105
+ # ...
106
+
107
+ # 소비자물가지수(CPI) 조회
108
+ df = ecos.get_cpi(start_date="202301", end_date="202312")
109
+ print(df)
110
+
111
+ # 국고채 수익률 조회
112
+ df = ecos.get_treasury_yield(maturity="10Y")
113
+ print(df)
114
+
115
+ # GDP 조회
116
+ df = ecos.get_gdp(frequency="Q", basis="real")
117
+ print(df)
118
+ ```
119
+
120
+ ## 지원 지표
121
+
122
+ ### 금리 지표
123
+
124
+ | 함수 | 설명 |
125
+ |-----|------|
126
+ | `get_base_rate()` | 한국은행 기준금리 |
127
+ | `get_treasury_yield(maturity)` | 국고채 수익률 (1Y, 3Y, 5Y, 10Y, 20Y, 30Y) |
128
+ | `get_yield_spread()` | 장단기 금리차 |
129
+
130
+ ### 물가 지표
131
+
132
+ | 함수 | 설명 |
133
+ |-----|------|
134
+ | `get_cpi()` | 소비자물가지수 전년동월비 |
135
+ | `get_core_cpi()` | 근원 CPI (식료품·에너지 제외) |
136
+ | `get_ppi()` | 생산자물가지수 전년동월비 |
137
+
138
+ ### 성장 지표
139
+
140
+ | 함수 | 설명 |
141
+ |-----|------|
142
+ | `get_gdp(frequency, basis)` | GDP (분기/연간, 실질/명목) |
143
+ | `get_gdp_deflator()` | GDP 디플레이터 |
144
+
145
+ ### 통화 지표
146
+
147
+ | 함수 | 설명 |
148
+ |-----|------|
149
+ | `get_money_supply(indicator)` | 통화량 (M1, M2, Lf) |
150
+ | `get_bank_lending(sector)` | 은행 대출 (가계/기업/전체) |
151
+
152
+ ## 상세 사용법
153
+
154
+ ### 기간 지정
155
+
156
+ ```python
157
+ # 월간 데이터 (YYYYMM 형식)
158
+ df = ecos.get_base_rate(start_date="202001", end_date="202312")
159
+
160
+ # 일간 데이터 (YYYYMMDD 형식)
161
+ df = ecos.get_treasury_yield(maturity="3Y", start_date="20240101", end_date="20241231")
162
+
163
+ # 분기 데이터 (YYYYQN 형식)
164
+ df = ecos.get_gdp(frequency="Q", start_date="2020Q1", end_date="2024Q4")
165
+
166
+ # 연간 데이터 (YYYY 형식)
167
+ df = ecos.get_gdp(frequency="A", start_date="2015", end_date="2024")
168
+ ```
169
+
170
+ ### 캐시 관리
171
+
172
+ ```python
173
+ import ecos
174
+
175
+ # 캐시 비활성화
176
+ ecos.disable_cache()
177
+
178
+ # 캐시 활성화
179
+ ecos.enable_cache()
180
+
181
+ # 캐시 초기화
182
+ ecos.clear_cache()
183
+ ```
184
+
185
+ ### 에러 처리
186
+
187
+ ```python
188
+ import ecos
189
+ from ecos import EcosAPIError, EcosConfigError, EcosNetworkError
190
+
191
+ try:
192
+ df = ecos.get_base_rate()
193
+ except EcosConfigError as e:
194
+ print(f"API 키 설정 오류: {e}")
195
+ except EcosNetworkError as e:
196
+ print(f"네트워크 오류: {e}")
197
+ except EcosAPIError as e:
198
+ print(f"API 오류 [{e.code}]: {e.message}")
199
+ ```
200
+
201
+ ### 로깅 활성화(선택)
202
+
203
+ 라이브러리는 import 시점에 로깅 핸들러를 자동으로 구성하지 않습니다. 필요 시 아래처럼 활성화하세요.
204
+
205
+ ```python
206
+ import logging
207
+ import ecos
208
+
209
+ ecos.setup_logging(logging.INFO)
210
+ ```
211
+
212
+ ### 직접 클라이언트 사용
213
+
214
+ ```python
215
+ from ecos import EcosClient
216
+
217
+ # 클라이언트 생성
218
+ client = EcosClient(
219
+ api_key="your_api_key",
220
+ timeout=60,
221
+ max_retries=5,
222
+ use_cache=True,
223
+ )
224
+
225
+ # 통계 조회
226
+ response = client.get_statistic_search(
227
+ stat_code="722Y001",
228
+ period="M",
229
+ start_date="202401",
230
+ end_date="202412",
231
+ item_code1="0101000",
232
+ )
233
+ ```
234
+
235
+ ### 전역 기본 클라이언트 주입(선택)
236
+
237
+ indicator 함수들이 사용할 “기본 클라이언트”를 교체하고 싶다면 아래처럼 설정할 수 있습니다.
238
+
239
+ ```python
240
+ import ecos
241
+ from ecos import EcosClient
242
+
243
+ custom = EcosClient(timeout=60, max_retries=5, use_cache=True)
244
+ ecos.set_client(custom)
245
+
246
+ df = ecos.get_cpi() # custom 클라이언트 사용
247
+ ```
248
+
249
+ ## 테스트
250
+
251
+ ```bash
252
+ # 테스트 실행
253
+ pytest
254
+
255
+ # 커버리지 포함
256
+ pytest --cov=src/ecos
257
+
258
+ # 특정 테스트만 실행
259
+ pytest tests/test_config.py -v
260
+ ```
261
+
262
+ ## 프로젝트 구조
263
+
264
+ ```
265
+ ecos-reader/
266
+ ├── src/ecos/
267
+ │ ├── __init__.py # Public API
268
+ │ ├── client.py # API 클라이언트
269
+ │ ├── config.py # 설정 관리
270
+ │ ├── cache.py # 캐시 레이어
271
+ │ ├── parser.py # 응답 파서
272
+ │ ├── exceptions.py # 예외 클래스
273
+ │ ├── constants.py # 상수 정의
274
+ │ └── indicators/ # 지표 모듈
275
+ │ ├── interest_rate.py # 금리
276
+ │ ├── prices.py # 물가
277
+ │ ├── growth.py # 성장
278
+ │ └── money.py # 통화
279
+ ├── tests/ # 테스트 코드
280
+ ├── examples/ # 예제 코드
281
+ ├── pyproject.toml
282
+ └── README.md
283
+ ```
284
+
285
+ # 라이센스
286
+ MIT License - 자세한 내용은 [LICENSE](LICENSE) 파일을 참조하세요.