Metadata-Version: 2.4
Name: zotero2readwise
Version: 1.4.2
Summary: Export your Zotero annotations and notes to Readwise
Project-URL: Homepage, https://github.com/e-alizadeh/Zotero2Readwise
Project-URL: Repository, https://github.com/e-alizadeh/Zotero2Readwise
Project-URL: Documentation, https://github.com/e-alizadeh/Zotero2Readwise
Author-email: ealizadeh <hello@ealizadeh.com>
License: MIT
License-File: LICENSE
Keywords: Readwise,Zotero
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Software Development :: Build Tools
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Requires-Python: >=3.12
Requires-Dist: python-dotenv<1.1.0
Requires-Dist: pyzotero>=1.4.26
Requires-Dist: requests>=2.26.0
Provides-Extra: dev
Requires-Dist: ipdb>=0.13.13; extra == 'dev'
Requires-Dist: ipython>=8.10.0; extra == 'dev'
Requires-Dist: pre-commit>=3.5.0; extra == 'dev'
Requires-Dist: pytest-cov>=4.1.0; extra == 'dev'
Requires-Dist: pytest-mock>=3.12.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Description-Content-Type: text/markdown

# Zotero ➡️ Readwise

`zotero2readwise` is a Python library that retrieves all [Zotero](https://www.zotero.org/) annotations† and notes.
Then, It automatically uploads them to your [Readwise](https://readwise.io/)§.

This is particularly useful for the new [Zotero PDF Reader](https://www.zotero.org/support/pdf_reader_preview)
that stores all highlights in the Zotero database.
The new Zotero, also available for [iOS app](https://www.zotero.org/iosbeta) (currently in beta).
In the new Zotero, the annotations are NOT saved in the PDF file unless you export the highlights in order to save them.

If you annotate your files outside the new Zotero PDF reader, this library may not work with your PDF annotations as those are not retrievable from Zotero API.

**_This library is for you if you annotate (highlight + note) using the Zotero's PDF reader (including the Zotero iOS)_**

👉***Updating an existing Zotero annotation or note and re-running this library will update the corresponding Readwise highlight without creating a duplicate!***

† Annotations made in the new Zotero PDF reader and note editor.

§ Readwise is a _paid_ service/software that integrates your highlights from almost everywhere (Pocket, Instapaper, Twitter, Medium, Apple Books, and many more).
It even has an amazing OCR for directly importing your highlights on a physical book/article into Readwise and allowing
you to export all your highlights to Obsidian, Notion, Roam, Markdown, etc.
Moreover, It has an automated [Spaced Repition](https://en.wikipedia.org/wiki/Spaced_repetition) and [Active Recall](https://en.wikipedia.org/wiki/Testing_effect).

---


# Installation

## Using pip (recommended for users)
You can install the library by running:
```shell
pip install zotero2readwise
```

Note: If you do not have pip installed on your system, you can follow the instructions [here](https://pip.pypa.io/en/stable/installation/).

## For Development

This project uses [uv](https://github.com/astral-sh/uv) for dependency management and requires Python 3.12 or higher.

### Install uv
```shell
curl -LsSf https://astral.sh/uv/install.sh | sh
```

### Clone and setup the repository
```shell
git clone https://github.com/e-alizadeh/Zotero2Readwise.git
cd Zotero2Readwise
uv sync --all-extras  # Install all dependencies including dev tools
```

### Run tests
```shell
uv run pytest  # Run all tests with coverage
```


# Usage
Since we have to retrieve the notes from Zotero API and then upload them to the Readwise, the minimum requirements are:
* **Readwise access token** [Required]: You can get your access token from https://readwise.io/access_token
* **Zotero API key** [Required]: Create a new Zotero Key from [your Zotero settings](https://www.zotero.org/settings/keys/new)
* **Zotero personal or group ID** [Required]:
    * Your **personal library ID** (aka **userID**) can be found [here](https://www.zotero.org/settings/keys) next to `Your userID for use in API calls is XXXXXX`.
    * If you're using a **group library**, you can find the library ID by
        1. Go to `https://www.zotero.org/groups/`
        2. Click on the interested group.
        3. You can find the library ID from the URL link that has format like *https://www.zotero.org/groups/<group_id>/group_name*. The number between `/groups/` and `/group_name` is the libarry ID.
* **Zotero library type** [Optional]: *"user"* (default) if using personal library and *"group"* if using group library.

Note that if you want to retrieve annotations and notes from a group, you should provide the group ID (`zotero_library_id=<group_id>`) and set the library type to group (`zotero_library_type="group"`).

## Approach 1 (running a python script)
For this approach you can download `run.py` script (from [here](https://github.com/e-alizadeh/Zotero2Readwise/blob/master/zotero2readwise/run.py)). Run `python run.py -h` to get more information about all options.
You can simply run the script as the following:
```shell
python run.py <readwise_token> <zotero_key> <zotero_id>
```

## Approach 2 (through python terminal)
```python
from zotero2readwise.zt2rw import Zotero2Readwise

zt_rw = Zotero2Readwise(
    readwise_token="your_readwise_access_token",  # Visit https://readwise.io/access_token)
    zotero_key="your_zotero_key",  # Visit https://www.zotero.org/settings/keys
    zotero_library_id="your_zotero_id", # Visit https://www.zotero.org/settings/keys
    zotero_library_type="user", # "user" (default) or "group"
    include_annotations=True, # Include Zotero annotations -> Default: True
    include_notes=False, # Include Zotero notes -> Default: False
)
zt_rw.run()
```
Just to make sure that all files are created, you can run `save_failed_items_to_json()` from `readwise` attribute of
the class object to save any highlight that failed to upload to Readwise.
If a file or more failed to create, the filename (item title) and the corresponding Zotero
item key will be saved to a txt file.
```python
zt_rw.readwise.save_failed_items_to_json("failed_readwise_highlights.json")
```

## Approach 3 (through the nix flake)
If you have `nix`, you can skip any installation and do:
```sh
nix run github:e-alizadeh/Zotero2Readwise -- <readwise_token> <zotero_key> <zotero_id>
```
The text file with failed highlights, which usually would be written to the Zotero2Readwise python package directory, will now be written to you working directory, since nix does not allow writing to package directories.
If you don't want this file created, supply `--suppress_failures` as an additional argument.

---
# Automated Sync with GitHub Actions

### Set up a scheduled automation once and forget about it!

You can use the [Zotero2Readwise-Sync](https://github.com/e-alizadeh/Zotero2Readwise-Sync) repository that contains
a GitHub Actions workflow to automatically sync your Zotero annotations/notes to Readwise on a schedule.

**Quick Setup:**

1. Fork [Zotero2Readwise-Sync](https://github.com/e-alizadeh/Zotero2Readwise-Sync)
2. Add your secrets in the forked repo's Settings → Secrets:
   - `READWISE_TOKEN` - Your Readwise access token
   - `ZOTERO_KEY` - Your Zotero API key
   - `ZOTERO_ID` - Your Zotero user/library ID
3. The workflow runs automatically on schedule (or trigger manually)

**Minimal Workflow Example:**

```yaml
name: Zotero to Readwise Sync

on:
  schedule:
    - cron: "0 3 * * 1"  # Weekly on Monday at 3 AM UTC
  workflow_dispatch:  # Manual trigger

jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - uses: astral-sh/setup-uv@v4
      - run: uvx --from zotero2readwise run
        env:
          READWISE_TOKEN: ${{ secrets.READWISE_TOKEN }}
          ZOTERO_KEY: ${{ secrets.ZOTERO_KEY }}
          ZOTERO_LIBRARY_ID: ${{ secrets.ZOTERO_ID }}
```


# Request a new feature or report a bug
Feel free to request a new feature or report a bug in GitHub issue [here](https://github.com/e-alizadeh/Zotero2Readwise/issues).


# 📫 How to reach me:
<a href="https://ealizadeh.com" target="_blank"><img alt="Personal Website" src="https://img.shields.io/badge/Personal%20Website-%2312100E.svg?&style=for-the-badge&logoColor=white" /></a>
<a href="https://www.linkedin.com/in/alizadehesmaeil/" target="_blank"><img alt="LinkedIn" src="https://img.shields.io/badge/linkedin-%230077B5.svg?&style=for-the-badge&logo=linkedin&logoColor=white" /></a>
<a href="https://medium.ealizadeh.com/" target="_blank"><img alt="Medium" src="https://img.shields.io/badge/medium-%2312100E.svg?&style=for-the-badge&logo=medium&logoColor=white" /></a>
<a href="https://twitter.com/intent/follow?screen_name=es_alizadeh&tw_p=followbutton" target="_blank"><img alt="Twitter" src="https://img.shields.io/badge/twitter-%231DA1F2.svg?&style=for-the-badge&logo=twitter&logoColor=white" /></a>

<a href="https://www.buymeacoffee.com/ealizadeh" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-blue.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
