Registry / http-networking / internetarchive

internetarchive

JSON →
library5.9.0pypypi✓ verified 84d ago

internetarchive is a Python interface to archive.org, providing both a command-line interface (CLI) and a Python API. It allows programmatic access to search, download, upload, and interact with various Internet Archive services. The library is actively maintained, with version 5.8.0 being the latest stable release, and new versions released periodically to add features, improve performance, and address bugs or security vulnerabilities.

pip install internetarchive
INSTALL
IMPORT
SIG · INTERNETARCHIVE
I
internetarchive
http-networkingpythonv5.9.0
Install
2.5s avg
Import
697ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.9.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
installs and imports cleanly · install 0.0s · import 0.735s · 23MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 2.5s · import 0.660s · 23MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_item
from internetarchive import get_item
search_items
from internetarchive import search_items
upload
from internetarchive import upload
download
from internetarchive import download
configure
from internetarchive import configure
import internetarchive.configure
The configure function is typically imported directly or used via the 'ia configure' CLI command. Direct import from the top-level package is the standard approach.

This quickstart demonstrates how to search for items, download files, and upload new content to the Internet Archive using the `internetarchive` Python library. It highlights the use of `search_items` to find content, `get_item` and `File.download` for downloading, and the `upload` function for creating new archive items. Authentication for uploads requires setting `IA_ACCESS_KEY` and `IA_SECRET_KEY` environment variables.

import os from internetarchive import search_items, get_item, upload import tempfile # --- Authentication --- # Set your IA S3 keys as environment variables for uploads and metadata modification. # You can generate them at https://archive.org/account/s3.php # For programmatic access, it's recommended to set IA_ACCESS_KEY and IA_SECRET_KEY # as environment variables. # Example: export IA_ACCESS_KEY='YOUR_ACCESS_KEY' # export IA_SECRET_KEY='YOUR_SECRET_KEY' # --- 1. Search for items --- print("Searching for items tagged 'NASA'...") search_results = search_items('subject:NASA') for i, result in enumerate(search_results.iter_as_results()): if i >= 3: # Limit to 3 results for brevity break print(f" - Identifier: {result['identifier']}, Title: {result.get('title')}") # --- 2. Download a file from an item --- # Using an example item known to exist with publicly downloadable files print("\nAttempting to download a file from 'nasa_images_1960s'...") try: item_to_download = get_item('nasa_images_1960s') # Use a stable public item # Try to find an image file, otherwise download the first available file files = item_to_download.get_files(formats=['JPEG', 'PNG', 'image/jpeg']) if files: file_to_download = files[0] print(f"Downloading {file_to_download.name}...") # Use tempfile for a safe, temporary download location with tempfile.TemporaryDirectory() as tmpdir: downloaded_path = file_to_download.download(tmpdir) print(f"Downloaded to: {downloaded_path}") else: print("No suitable files found to download from 'nasa_images_1960s'.") except Exception as e: print(f"Error during download: {e}") # --- 3. Upload a dummy file --- # Requires IA_ACCESS_KEY and IA_SECRET_KEY to be set as environment variables access_key = os.environ.get('IA_ACCESS_KEY', 'YOUR_ACCESS_KEY') secret_key = os.environ.get('IA_SECRET_KEY', 'YOUR_SECRET_KEY') if access_key == 'YOUR_ACCESS_KEY' or secret_key == 'YOUR_SECRET_KEY': print("\nSkipping upload example: IA_ACCESS_KEY or IA_SECRET_KEY not set.") print("Please set environment variables or use 'ia configure' to enable uploads.") else: print("\nAttempting to upload a dummy file...") temp_file_name = "my_dummy_file.txt" temp_file_content = "This is a test upload from the internetarchive Python library." identifier = "my_unique_test_item_12345" # Replace with a truly unique identifier with tempfile.NamedTemporaryFile(mode='w', delete=False, suffix='.txt') as f: f.write(temp_file_content) temp_file_path = f.name metadata = { 'title': f'My Test Item {identifier}', 'description': 'A dummy item uploaded via Python library quickstart.', 'mediatype': 'data', # Required 'collection': 'test_collection' # Replace with a collection you have write access to } try: print(f"Uploading {temp_file_path} to {identifier}...") r = upload(identifier, files=[temp_file_path], metadata=metadata) print(f"Upload successful! Status: {r[0].status_code}") print(f"View item at: https://archive.org/details/{identifier}") except Exception as e: print(f"Error during upload: {e}") finally: os.remove(temp_file_path)
ia --version
Debug
Known issues
breakingA critical bug in versions v5.4.1 to v5.6.x (fixed in v5.7.0) caused `ia delete --glob` and `ia delete --format` to delete *all* files in an item, regardless of the specified pattern, potentially leading to significant data loss.
fix
Upgrade to internetarchive v5.7.0 or higher immediately. Always use `ia delete --dry-run` first to preview deletions.
affects: >=5.4.1, <5.7.0
breakingVersions <=5.5.0 contain a critical directory traversal vulnerability in `File.download()` (fixed in v5.5.1). This allowed malicious filenames to write files outside the target directory, a severe risk, especially on Windows.
fix
Upgrade to internetarchive v5.5.1 or higher immediately. Implement robust input validation if handling untrusted filenames directly.
affects: <5.5.1
gotchaThe Internet Archive API has rate limits, especially for uploads. Exceeding these limits can lead to temporary (or sometimes persistent, requiring manual intervention) account lockout for API uploading privileges.
fix
Implement exponential backoff or ensure your upload script adheres to reasonable delays. Contact info@archive.org if your API upload privilege is locked.
affects: All
gotchaCertain metadata fields (e.g., `mediatype`, `collection`) are 'write-once' and can only be set during the *initial* upload of an item. Subsequent attempts to modify them will be ignored or cause errors.
fix
Carefully plan and confirm all required metadata, especially 'write-once' fields, before the first upload of an item.
affects: All
gotchaInstalling `internetarchive` via unsupported third-party package managers (e.g., Homebrew, MacPorts, Linux system packages like `apt` or `yum`) often results in severely outdated, incompatible, or broken versions.
fix
Always install `internetarchive` using `pip`, `pipx`, or from source. If previously installed via an unsupported method, uninstall it first (e.g., `brew uninstall internetarchive`) and then use a supported method.
affects: All
Errors
Common errors & fixes
HTTPError: 403 Client Error: Forbidden for url: https://s3.us.archive.org/...
Incorrect or missing Internet Archive S3 credentials (IA_ACCESS_KEY, IA_SECRET_KEY) for operations requiring authentication (upload, metadata modification).
fix
Ensure `IA_ACCESS_KEY` and `IA_SECRET_KEY` environment variables are correctly set with valid keys. Alternatively, use `internetarchive.configure()` or the `ia configure` CLI command to set them in the configuration file (`~/.ia`).
All files in item 'my_item_id' were deleted unexpectedly after running 'ia delete --glob="*.txt"'
This describes the behavior of a critical bug in `ia delete` command versions 5.4.1 through 5.6.x, where glob patterns were ignored, leading to unintended mass deletions.
fix
Upgrade the `internetarchive` library to version 5.7.0 or newer. Always test delete commands with `ia delete --dry-run` first to verify the intended files are targeted.
Error: Failed to download file 'malicious_path/../../etc/passwd'. Permission denied.
This indicates an attempt by a potentially malicious filename to perform directory traversal, which was a vulnerability in `File.download()` prior to v5.5.1, or a general permission issue.
fix
Upgrade to `internetarchive` v5.5.1 or higher to patch the directory traversal vulnerability. Ensure target download directories have appropriate write permissions for the user running the script.
Upgrade
Version history
5.9.0latest on PyPI · released May 28, 2026
Audit
Dependencies
pythonrequiredRequires Python 3.9 or newer
ujsonoptionalFaster JSON parsing for 'speedups' extra
geventoptionalConcurrent downloads for 'speedups' extra
Agent activity
16 hits · last 30 days
node
14
Resources
internetarchive — pip install internetarchive · libregistry