OpenDartReader

repository·master·Indexed 19 days ago

https://github.com/financedata/opendartreader

A Python library and CLI tool designed to simplify access to the South Korean Financial Supervisory Service's 'Open DART' API. It provides functionality to search for corporate disclosures, retrieve company profiles, download original disclosure documents, and extract financial statements, shareholder information, and business report items into pandas DataFrames. Version 0.3.2.

Tokens
15K
Snippets
69
Records
76
Agent score
67%

What's inside opendartreader

  1. Initialize the OpenDartReader client

    master

    In your Python code, you can initialize the client by passing the API key directly or by relying on the environment variables configured above.

    from opendartreader import OpenDartReader
    
    # Option 1: Explicit API key
    dart = OpenDartReader('your_api_key_here')
    
    # Option 2: Rely on DART_API_KEY environment variable
    dart = OpenDartReader()
    from opendartreader import OpenDartReader
    
    dart = OpenDartReader('your_api_key_here')
  2. Configure the DART_API_KEY

    master

    OpenDartReader requires an API key from the Open DART service. You can provide this key in two ways:

    1. Using a .env file: Create a .env file in your project root or home directory.
    2. Using an environment variable: Export the variable in your shell session.
    # Option 1: .env file
    DART_API_KEY="your_api_key_here"
    
    # Option 2: Environment variable
    export DART_API_KEY="your_api_key_here"
  3. Initialize OpenDartReader with an API Key

    master

    To use the library, you must create an OpenDartReader object. You can provide your API key directly during initialization, or set it as an environment variable named DART_API_KEY. Using an environment variable (e.g., in a .env file) is recommended.

    import OpenDartReader
    
    # Option 1: Specify API key directly
    api_key = 'YOUR_API_KEY'
    dart = OpenDartReader(api_key)
    
    # Option 2: Use environment variable DART_API_KEY (Recommended)
    # If DART_API_KEY is set in your environment, you can initialize without arguments
    dart = OpenDartReader()
    import OpenDartReader
    
    # Option 1: Specify API key directly
    api_key = 'YOUR_API_KEY'
    dart = OpenDartReader(api_key)
    
    # Option 2: Use environment variable DART_API_KEY (Recommended)
    dart = OpenDartReader()
  4. Configure the DART_API_KEY environment variable

    master

    OpenDartReader requires an API key from the Open DART service. The library automatically looks for an environment variable named DART_API_KEY or a .env file containing it.

    Unix/macOS:

    export DART_API_KEY="your_api_key_here"

    Windows (current session):

    set DART_API_KEY=your_api_key_here

    Using a .env file: Create a .env file in your project directory:

    DART_API_KEY="your_api_key_here"
    export DART_API_KEY="your_api_key_here"
  5. Download attachments from a disclosure report

    master

    You can retrieve and save files attached to a specific disclosure report.

    Workflow:

    1. Get the list of files using attach_files(rcp_no).
    2. Iterate through the dictionary and use download(url, fn) to save them.

    Methods:

    • attach_files(rcp_no): Returns a dict of {file_name: url}.
    • download(url, fn): Saves the file from url to the path fn.

    Example:

    rcp_no = '20220308000798'
    files = dart.attach_files(rcp_no)
    for title, url in files.items():
        dart.download(url, title)
    # Attach files and download them
    rcp_no = '20220308000798'
    files = dart.attach_files(rcp_no)
    for title, url in files.items():
        dart.download(url, title)
  6. Initialize OpenDartReader

    master

    To use the library, you must first create an OpenDartReader object using an API key. You can obtain an API key by registering on the Open DART authentication key application page. The key consists of 40 alphanumeric characters.

    import OpenDartReader
    
    api_key = 'YOUR_API_KEY'
    dart = OpenDartReader(api_key)
    import OpenDartReader
    
    api_key = 'd81e78ac719d1c1e4ec4558ef22a737ab6cbb4c8'
    dart = OpenDartReader(api_key)
  7. Configure the OpenDartReader CLI API Key

    master

    The OpenDartReader CLI requires a DART API Key to function. You can provide the key in two ways:

    1. Environment Variable: Set the DART_API_KEY environment variable in your shell. This is the recommended method for persistent use.
    2. CLI Flag: Pass the --api-key flag directly to the command.

    If no key is provided via either method, the CLI will exit with an error.

    # Using environment variable (recommended)
    export DART_API_KEY='your_api_key_here'
    python -m opendartreader.cli list SamsungElectronics
    
    # Using CLI flag
    python -m opendartreader.cli --api-key 'your_api_key_here' list SamsungElectronics
  8. Initialize OpenDartReader

    master

    To use the library, instantiate the OpenDartReader class. You must provide a DART API key either as a direct argument or by setting the DART_API_KEY environment variable. The class automatically manages a local cache directory named docs_cache to store corporate code data for performance.

    from opendartreader import OpenDartReader
    
    # Option 1: Pass API key directly
    dart = OpenDartReader(api_key='YOUR_API_KEY')
    
    # Option 2: Use environment variable DART_API_KEY
    # dart = OpenDartReader()