dart-fss

repository·master·Indexed 18 days ago

https://github.com/josw123/dart-fss

A Python library for web-scraping the DART (Data Analysis, Retrieval and Transfer System) website operated by the South Korean Financial Supervisory Service. It provides a wrapper around the Open DART API to retrieve corporate lists, search for regulatory filings, and extract financial statements (Balance Sheet, Income Statement, Comprehensive Income Statement, and Cash Flow Statement) into Excel files or XBRL data.

Tokens
7.1K
Snippets
27
Records
37
Agent score
63%

What's inside dart-fss

  1. Explore Open DART API modules in dart-fss

    master

    The dart-fss library provides a wrapper around the Open DART API, organized into several specialized modules based on the type of information you need to retrieve:

    • Filing Information (dart_fss.api.filings): Access public disclosure information.
    • Business Report Key Information (dart_fss.api.info): Retrieve key details from business reports.
    • Listed Company Financial Information (dart_fss.api.finance): Access financial statements and data for listed companies.
    • Shareholder Disclosure Information (dart_fss.api.shareholder): Retrieve comprehensive information regarding shareholder disclosures.
  2. Extract XBRL data from reports

    master

    You can extract and analyze XBRL data from financial reports using the DartXbrl class. Once a report is selected, its .xbrl attribute provides access to XBRL-specific methods for retrieving financial statements and audit information.

    import dart_fss as dart
    
    # Assuming 'report' is a selected filing object
    xbrl = report.xbrl
    
    # Check if consolidated financial statements exist
    exists = xbrl.exist_consolidated()
    
    # Get audit information as a Pandas DataFrame
    audit_df = xbrl.get_audit_information(lang='en')
    
    # Extract cash flow statements
    cf_list = xbrl.get_cash_flows()
    # Access the first cash flow statement in the list
    cf = cf_list[0]
    
    # Convert to Pandas DataFrame
    df = cf.to_DataFrame()
    # Convert to Pandas DataFrame excluding classification info
    df_wo_class = cf.to_DataFrame(show_class=False)
  3. Configure DART-FSS request settings

    master

    You can manage request-related configurations through the dart_fss.utils.request module, which uses a Singleton class. This allows you to control the delay between requests, set up proxies, and modify the User-Agent used for API calls.

    import dart_fss as dart
    
    # Set request delay to 0.7 seconds
    dart.utils.request.set_delay(0.7)
    
    # Configure proxies
    proxies = {'http': 'http://xxxxxxxxx.xxx', 'https': 'https://xxxxxxxxx.xxx'}
    dart.utils.request.set_proxies(proxies)
    
    # Force update the User-Agent
    dart.utils.request.update_user_agent(force=True)
  4. Configure the Open DART API Key

    master

    To use the library, you must obtain an API key from Open DART. You can configure the key in two ways:

    1. Set the DART_API_KEY environment variable.
    2. Use the dart.set_api_key() method within your Python script before performing other operations.
    import dart_fss as dart
    
    api_key = 'YOUR_API_KEY_HERE'
    dart.set_api_key(api_key=api_key)
  5. Quick Start: Extract financial statements for a company

    master

    This workflow demonstrates how to load the company list, find a specific company by name, extract annual consolidated financial statements starting from a specific date, and save the results to an Excel file.

    import dart_fss as dart
    
    # 1. Set API Key
    api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    dart.set_api_key(api_key=api_key)
    
    # 2. Load company list from DART
    corp_list = dart.get_corp_list()
    
    # 3. Search for a company (e.g., Samsung Electronics)
    samsung = corp_list.find_by_corp_name('삼성전자', exactly=True)[0]
    
    # 4. Extract annual consolidated financial statements from 2012 onwards
    fs = samsung.extract_fs(bgn_de='20120101')
    
    # 5. Save results to Excel (default location: ./fsdata)
    fs.save()
  6. Troubleshoot common dart-fss errors

    master

    When working with dart-fss, you may encounter several specific error classes related to API authentication, rate limiting, and data availability. Handling these exceptions allows you to build more resilient data extraction pipelines.

    Error Categories

    • Authentication Errors: APIKeyError is raised when there is an issue with your Open DART API key.
    • Rate Limiting & Access Errors:
      • OverQueryLimit: Raised when you have exceeded the allowed number of API requests.
      • TemporaryLocked: Raised when access is temporarily restricted.
    • Data Availability Errors:
      • NoDataReceived: Raised when the API call completes but returns no data.
      • NotFoundConsolidated: Specifically raised when requested consolidated financial statements cannot be found.
      • ServiceClose: Raised if the underlying DART service is unavailable or closed.
    • Request & System Errors:
      • InvalidField: Raised when an invalid field name is provided in a request.
      • UnknownError: A generic error for unexpected issues.
  7. API Rate Limiting Precautions

    master
    When using Open DART and the DART website, be aware that making more than 1,000 requests per minute may result in service restrictions. Check the official Open DART FAQ for detailed usage limits.
  8. Extract XBRL data using a complete workflow

    master

    This example demonstrates the full workflow: loading the corporation list, finding a specific company by its corp_code, searching for annual reports (pblntf_detail_ty='a001'), selecting a report, and extracting its XBRL data into a Pandas DataFrame.

    import dart_fss as dart
    
    # 1. Load all listed companies
    corp_list = dart.get_corp_list()
    
    # 2. Find a specific company (e.g., Samsung Electronics) by corp_code
    corp_code = '00126380'
    samsung = corp_list.find_by_corp_code(corp_code=corp_code)
    
    # 3. Search for filings (e.g., annual reports since 2019)
    reports = samsung.search_filings(bgn_de='20190101', pblntf_detail_ty='a001')
    
    # 4. Select the first report and access its XBRL data
    report = reports[0]
    xbrl = report.xbrl
    
    # 5. Check for consolidated statements and extract cash flows
    if xbrl.exist_consolidated():
        cf = xbrl.get_cash_flows()[0]
        df = cf.to_DataFrame()
        print(df)