> ## Documentation Index
> Fetch the complete documentation index at: https://docs.landing.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Parse a Directory of Documents

export const companyName = 'LandingAI';

export const extract = 'ADE Extract';

export const parse = 'ADE Parse';

export const ade = 'Agentic Document Extraction';

## Overview

Parse all documents in a folder by iterating through files and calling the parse API for each supported file type.

<Info>
  These examples require the [Python](./ade-python) or [TypeScript](./ade-typescript) client library. Before running a script, set your API key and install the library and any required dependencies.
</Info>

## Scripts

<CodeGroup>
  ```python Python [expandable] theme={null}
  from pathlib import Path
  from landingai_ade import LandingAIADE

  # Initialize client (uses the API key from the VISION_AGENT_API_KEY environment variable)
  client = LandingAIADE()

  # Replace "data/" with your folder path
  data_folder = Path("data/")

  for filepath in data_folder.glob("*"):
      # Adjust file types as needed for your use case
      if filepath.suffix.lower() in ['.pdf', '.png', '.jpg', '.jpeg']:
          print(f"Processing: {filepath.name}")

          response = client.parse(
              document=filepath,
              model="dpt-2-latest"
          )
          print(response.chunks)

          # Save markdown output (useful if you plan to run extract on the markdown)
          output_md = filepath.stem + ".md"
          with open(output_md, "w", encoding="utf-8") as f:
              f.write(response.markdown)
  ```

  ```typescript TypeScript [expandable] theme={null}
  import LandingAIADE from "landingai-ade";
  import fs from "fs";
  import path from "path";

  // Initialize client (uses the API key from the VISION_AGENT_API_KEY environment variable)
  const client = new LandingAIADE();

  // Replace with your folder path containing documents to parse
  const dataFolder = "data/";

  const files = fs.readdirSync(dataFolder);

  for (const filename of files) {
    const filepath = path.join(dataFolder, filename);
    const fileExt = path.extname(filepath).toLowerCase();

    // Adjust file types as needed for your use case
    if (['.pdf', '.png', '.jpg', '.jpeg'].includes(fileExt)) {
      console.log(`Processing: ${filename}`);

      const response = await client.parse({
        document: fs.createReadStream(filepath),
        model: "dpt-2-latest"
      });
      console.log(response.chunks);

      // Save Markdown output (useful if you plan to run extract on the Markdown)
      const outputMd = path.basename(filepath, fileExt) + ".md";
      fs.writeFileSync(outputMd, response.markdown, "utf-8");
    }
  }
  ```
</CodeGroup>
