Llama Cloud Python SDK
The `llama-cloud` Python SDK is the official library for interacting with the Llama Cloud API, providing convenient access to services like LlamaParse for agentic OCR and document processing, structured data extraction, document classification, and RAG ingestion. The library offers both synchronous and asynchronous clients and is actively maintained with frequent releases, currently at version 2.3.0.
Warnings
- breaking The v2.0.0 release introduced significant breaking changes, including the removal of the v1 extraction resource and a restructure of metadata. If you were using `extraction` features prior to v2.0.0, your code will need updates.
- breaking The `llama-cloud-services` package is deprecated and will no longer be maintained after May 1, 2026. This older SDK has different import paths and API surface areas.
- gotcha Hardcoding API keys directly in your application code is a security risk. API keys are user and project-scoped.
- gotcha LlamaParse API v2 introduced structured configuration objects (`input_options`, `output_options`, `processing_options`) instead of a flat list of parameters from v1. Old parameter names or structures from v1 will not work with v2 endpoints.
Install
-
pip install llama-cloud
Imports
- LlamaCloud
from llama_cloud import LlamaCloud
- AsyncLlamaCloud
from llama_cloud import AsyncLlamaCloud
- APIError
from llama_cloud import APIError
Quickstart
import os
from llama_cloud import LlamaCloud
from pathlib import Path
# Ensure LLAMA_CLOUD_API_KEY is set in your environment variables
# e.g., os.environ['LLAMA_CLOUD_API_KEY'] = 'llx-...' or using a .env file
client = LlamaCloud(
api_key=os.environ.get('LLAMA_CLOUD_API_KEY', '')
)
# Example: Upload a dummy file and create a parsing job
# Replace with a real file path for actual usage
# file_path = Path("path/to/your/document.pdf")
# with open(file_path, "rb") as f:
# file_obj = client.files.create(
# file=(file_path.name, f.read(), "application/pdf"),
# purpose="parse",
# )
# For demonstration, simulate a file_id to create a parsing job
# In a real scenario, file_id would come from client.files.create() or an existing file.
dummy_file_id = "your-example-file-id" # Replace with actual file_id if uploading
if not dummy_file_id:
print("Please provide a valid file_id or upload a file first.")
else:
try:
job = client.parsing.create(
tier="agentic", # or "fast", "cost_effective"
version="latest",
file_id=dummy_file_id,
# For example, to get markdown output:
output_options={
"markdown": {
"tables": {
"output_tables_as_markdown": True
}
}
},
expand=["markdown"]
)
print(f"Created parsing job with ID: {job.id}")
# You would typically poll the job status and retrieve results here
# For example, using client.parsing.get_job_result(job.id)
except Exception as e:
print(f"An error occurred: {e}")