-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add e-Stat provider for Japan government statistical data #7215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
YenAle-FT-Gmail
wants to merge
15
commits into
OpenBB-finance:develop
Choose a base branch
from
YenAle-FT-Gmail:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,450
−0
Open
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
e35d652
feat: Add e-Stat provider for Japanese government statistical data
YenAle-FT-Gmail 6bf0102
config setup for local testing
YenAle-FT-Gmail 492f4e0
feat: Add e-Stat provider for Japanese government statistical data
YenAle-FT-Gmail 9190952
Delete test_estat_integration.py
YenAle-FT-Gmail 897fa9c
Merge branch 'develop' into develop
deeleeramone 82ce642
Merge branch 'develop' into develop
deeleeramone e18de90
fix: Correct e-Stat provider credential handling
YenAle-FT-Gmail 407c123
docs: Improve README and remove broken data_format parameter
YenAle-FT-Gmail 4f8c79b
Merge branch 'OpenBB-finance:develop' into develop
YenAle-FT-Gmail 05b0daf
Merge branch 'develop' into develop
deeleeramone 50ae29e
implement search
YenAle-FT-Gmail 3836bfc
Merge branch 'develop' into develop
deeleeramone 9776727
Merge branch 'develop' into develop
deeleeramone 1fa9b28
Merge branch 'develop' into develop
deeleeramone a33bc8d
Merge branch 'develop' into develop
deeleeramone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| # OpenBB e-Stat Provider | ||
|
|
||
| ## Overview | ||
|
|
||
| The e-Stat provider integrates Japan's official government statistical portal API into OpenBB. [e-Stat](https://www.e-stat.go.jp/en) is operated by the Ministry of Internal Affairs and Communications and provides access to 28+ statistical databases including population census, labor surveys, economic indicators, trade statistics, and regional data. | ||
|
|
||
| **Attribution Notice**: This service uses API functions from e-Stat, however its contents are not guaranteed by government. | ||
|
|
||
| ## Setup Instructions | ||
|
|
||
| ### Step 1: Register for e-Stat Account | ||
|
|
||
| 1. Visit: https://www.e-stat.go.jp/en/mypage/user/preregister | ||
| 2. Complete registration with your email | ||
| 3. Confirm your email and log in | ||
|
|
||
| ### Step 2: Get Your Application ID (API Key) | ||
|
|
||
| 1. After logging in, go to "My Page" (top right corner) | ||
| 2. Click on "API functions" section | ||
| 3. Fill in the simple form: | ||
| - **Name**: Your app name | ||
| - **URL**: Your URL (use `http://test.localhost/` if not public) | ||
| - **Overview**: Brief description (optional) | ||
| 4. Click "Issue" button | ||
| 5. Your Application ID will be displayed immediately | ||
|
|
||
|  | ||
| *Example of the API functions dashboard showing Application IDs* | ||
|
|
||
| ### Step 3: Configure Your API Key | ||
|
|
||
| ```python | ||
| from openbb import obb | ||
|
|
||
| # Set your API key (required) | ||
| obb.account.credentials.estat_api_key = "your_application_id_here" | ||
| ``` | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ```python | ||
| # Get Japanese population census data | ||
| data = obb.economy.statistical_data( | ||
| provider="estat", | ||
| symbol="0003433219", # Population Census dataset ID | ||
| ) | ||
|
|
||
| # Get data with filters | ||
| data = obb.economy.statistical_data( | ||
| provider="estat", | ||
| symbol="0003433219", | ||
| area_code="13000", # Tokyo Prefecture | ||
| start_date="2020-01", | ||
| end_date="2020-12" | ||
| ) | ||
| ``` | ||
|
|
||
| ## Finding Your Data | ||
|
|
||
| ### Understanding the Data Structure | ||
|
|
||
| Think of e-Stat as Japan's official government data library. To use it effectively, understand these key concepts: | ||
|
|
||
| **Dataset IDs** (like `0003433219`): Unique identifiers for each data collection. You'll find these on the e-Stat website when browsing datasets. | ||
|
|
||
| **Area Codes**: Geographic filters | ||
| - `00000` = All of Japan (national data) | ||
| - `13000` = Tokyo Prefecture | ||
| - `27000` = Osaka Prefecture | ||
| - City codes are longer (e.g., `13101` for Chiyoda-ku, Tokyo) | ||
|
|
||
| **Stats Codes**: Survey identifiers (e.g., `00200521` for Population Census) | ||
|
|
||
| **Category Codes**: Vary by dataset - check the specific dataset documentation for valid values | ||
|
|
||
| ### Three Ways to Find Dataset IDs | ||
|
|
||
| #### Method 1: Browse the Website (Easiest) | ||
|
|
||
| 1. Go to: https://www.e-stat.go.jp/en/stat-search/database | ||
| 2. Use categories like "Population and Households", "Labor and Wages", "Prices" | ||
| 3. Click on a dataset to view details | ||
| 4. The dataset ID appears in the URL and dataset information | ||
|
|
||
| #### Method 2: Search by Keywords | ||
|
|
||
| Use the search box on the e-Stat website with English terms like "population", "unemployment", "consumer price" | ||
|
|
||
| #### Method 3: API Discovery | ||
|
|
||
| ```python | ||
| import requests | ||
|
|
||
| # Search for datasets programmatically | ||
| url = "https://api.e-stat.go.jp/rest/3.0/app/json/getStatsList" | ||
| params = { | ||
| "appId": "your_api_key_here", | ||
| "lang": "E", | ||
| "searchWord": "population census", | ||
| "limit": 20 | ||
| } | ||
|
|
||
| response = requests.get(url, params=params) | ||
| data = response.json() | ||
| # Dataset IDs will be in the response | ||
| ``` | ||
|
|
||
| ### Common Datasets | ||
|
|
||
| **Population Census**: `0003433219` and similar IDs | ||
| - Complete population count every 5 years | ||
| - Includes demographics by prefecture/city | ||
|
|
||
| **Consumer Price Index**: Various IDs in the `0003` series | ||
| - Monthly inflation data | ||
| - Price changes by category | ||
|
|
||
| **Labor Force Survey**: Multiple IDs in the `0003` series | ||
| - Monthly employment statistics | ||
| - Unemployment rates | ||
|
|
||
| Note: Dataset IDs can change when surveys are updated. Always verify current IDs on the e-Stat website. | ||
|
|
||
| ## Parameters | ||
|
|
||
| - `symbol`: Statistical dataset ID (required) - the unique identifier from e-Stat | ||
| - `stats_code`: Survey code like `00200521` for specific surveys | ||
| - `area_code`: Geographic filter (see area codes above) | ||
| - `category_code`: Dataset-specific category filters | ||
| - `search_kind`: "1" for standard statistics, "2" for regional mesh statistics | ||
| - `collect_area`: Collection area for aggregated data | ||
| - `start_date` / `end_date`: Date range in YYYY-MM format | ||
|
|
||
| **Note**: This provider currently only supports JSON format responses. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| **"Invalid Application ID" Error** | ||
| - Verify your API key from the e-Stat API functions page | ||
| - Ensure you've set `obb.account.credentials.estat_api_key` | ||
|
|
||
| **"Statistical data not found" Error** | ||
| - Check the dataset ID is current (IDs can change) | ||
| - Not all parameters work with all datasets | ||
| - Try removing optional parameters | ||
|
|
||
| **Japanese Text in Responses** | ||
| - Normal for some metadata despite `lang=E` parameter | ||
| - Numerical data is universal | ||
|
|
||
| **Empty Data** | ||
| - Some datasets update infrequently (annually or every 5 years) | ||
| - Check the e-Stat website for update schedules | ||
|
|
||
| ## API Reference | ||
|
|
||
| - **API Guide**: https://www.e-stat.go.jp/api/api/index.php/en/api-info/api-guide | ||
| - **API Specification**: https://www.e-stat.go.jp/api/api/index.php/en/api-info/api-spec | ||
| - **Database Search**: https://www.e-stat.go.jp/en/stat-search/database | ||
|
|
||
| ## Development | ||
|
|
||
| ### Running Tests | ||
|
|
||
| ```bash | ||
| cd openbb_platform/providers/estat | ||
| poetry install | ||
| poetry run pytest tests/ | ||
| ``` | ||
|
|
||
| ### Contributing | ||
|
|
||
| Contributions are welcome! Areas for improvement: | ||
| - Additional data fetchers for specific statistical categories | ||
| - Enhanced date parsing for Japanese fiscal periods | ||
| - Caching for frequently accessed metadata | ||
|
|
||
| Please ensure all contributions maintain the attribution notice and comply with e-Stat's terms of use. | ||
|
|
||
| ## License & Attribution | ||
|
|
||
| When using this provider, you must acknowledge: | ||
|
|
||
| > This service uses API functions from e-Stat, however its contents are not guaranteed by government. | ||
|
|
||
| This attribution is required by e-Stat's terms of use: https://www.e-stat.go.jp/api/api/index.php/en/api-info/credit | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| """e-Stat Provider Module. | ||
|
|
||
| ATTRIBUTION: This service uses API functions from e-Stat, | ||
| however its contents are not guaranteed by government. | ||
| """ | ||
|
|
||
| from openbb_core.provider.abstract.provider import Provider | ||
|
|
||
| from openbb_estat.models.statistical_data import EstatStatisticalDataFetcher | ||
|
|
||
| estat_provider = Provider( | ||
| name="estat", | ||
| website="https://www.e-stat.go.jp/api/", | ||
| description="The e-Stat API provides access to Japanese government statistical data" | ||
| + " from various ministries and agencies including economic, demographic, and social statistics." | ||
| + " Attribution: This service uses API functions from e-Stat, however its contents are not guaranteed by government.", | ||
| credentials=["api_key"], | ||
| fetcher_dict={ | ||
| "EstatStatisticalData": EstatStatisticalDataFetcher, | ||
| }, | ||
| repr_name="e-Stat Japan Statistical Data API", | ||
| instructions="Register for a free API key at: https://www.e-stat.go.jp/api/", | ||
| ) |
1 change: 1 addition & 0 deletions
1
openbb_platform/providers/estat/openbb_estat/models/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| """e-Stat Models.""" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.