-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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.
Open
Changes from 5 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
Some comments aren't visible on the classic Files Changed page.
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,188 @@ | ||
| # OpenBB e-Stat Provider | ||
|
|
||
| ## Overview | ||
|
|
||
| The e-Stat provider integrates Japan's official government statistical portal API into OpenBB, providing access to comprehensive economic, demographic, and social statistics from Japanese government ministries and agencies. | ||
|
|
||
| **Attribution Notice**: This service uses API functions from e-Stat, however its contents are not guaranteed by government. | ||
|
|
||
| ## What is e-Stat? | ||
|
|
||
| [e-Stat](https://www.e-stat.go.jp/en) is the official portal site of Japanese government statistics, operated by the Ministry of Internal Affairs and Communications. It provides access to statistical data from all Japanese government ministries and agencies in a centralized location. | ||
|
|
||
| ### Available Data Categories | ||
|
|
||
| The e-Stat API provides access to 28+ statistical databases including: | ||
|
|
||
| - **Population & Households**: Population Census, Vital Statistics, Population Estimates | ||
| - **Labor & Wages**: Labour Force Survey, Employment Status Survey, Basic Wage Structure | ||
| - **Economic Data**: Economic Census, Consumer Price Index, Retail Price Survey | ||
| - **Trade Statistics**: Import/Export data, Trade indices | ||
| - **Industry**: Industrial Production Index, Manufacturing data | ||
| - **Regional Data**: Prefecture and municipality-level statistics | ||
| - **Social Statistics**: Education, Health, Housing, and more | ||
|
|
||
| ## Quick Start (No Setup Required!) | ||
|
|
||
| The e-Stat provider works **out of the box** with OpenBB's shared Application ID. No registration needed for testing! | ||
|
|
||
| ```python | ||
| from openbb import obb | ||
|
|
||
| # Just start using it - no API key needed! | ||
| data = obb.economy.statistical_data( | ||
| provider="estat", | ||
| symbol="0003433219" # Population Census data | ||
| ) | ||
| ``` | ||
|
|
||
| **Note**: The default API key is provided for convenience but may be revoked if necessary. For production use, please register for your own free API key. | ||
|
|
||
| ## Setup Instructions (For Production Use) | ||
|
|
||
| While the provider includes a default API key for convenience, you may want your own for production use: | ||
|
|
||
| ### 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 Personal API Key | ||
|
|
||
| ```python | ||
| from openbb import obb | ||
|
|
||
| # Override the default with your personal API key | ||
| obb.account.credentials.estat_api_key = "your_application_id_here" | ||
| ``` | ||
|
|
||
| ## Usage Examples | ||
|
|
||
| ### Basic Statistical Data Query | ||
|
|
||
| ```python | ||
| # Get Japanese population census data | ||
| data = obb.economy.statistical_data( | ||
| provider="estat", | ||
| symbol="0003433219", # Population Census dataset ID | ||
| ) | ||
|
|
||
| # Get data with specific parameters | ||
| data = obb.economy.statistical_data( | ||
| provider="estat", | ||
| symbol="0003433219", | ||
| area_code="13000", # Tokyo | ||
| start_date="2020-01", | ||
| end_date="2023-12" | ||
| ) | ||
| ``` | ||
|
|
||
| ### Query Parameters | ||
|
|
||
| - `symbol` / `stats_data_id`: Statistical dataset ID (required) | ||
| - `stats_code`: Statistical survey code (e.g., "00200521" for Population Census) | ||
| - `area_code`: Area code for specific regions | ||
| - `category_code`: Category filter | ||
| - `search_kind`: "1" for standard statistics, "2" for regional mesh statistics | ||
| - `collect_area`: Collection area for aggregated data | ||
| - `start_date` / `end_date`: Date range for time series data | ||
|
|
||
| ### Finding Dataset IDs | ||
|
|
||
| To find specific dataset IDs: | ||
| 1. Browse available databases: https://www.e-stat.go.jp/en/stat-search/database | ||
| 2. Use the API's `getStatsList` endpoint to search programmatically | ||
| 3. Common dataset examples: | ||
| - Population Census: Various IDs starting with "0003..." | ||
| - Consumer Price Index: IDs vary by category | ||
| - Labour Force Survey: Check current catalog | ||
|
|
||
| ## API Documentation | ||
|
|
||
| - **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 | ||
| - **Data Overview**: https://www.e-stat.go.jp/api/api/index.php/en/api-info/api-data | ||
| - **Database Search**: https://www.e-stat.go.jp/en/stat-search/database | ||
|
|
||
| ### Technical Details | ||
|
|
||
| - **Base URL**: `https://api.e-stat.go.jp/rest/3.0/app/` | ||
| - **Formats**: JSON (default), XML, CSV | ||
| - **Language**: English supported with `lang=E` parameter | ||
| - **Rate Limits**: Not explicitly documented, use responsibly | ||
| - **HTTPS**: Supported | ||
| - **Compression**: gzip supported | ||
|
|
||
| ## Development | ||
|
|
||
| ### Running Tests | ||
|
|
||
| ```bash | ||
| cd openbb_platform/providers/estat | ||
| poetry install | ||
| poetry run pytest tests/ | ||
| ``` | ||
|
|
||
| ### Test Coverage | ||
|
|
||
| The test suite includes: | ||
| - Parameter validation | ||
| - Data transformation | ||
| - Error handling (authentication, data not found, server errors) | ||
| - Helper function tests | ||
| - Edge case handling | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Common Issues | ||
|
|
||
| 1. **"Invalid Application ID" Error** | ||
| - Verify your API key is correct | ||
| - Ensure you're using the Application ID from the API functions page | ||
|
|
||
| 2. **"Statistical data not found" Error** | ||
| - Check the dataset ID is valid | ||
| - Some datasets may require specific parameter combinations | ||
|
|
||
| 3. **Japanese Text in Responses** | ||
| - The provider sets `lang=E` for English | ||
| - Some metadata may still contain Japanese text | ||
| - Use browser translation tools when browsing the e-Stat website | ||
|
|
||
| ### Support | ||
|
|
||
| - e-Stat Support (Japanese): https://www.e-stat.go.jp/contact | ||
| - OpenBB Issues: https://github.com/OpenBB-finance/OpenBB/issues | ||
|
|
||
| ## 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 | ||
|
|
||
| ## Contributing | ||
|
|
||
| Contributions are welcome! Areas for improvement: | ||
| - Additional data fetchers for specific statistical categories | ||
| - Support for CSV/XML response formats | ||
| - Caching for frequently accessed metadata | ||
| - Enhanced date parsing for various Japanese fiscal periods | ||
|
|
||
| Please ensure all contributions maintain the attribution notice and comply with e-Stat's terms of use. | ||
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=["estat_api_key"], | ||
deeleeramone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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.
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.