llama-index readers imap integration
Project description
LlamaIndex Readers Integration: IMAP
Overview
Simple IMAP reader allows loading emails from a given mailbox. It concatenates useful fields from each email into a single document used by LlamaIndex.
Installation
pip install llama-index-readers-imap
Usage
from llama_index.readers.imap import ImapReader
# Initialize the server
mailbox = ImapReader(
host="<MAIL HOST>",
username="<MAIL USERNAME>",
password="<MAIL PASSWORD>",
)
# Lazy load emails from the given mailbox
emails = mailbox.lazy_load_data(
folder="INBOX", # Customize the folder to read from
metadata_names=[
"uid",
"from_values",
], # Customize the metadata (date is always included). You can get the full list at https://pypi.org/project/imap-tools/#email-attributes
search_criteria=None, # By default all emails are read, customize the query following https://pypi.org/project/imap-tools/#search-criteria
save_attachment=None, # Callback function to save attachments
)
Saving attachments
The lazy_load_data function accepts an optional save_attachment callback function which, if defined, is called for every attachment in the email.
Its only parameter is an imap_tools.MailAttachment which is described in the official documentation. It must return the path of the saved attachment as a string. Every saved attachment will be added to the Document metadata with its saved filename and the original one.
Here's a simple example of the save_attachment function:
import imap_tools
def save_attachment(attachment: imap_tools.MailAttachment) -> str:
with open(f"attachments/custom_filename", "wb") as f:
f.write(attachment.payload)
return "attachments/custom_filename"
This loader is designed to be used as a way to load data into LlamaIndex.
Project details
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_index_readers_imap-0.2.3.tar.gz.
File metadata
- Download URL: llama_index_readers_imap-0.2.3.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
238895872cb2c5ce99798530e37af69900b6c1b96059243a7eb6344f14be2119
|
|
| MD5 |
61042ad958f2ff7d71516670b37a1e43
|
|
| BLAKE2b-256 |
ef23a742be95e64abce1edb8818d29a3a4c6cd3523032d5ac8f9713bdac0fb21
|
File details
Details for the file llama_index_readers_imap-0.2.3-py3-none-any.whl.
File metadata
- Download URL: llama_index_readers_imap-0.2.3-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1961b1c4f7bece935fdda9b6679c296153ea302495ab97311a07b1e54a20b6cc
|
|
| MD5 |
79f227a1711cf8032a1e3ac1fcf83058
|
|
| BLAKE2b-256 |
76e6dd88c78cd7bbd48cb6a429ec197f9572cd86220de536377f3a6baac3864a
|