Implementation:Run llama Llama index Download Module
| Knowledge Sources | |
|---|---|
| Domains | Download, Module |
| Last Updated | 2026-02-11 19:00 GMT |
Overview
Provides the core functionality for downloading LlamaHub modules (loaders, tools, packs, and agents) from the remote repository, installing their dependencies, and dynamically loading them into memory.
Description
The download/module.py module is the primary mechanism for fetching community-contributed modules from LlamaHub. It defines a MODULE_TYPE enum with four categories: LOADER, TOOL, LLAMAPACK, and DATASETS.
The download workflow consists of three key functions:
- get_module_info resolves a module class name to its module ID and list of extra files by consulting a library.json file. It first checks a local cache and falls back to fetching from the remote LlamaHub repository.
- download_module_and_reqs downloads the module's base Python file and any extra files from the remote repository. If an __init__.py extra file is found, it automatically updates the local package's exports. It then reads a requirements.txt file and installs any missing dependencies using pip via subprocess.
- download_llama_module is the primary entry point that orchestrates the full download flow: initializing a local directory, fetching module info, downloading files and installing requirements, and dynamically loading the module using importlib to return the requested class.
The module also provides track_download which sends an analytics event to the LlamaHub proxy server to track download counts for community modules.
The use_gpt_index_import parameter exists as a legacy compatibility flag for import rewriting, and skip_load allows downloading without loading the module into memory.
Usage
Use this module when you need to dynamically download and load community-contributed loaders, tools, or agent packs from the LlamaHub repository. It is the backend for the download_loader, download_tool, and similar convenience functions throughout the LlamaIndex framework.
Code Reference
Source Location
- Repository: Run_llama_Llama_index
- File: llama-index-core/llama_index/core/download/module.py
Signature
def download_llama_module(
module_class: str,
llama_hub_url: str = LLAMA_HUB_URL,
refresh_cache: bool = False,
custom_dir: Optional[str] = None,
custom_path: Optional[str] = None,
library_path: str = "library.json",
base_file_name: str = "base.py",
use_gpt_index_import: bool = False,
disable_library_cache: bool = False,
override_path: bool = False,
skip_load: bool = False,
) -> Any
Import
from llama_index.core.download.module import download_llama_module
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| module_class | str | Yes | The name of the LlamaHub module class to download (e.g., "GmailOpenAIAgentPack"). |
| llama_hub_url | str | No | Base URL for the LlamaHub remote repository. Defaults to the llama-hub main branch raw content URL. |
| refresh_cache | bool | No | If True, skips local cache and re-downloads from remote. Defaults to False. |
| custom_dir | Optional[str] | No | Custom directory name under the parent folder for downloads. |
| custom_path | Optional[str] | No | Custom absolute directory path for downloads. |
| library_path | str | No | Relative path to the library.json metadata file. Defaults to "library.json". |
| base_file_name | str | No | Name of the main Python file to download. Defaults to "base.py". |
| use_gpt_index_import | bool | No | Legacy flag for import rewriting compatibility. Defaults to False. |
| disable_library_cache | bool | No | If True, does not write library.json to local cache. Defaults to False. |
| override_path | bool | No | If True, writes files directly to the base directory instead of a module_id subdirectory. Defaults to False. |
| skip_load | bool | No | If True, downloads the module but does not load it into memory. Returns None. Defaults to False. |
Outputs
| Name | Type | Description |
|---|---|---|
| result | Any | The downloaded module class (e.g., a Loader, Pack, or Agent class), or None if skip_load is True. |
Usage Examples
from llama_index.core.download.module import download_llama_module
# Download and load a module from LlamaHub
WikipediaReader = download_llama_module(
module_class="WikipediaReader",
refresh_cache=False,
)
# Use the loaded module
reader = WikipediaReader()
documents = reader.load_data(pages=["Python (programming language)"])