Skip to main content
You can quickly get started with by either using our Python library or calling the APIs directly. This article guides you through each approach. You can then customize these scripts to meet the needs of your use case.

Get Started with the Python Library

This tutorial walks you through how to parse a document then extract a subset of fields from it using the Python library.

1. Set the API Key as an Environment Variable

Get your API key and set it as an environment variable. For more details, go to API Key.
export VISION_AGENT_API_KEY=<your-api-key>

2. Install the landingai-ade Library

Install the library.
pip install landingai-ade

3. Parse a Document

Run the script below to parse this document: Bank Statement. The script saves the response to a Markdown file.
from landingai_ade import LandingAIADE

# Parse the document
response = LandingAIADE().parse(document_url="bank-statement.pdf")

# Print the results
print("Extracted Markdown:")
print(response.markdown)
print("Extracted Chunks:")
print(response.chunks)

# Save Markdown to a file
if response.markdown:
    with open('markdown-bank-statement.md', 'w', encoding='utf-8') as f:
        f.write(response.markdown)
    print("\nMarkdown content saved to a Markdown file.")
else:
    print("No 'markdown' field found in the response")

4. Extract Fields from a Document

Now that we have the parsed output in a Markdown file, let’s extract these fields: Account Holder Name and Number of Deposits. To do this, run the script below.
from landingai_ade import LandingAIADE
from landingai_ade.lib import pydantic_to_json_schema
from pydantic import BaseModel, Field
from pathlib import Path

# Define your schema: this tells the API what fields to extract
class Account(BaseModel):
    name: str = Field(description="Account holder name")
    number_deposits: int = Field(description="The number of deposits")

# Convert to JSON schema
schema = pydantic_to_json_schema(Account)

# Extract fields
response = LandingAIADE().extract(
    schema=schema,
    markdown=Path('markdown-bank-statement.md')
)

# Print the extracted fields
print(response.extraction)
The response returns the key-value pairs for the Account Holder Name and Number of Deposits.
{'name': 'Sarah J. Mitchell', 'number_deposits': 5}

Get Started with the API

You can call the APIs directly:

1. Get Your API Key

Get your API key. For more details, go to API Key.

2. Parse a Document

Run the code below to parse a document with the API. Replace YOUR_API_KEY with your API key, and replace document.pdf with the filepath to your document.
curl -X POST 'https://api.va.landing.ai/v1/ade/parse' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -F 'document=@document.pdf' \

3. Extract Fields from a Document

After parsing a document, save the markdown response to a Markdown file. Pass that Markdown file and the extraction schema to the API using the code below. Replace YOUR_API_KEY, the schema value, and markdown.md with your information.
curl -X POST 'https://api.va.landing.ai/v1/ade/extract' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -F 'schema=@{"type": "object", "properties": {"field1": {"type": "string"}, "field2": {"type": "string"}}, "required": ["field1", "field2"]}' \
  -F 'markdown=@markdown.md'
I