Overview
Parse all documents in a folder by iterating through files and calling the parse API for each supported file type.These examples require the Python or TypeScript client library. Before running a script, set your API key and install the library and any required dependencies.
Scripts
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)
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");
}
}