Kindle Automator is an open-source automation platform that turns Android emulators into programmable Kindle reading agents. It provides a REST API to control the Amazon Kindle Android app, enabling developers to build applications that can read books, navigate pages, extract text via OCR, and manage entire Kindle libraries programmatically.
The Kindle ecosystem is notoriously locked down. Amazon provides no official API for third-party applications to interact with your purchased Kindle books. This project bridges that gap by using Android emulation and UI automation to provide programmatic access to Kindle functionality.
Use cases include:
- Building accessible reading applications for users with disabilities
- Creating custom reading interfaces and experiences
- Developing AI-powered reading assistants
- Automating book organization and library management
- Research applications requiring bulk text extraction
- Building cross-platform reading synchronization tools
-
π₯ Multi-User Support - Run multiple Android emulators simultaneously, each with its own authenticated Amazon account and isolated profile data
-
π REST API - Complete HTTP API for all Kindle operations including authentication, library browsing, book opening, page navigation, and screenshots
-
π OCR Text Extraction - Extract readable text from any page using Google Document AI or Mistral OCR with automatic UI element filtering
-
π‘ Real-Time Streaming - Server-Sent Events (SSE) endpoint for streaming book library data as it loads, with cover image extraction
-
πΌοΈ Book Cover Extraction - Automatically extract and cache book cover images from the library view for use in your applications
-
π Table of Contents Navigation - Retrieve chapter listings and jump directly to any chapter in a book
-
π― Absolute Page Navigation - Navigate to specific page positions with session tracking to maintain reading progress across requests
-
π Preview Mode - Look ahead or behind in a book without changing your actual reading position
-
π₯οΈ VNC Remote Access - View and interact with emulators in real-time through browser-based VNC streaming via WebSocket
-
𧬠Profile Cloning - Create new user profiles from authenticated "seed" templates for rapid deployment
-
π§ Cold Storage Archival - Automatically archive inactive user profiles to cloud storage (DigitalOcean Spaces) and restore on demand
-
π€ State Machine Architecture - Intelligent handling of Kindle app states including login screens, dialogs, popups, and reading modes
-
π Request Deduplication - Smart request queuing with priority handling to prevent conflicting automation commands
-
π€ Idle Management - Automatic shutdown of inactive emulators to conserve server resources
-
πΈ Snapshot Recovery - Save and restore emulator states for fast startup and crash recovery
-
π Admin Dashboard - Built-in Flask-Admin interface for monitoring users, VNC instances, and system state
-
π Sentry Integration - Production-ready error tracking and monitoring with intelligent error filtering
-
π Device Fingerprint Randomization - Randomize device identifiers (MAC addresses, serial numbers, Android IDs) to avoid detection
To get started with the automation setup, you need to install Appium and the necessary drivers. Follow the steps below:
-
Install Appium: Appium is a tool for automating mobile applications. You can install it using npm (Node Package Manager). If you don't have npm installed, you need to install Node.js first, which includes npm.
npm install -g appium
-
Install UiAutomator2 Driver: After installing Appium, you need to install the UiAutomator2 driver, which is required for Android automation.
appium driver install uiautomator2
-
Verify Installation: To verify that Appium and the UiAutomator2 driver are installed correctly, you can run the following command:
appium -v
This should display the version of Appium installed. Additionally, you can check the installed drivers by running:
appium driver list
This should list
uiautomator2among the installed drivers.
Now you are ready to proceed with the automation setup and run the scripts.
-
Install Android Studio: To run Android emulators and use Android SDK tools, you need to install Android Studio. Follow the steps below to install Android Studio:
- Download Android Studio from the official website: https://developer.android.com/studio
- Follow the installation instructions for your operating system (Windows, macOS, or Linux).
- During the installation, make sure to install the Android SDK and Android Virtual Device (AVD) components.
-
Set Up Android SDK: After installing Android Studio, you need to set up the Android SDK and ensure that the
adb(Android Debug Bridge) tool is available in your system's PATH.- Open Android Studio and go to
Preferences(macOS) orSettings(Windows/Linux). - Navigate to
Appearance & Behavior>System Settings>Android SDK. - Make sure the SDK Path is set to the default location or a location of your choice.
- Under the
SDK Toolstab, ensure that the following tools are installed:- Android SDK Build-Tools
- Android Emulator
- Android SDK Platform-Tools
- Android SDK Tools
- Open Android Studio and go to
-
Add Android SDK to PATH: To use
adband other Android SDK tools from the command line, you need to add the Android SDK'splatform-toolsdirectory to your system's PATH.-
For macOS/Linux:
echo 'export ANDROID_HOME=~/Library/Android/sdk' >> ~/.bash_profile echo 'export PATH=$PATH:$ANDROID_HOME/platform-tools' >> ~/.bash_profile source ~/.bash_profile
-
For Windows:
- Open
System Properties(right-click onThis PCorMy Computerand selectProperties). - Click on
Advanced system settingsand thenEnvironment Variables. - Under
System variables, find thePathvariable, select it, and clickEdit. - Add the path to the
platform-toolsdirectory (e.g.,C:\Users\<YourUsername>\AppData\Local\Android\Sdk\platform-tools).
- Open
-
-
Verify Android SDK Installation: To verify that the Android SDK is installed correctly and
adbis available, you can run the following command:adb devices
This should list any connected Android devices or running emulators. If no devices are listed, ensure that your device is connected and USB debugging is enabled, or that an emulator is running.
Now you are ready to proceed with the automation setup and run the scripts.
-
Set Up Virtual Environment: To ensure that all dependencies are installed in an isolated environment, you should set up a virtual environment using
virtualenv.-
Install
virtualenvif you haven't already:uv install virtualenv
-
Create a virtual environment named
kindle-automator:virtualenv kindle-automator
-
Activate the virtual environment:
- For macOS/Linux:
source kindle-automator/bin/activate - For Windows:
.\kindle-automator\Scripts\activate
- For macOS/Linux:
-
-
Install Dependencies: Once the virtual environment is activated, install the required dependencies using
make deps:make deps
-
Database Setup (Required for first-time setup): The application requires PostgreSQL and Redis to be running. These are provided via Docker containers from the web-app project:
# Start Docker containers (PostgreSQL and Redis) cd ../web-app && make fast cd ../kindle-automator # Initialize the database (creates kindle_dev database, runs migrations, imports data) make db-setup
This only needs to be done once when setting up a new development environment. The
make db-setupcommand will:- Create the
kindle_devdatabase if it doesn't exist - Run all database migrations
- Import any existing user data from
user_data/users.json
Note: Make sure Docker Desktop is running and the
sol_postgrescontainer is available on port 5496. - Create the
-
Configuration: The application uses a
.envfile for API keys and other configuration. Create your.envfile by copying the example:cp .env.example .env
Then edit the
.envfile to add your API keys:# API Keys MISTRAL_API_KEY=your-actual-mistral-api-keyThis file is listed in
.gitignoreto ensure your API keys are never committed to the repository.Note: Amazon credentials (email and password) must be provided in the /auth API request, and captcha solutions (if needed) must be provided to the /captcha endpoint. These are not read from environment variables or configuration files. The system will automatically initialize when needed, but you must authenticate with the /auth endpoint before accessing other features.
-
Running Tests: To run the integration tests, you need to generate authentication tokens first:
# Generate staff authentication token make test-staff-auth # Generate web authentication token (see ../web-app/CLAUDE.md for details) make test-web-auth
After generating the tokens, add them to your
.envfile:INTEGRATION_TEST_STAFF_AUTH_TOKEN=<your-staff-token> WEB_INTEGRATION_TEST_AUTH_TOKEN=<your-web-token>Then run the tests:
make test -
Run the Script: After setting up the virtual environment, installing dependencies, and configuring your environment, you can run the automation script using:
make run
This will install the Kindle APK and start the Flask server so it's ready to automate the app.
The system now includes AVD profile management that creates and manages separate Android Virtual Devices for each user account. This allows you to:
- Maintain multiple authenticated Kindle accounts simultaneously
- Switch between accounts without having to re-authenticate each time
- Preserve the state of each account, including downloaded books and login credentials
Each time a new email address is sent to the /auth endpoint, the system automatically:
- Checks if a profile already exists for this email
- If it exists, switches to that profile
- If not, creates a new AVD profile for the email
- Initializes the Kindle app in the selected profile
GET /profiles- List all available profiles and the current active profilePOST /profiles- Create, delete, or switch profiles withactionparameter:{"action": "create", "email": "user@example.com"}{"action": "delete", "email": "user@example.com"}{"action": "switch", "email": "user@example.com"}
- When using
/auth, you can add arecreateparameter to delete and recreate a profile:{"email": "user@example.com", "password": "password123", "recreate": true}- This is useful when you want to start fresh with a clean profile
For M1/M2/M4 Mac users who need to create and manage AVDs directly in Android Studio, we've added a special workflow:
- Create your AVD in Android Studio with your preferred settings
- Register the AVD with Kindle Automator using one of the following:
# Interactive registration make register-avd # Complete workflow (recommended) make android-studio-avd
- Start the emulator manually from Android Studio
- Run the Kindle Automator server with:
make server
This approach allows you to use manually created AVDs with the profile tracking system. The system will associate your Android Studio AVD with a specific email account and track which one is active, without trying to start the emulator itself.
Due to compatibility issues with Android emulation on ARM-based Macs, the profile system has been adapted to:
- Create and track profiles without attempting to start the emulator automatically
- Provide several ways to manage the emulator:
-
Start both emulator and server together:
make dev
This single command starts the emulator for the current profile and then launches the server.
-
Start just the emulator for the current profile:
make run-emulator
This automatically selects the AVD associated with the current profile (e.g., after using
make profile-switch). -
Choose which AVD to start:
make run-emulator-choose
This shows a list of all available AVDs and lets you select which one to run.
-
Register an Android Studio AVD:
make register-avd
This allows you to associate an Android Studio AVD with an email profile.
-
Create or switch to a profile:
make profile-create EMAIL=user@example.com
or
make profile-switch EMAIL=user@example.com
-
Start everything with one command:
make dev
-
Test the API endpoints:
make test-auth EMAIL=user@example.com PASSWORD=yourpassword
The system will track which profile is "current" even if the emulator starts separately.
- Create AVDs directly in Android Studio
- Register them with Kindle Automator:
make android-studio-avd
- Start the emulator from Android Studio
- Start the server:
make server
- Test the API endpoints:
make test-auth EMAIL=user@example.com PASSWORD=yourpassword
In production environments (Linux servers), the emulator starts automatically as part of the profile switching process without needing manual intervention.
server/server.py: Flask server on port 4098views/state_machine.py: Handles Kindle app states and transitionsviews/core/app_state.py: Kindle views and app statesviews/core/avd_profile_manager.py: Manages AVD profiles for different user accountsviews/transition.py: Controller between states and handlersviews/view_inspector.py: App view identifying, interacting with appium driverhandlers/*_handler.py: Various handlers for different app statesautomator.py: Glue between the Kindle side and the server side, ensuring driver is runningdriver.py: Handles Appium driver initialization and management