Data Models
Relevant source files
The following files were used as context for generating this wiki page:
The data models in abx-dl define the core abstractions for the ArchiveBox plugin ecosystem, enabling a structured and reproducible workflow for web archiving. These models facilitate plugin discovery, configuration management, execution tracking, and output generation. Built primarily using Pydantic, these models ensure type safety and easy serialization to JSONL (JSON Lines) format, which is the standard manifest format for abx-dl runs.
The architecture separates concerns into plugin definitions (hooks and configuration), runtime environment management, and execution results (snapshots, processes, and archive results). This structured approach allows the tool to run a wide variety of extractors—from simple text extractors to complex headless browser scripts—while maintaining a consistent metadata trail.
Sources: abx_dl/models.py:1-15, README.md:104-124
Core Plugin Architecture
The plugin system is the heart of abx-dl. It is composed of Plugin objects that contain metadata and a collection of Hook objects, which are the actual executable scripts performing the work.
Plugin and Hook Models
A Plugin is identified by its directory name and contains a PluginConfig (derived from config.json) and a list of Hook objects discovered within its directory. Hooks follow a specific naming convention to determine their execution order and event family.
The diagram above shows the relationship between a Plugin, its configuration, and its associated hooks.
Sources: abx_dl/models.py:44-114
Hook Naming Convention
Hooks are language-agnostic executables. Their behavior and scheduling are determined by their filenames:
on_{Event}__[{order}_]{description}[.finite][.daemon][.bg].{ext}
| Component | Description |
|---|---|
{Event} | The bus event family (e.g., Install, BinaryRequest, CrawlSetup, Snapshot). |
{order} | Optional execution order prefix (defaults to 0). |
.bg | Marks a hook as a background process. |
.finite / .daemon | Sub-types of background hooks indicating if they exit or run until killed. |
Sources: abx_dl/models.py:47-61, abx_dl/models.py:341-360
Configuration and Environment Models
Configuration in abx-dl is multi-layered, handling user settings, runtime-derived paths, and plugin-specific properties.
Configuration Layers
- GlobalConfig: Managed via
pydantic-settings, this handles core paths (DATA_DIR, CONFIG_DIR) and universal settings like TIMEOUT and USER_AGENT. - PluginEnv: A flat, assembled model used at runtime to populate the environment variables for hook subprocesses.
- Machine Records: Persisted in
config.env(user-provided) andderived.env(runtime-cached values like resolved binary paths).
Sources: abx_dl/config.py:46-105, abx_dl/models.py:117-210
Runtime Environment Assembly
Before a hook is executed, abx-dl assembles a PluginEnv. This involves merging global defaults with user overrides and remapping directories to be run-local.
This flow illustrates how different configuration sources are merged into a final environment for hook execution.
Sources: abx_dl/models.py:129-165, abx_dl/config.py:206-234
Execution and Result Models
Every run of abx-dl generates structured records that track the lifecycle of the archive process.
Result Objects
- Snapshot: Represents the URL being archived. One is created per
download()call. - Process: Records the details of a single subprocess execution (command, exit code, stdout/stderr).
- ArchiveResult: The specific output of a plugin hook, including status and produced files.
| Model | Key Fields | Description |
|---|---|---|
Snapshot | url, id, crawl_id | Metadata for the target being archived. |
Process | cmd, exit_code, machine_hostname | Low-level execution tracking of hooks. |
ArchiveResult | status, output_str, output_files | High-level plugin output and success status. |
OutputFile | path, size | Details of a file generated during archiving. |
Sources: abx_dl/models.py:213-317
Data Flow Sequence
The following sequence diagram shows the progression from a URL submission to the generation of result records.
This diagram demonstrates the lifecycle of an archive operation and the resulting data persistence.
Sources: abx_dl/cli.py:539-570, abx_dl/models.py:311-325, README.md:126-138
Binary Dependency Models
Plugins declare their needs through RequiredBinary definitions in their config.json. These are resolved at runtime into Binary objects (provided by the abx-pkg dependency).
RequiredBinary Structure
- name: The binary name (e.g., "wget", "chromium").
- binproviders: Priority list of providers (e.g., "env,apt,brew").
- overrides: Version or platform-specific adjustments.
Sources: abx_dl/models.py:82-90, abx_dl/cli.py:657-674
Summary
The abx-dl data models provide a robust framework for managing the complexity of diverse web archiving tools. By defining clear structures for Plugins, Hooks, and their ArchiveResults, the system ensures that every archive operation is transparent, configurable, and produces standardized metadata. The separation of config.env and derived.env allows for persistent user preferences while maintaining a high-performance cache for runtime-specific data like binary locations.
Sources: abx_dl/models.py, abx_dl/config.py