A Python script for automatically downloading books from Anna's Archive using search queries (titles, authors, ISBNs, etc).
- Search Anna's Archive using any search query (title, author, ISBN, etc.)
- Interactive selection from all available format options
- Automatically download books via fast partner servers
- Simple environment variable authentication
- Detailed logging and progress reporting
- Customizable configuration via JSON file
- Python 3.8+
- Requests
- BeautifulSoup4
- InquirerPy
- python-dotenv
-
Install pyenv if you don't have it already:
# macOS brew install pyenv # Ubuntu/Debian curl https://pyenv.run | bash
-
Configure your shell by adding the following to your profile file (
.bashrc
,.zshrc
, etc.):export PATH="$HOME/.pyenv/bin:$PATH" eval "$(pyenv init --path)" eval "$(pyenv init -)"
-
Install Python with pyenv:
pyenv install 3.11.0 # or any other version 3.8+
-
Create a virtual environment:
# Navigate to the project directory cd path/to/annas-downloader # Create a virtual environment pyenv local 3.11.0 python -m venv .venv # Activate the virtual environment source .venv/bin/activate # On Windows: .venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Set up authentication and configuration:
# Copy the example .env file cp .env.example .env # Edit the .env file with your Anna's Archive account ID # You can find this by logging into Anna's Archive and checking your cookies # Look for the "aa_account_id2" cookie value # Make sure config.json exists (should be provided with the script) # If not, create it using the template from the documentation
The script uses a config.json
file for all search parameters, format preferences, and output settings. The default configuration is included, but you can customize it for your needs:
{
"search": {
"index": "",
"page": "1",
"display": "",
"sort": ""
},
"content": {
"types": [
"book_fiction",
"book_nonfiction",
"book_unknown",
"magazine",
"book_comic",
"standards_document",
"other",
"musical_score"
],
"ignore": [
"book_nonfiction",
"book_unknown",
"magazine",
"book_comic",
"standards_document",
"other",
"musical_score"
]
},
"formats": {
"ignore": [
"pdf",
"mobi",
"fb2",
"cbr"
],
"definitions": {
"epub": {
"priority": 100,
"extension": ".epub",
"icon": "π",
"display_name": "EPUB",
"content_type": "application/epub+zip"
},
"pdf": {
"priority": 80,
"extension": ".pdf",
"icon": "π",
"display_name": "PDF",
"content_type": "application/pdf"
},
"mobi": {
"priority": 60,
"extension": ".mobi",
"icon": "π",
"display_name": "MOBI",
"content_type": "application/x-mobipocket-ebook"
},
"fb2": {
"priority": 40,
"extension": ".fb2",
"icon": "π",
"display_name": "FB2",
"content_type": "application/fb2"
},
"cbr": {
"priority": 20,
"extension": ".cbr",
"icon": "ποΈ",
"display_name": "CBR",
"content_type": "application/x-cbr"
}
}
},
"access": {
"types": [
"aa_download",
"external_download",
"external_borrow",
"external_borrow_printdisabled",
"torrents_available"
],
"ignore": [
"external_download",
"external_borrow",
"external_borrow_printdisabled",
"torrents_available"
]
},
"languages": {
"types": [
"en",
"zh",
"ru",
"es",
"fr",
"de",
"it",
"pt",
"pl",
"nl"
],
"ignore": [
"zh",
"ru",
"es",
"fr",
"de",
"it",
"pt",
"pl",
"nl"
]
},
"output_dir": "books/"
}
- search: Basic search parameters
- content: Content types configuration
- types: All available content types
- ignore: Content types to exclude from search
- formats: File formats configuration
- ignore: Formats to exclude from search
- definitions: Detailed metadata for each format
- priority: Numeric priority value (higher = preferred)
- extension: File extension (e.g., ".epub")
- icon: Emoji icon for display
- display_name: Human-readable format name
- content_type: MIME type for the format
- access: Access methods configuration
- types: All available access methods
- ignore: Access methods to exclude
- languages: Languages configuration
- types: All available languages
- ignore: Languages to exclude
- output_dir: Default directory to save downloaded books
The script supports three primary modes of operation:
Search for a book with a specific query and download it:
python aapy.py single "Project Hail Mary" --output books/
You can also search by ISBN:
python aapy.py single "9781250881205"
Start an interactive session for multiple searches and downloads:
python aapy.py interactive
This mode allows you to:
- Enter multiple search queries (one at a time)
- Select from all available formats for each book
- Cancel any download at any point
Search for books without downloading them (useful for testing and troubleshooting):
python aapy.py debug "Foundation Asimov"
usage: aapy.py {single,interactive,debug} [-h] [--config CONFIG] [--output OUTPUT] [--verbose]
[--formats FORMAT [FORMAT ...]]
[--content CONTENT [CONTENT ...]]
[--access ACCESS [ACCESS ...]]
[--languages LANGUAGE [LANGUAGE ...]]
Download books from Anna's Archive by search query
modes:
single Download a book by search query (title, author, ISBN, etc)
interactive Run in interactive mode to download multiple books
debug Debug search results without downloading
options:
-h, --help show this help message and exit
--config CONFIG Path to config file (default: config.json)
--output OUTPUT, -o OUTPUT
Directory to save downloaded books (overrides config's output_dir)
--verbose, -v Enable verbose logging
--formats FORMAT [FORMAT ...]
Formats to include (all others will be ignored)
--content CONTENT [CONTENT ...]
Content types to include (all others will be ignored)
--access ACCESS [ACCESS ...]
Access methods to include (all others will be ignored)
--languages LANGUAGE [LANGUAGE ...]
Languages to include (all others will be ignored)
You can override configuration settings through command-line arguments. When you specify options on the command line, all other options of that type will be automatically ignored:
# Only include EPUB and PDF formats (ignoring all others)
python aapy.py single "Dune Herbert" --formats epub pdf
# Only include fiction books
python aapy.py single "Asimov" --content book_fiction
# Only include direct downloads from Anna's Archive
python aapy.py single "Sapiens" --access aa_download
# Only include English and Spanish books
python aapy.py single "Don Quixote" --languages en es
# Use a custom config file
python aapy.py interactive --config my_custom_config.json
Authentication is handled via the .env
file, which should contain your Anna's Archive account ID:
AA_ACCOUNT_ID=your_account_id_here
OUTPUT_DIR=books/
To find your account ID:
- Log in to Anna's Archive in your browser
- Open your browser's developer tools (F12 or right-click β Inspect)
- Go to the Storage or Application tab (depends on browser)
- Look for Cookies β annas-archive.org
- Find the cookie named
aa_account_id2
and copy its value - Paste this value in your
.env
file
- Search Phase: Searches Anna's Archive with parameters from config.json to find books matching your query
- Selection Phase: Presents an interactive menu of all matching books with format details
- Download Phase: Finds the fastest download link and saves the book file
You can customize the search parameters in the config.json file to:
-
Adjust format priorities:
"formats": { "definitions": { "pdf": { "priority": 120 }, "epub": { "priority": 100 } } }
-
Include different content types:
"content": { "ignore": ["magazine", "book_comic"] }
-
Change language preferences:
"languages": { "ignore": ["zh", "ru"] }
You can add support for new format types by adding them to the config:
- Add a complete definition under
definitions
:
"formats": {
"ignore": ["mobi", "fb2", "cbr"],
"definitions": {
"djvu": {
"priority": 90,
"extension": ".djvu",
"icon": "π",
"display_name": "DJVU",
"content_type": "image/vnd.djvu"
}
}
}
This extensible approach lets you add support for new formats without changing any code.
For convenience, a start.sh
script is included to quickly start the interactive mode:
# Make the script executable
chmod +x start.sh
# Run the script
./start.sh
This tool is provided for educational and research purposes only. Please respect copyright laws and the terms of service of Anna's Archive.