The official Python library for the llama-cloud API
Project description
Llama Cloud Python SDK
The official Python SDK for LlamaParse - the enterprise platform for agentic OCR and document processing.
With this SDK, create powerful workflows across many features:
- Parse - Agentic OCR and parsing for 130+ formats
- Extract - Structured data extraction with custom schemas
- Classify - Document categorization with natural-language rules
- Agents - Deploy document agents as APIs
- Index - Document ingestion and embedding for RAG
Documentation
Installation
pip install llama_cloud
Quick Start
import os
from llama_cloud import LlamaCloud
client = LlamaCloud(
api_key=os.environ.get("LLAMA_CLOUD_API_KEY"), # This is the default and can be omitted
)
# Parse a document
job = client.parsing.create(
tier="agentic",
version="latest",
file_id="your-file-id",
)
print(job.id)
File Uploads
from pathlib import Path
from llama_cloud import LlamaCloud
client = LlamaCloud()
# Upload using a Path
client.files.create(
file=Path("/path/to/document.pdf"),
purpose="parse",
)
# Or using bytes with a tuple of (filename, contents, media_type)
client.files.create(
file=("document.txt", b"content", "text/plain"),
purpose="parse",
)
Async Usage
import asyncio
from llama_cloud import AsyncLlamaCloud
client = AsyncLlamaCloud()
async def main():
job = await client.parsing.create(
tier="agentic",
version="latest",
file_id="your-file-id",
)
print(job.id)
asyncio.run(main())
MCP Server
Use the Llama Cloud MCP Server to enable AI assistants to interact with the API:
Error Handling
When the API returns a non-success status code, an APIError subclass is raised:
import llama_cloud
from llama_cloud import LlamaCloud
client = LlamaCloud()
try:
client.pipelines.list(project_id="my-project-id")
except llama_cloud.APIError as e:
print(e.status_code) # 400
print(e.__class__.__name__) # BadRequestError
| Status Code | Error Type |
|---|---|
| 400 | BadRequestError |
| 401 | AuthenticationError |
| 403 | PermissionDeniedError |
| 404 | NotFoundError |
| 422 | UnprocessableEntityError |
| 429 | RateLimitError |
| >=500 | InternalServerError |
| N/A | APIConnectionError |
Retries and Timeouts
The SDK automatically retries requests 2 times on connection errors, timeouts, rate limits, and 5xx errors. Requests timeout after 1 minute by default. Functions that combine multiple API calls (e.g. client.parsing.parse()) will have larger timeouts by default to account for the multiple requests and polling.
client = LlamaCloud(
max_retries=0, # Disable retries (default: 2)
timeout=30.0, # 30 second timeout (default: 1 minute)
)
Pagination
List methods support auto-pagination with for loops:
for run in client.extraction.runs.list(
extraction_agent_id="agent-id",
limit=20,
):
print(run)
Or fetch one page at a time:
page = client.extraction.runs.list(extraction_agent_id="agent-id", limit=20)
for run in page.items:
print(run)
while page.has_next_page():
page = page.get_next_page()
Logging
Configure logging via the LLAMA_CLOUD_LOG environment variable or the log option:
client = LlamaCloud(
log="debug", # "debug" | "info" | "warn" | "error" | "off"
)
Requirements
- Python 3.9+
Contributing
See CONTRIBUTING.md.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llama_cloud-2.5.0.tar.gz.
File metadata
- Download URL: llama_cloud-2.5.0.tar.gz
- Upload date:
- Size: 3.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e26ce54436642427aa6f194265b48c52d00c2c9b76a07367458364d2df9d9d9
|
|
| MD5 |
c12a19b277cd5d000e0313518a652944
|
|
| BLAKE2b-256 |
9bb0b6ecd545bd0514fd056ab40269f03484c7fbf75e35e0117e56b0d7cf1659
|
File details
Details for the file llama_cloud-2.5.0-py3-none-any.whl.
File metadata
- Download URL: llama_cloud-2.5.0-py3-none-any.whl
- Upload date:
- Size: 419.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc9f924b62dcf9f13a91264053e1381fdad78106771610e69da25b1159440c47
|
|
| MD5 |
4431372c3947b5ec5612bf94fff67519
|
|
| BLAKE2b-256 |
70d2ef1c97ec4848ed5ae510f4460da89014d39d9408636a23832a9ec8d0e4e9
|