2 |
3 | 
4 |
5 | Analyze and manipulate your Anki collection using pandas!
6 |
7 |
8 |
9 |
10 | [](https://ankipandas.readthedocs.io/) [](https://matrix.to/#/#AnkiPandas_community:gitter.im)
11 | [](https://github.com/klieret/ankipandas/blob/master/LICENSE.txt)
12 | [](https://git-scm.com/book/en/v2/GitHub-Contributing-to-a-Project)
13 |
14 |
15 |
16 |
17 | [](https://results.pre-commit.ci/latest/github/klieret/AnkiPandas/master)
18 | [](https://github.com/klieret/AnkiPandas/actions) [](https://coveralls.io/github/klieret/AnkiPandas?branch=master)
19 | [](https://github.com/klieret/AnkiPandas/actions/workflows/codeql.yml)
20 | [](https://gitmoji.dev) [](https://github.com/python/black)
21 | [](https://pypi.org/project/ankipandas/)
22 |
23 |
24 |
25 |
26 | ## 📝 Description
27 |
28 | > **Note**
29 | > This package needs a new maintainer, as I currently do not have enough time to continue development
30 | > of this package. Writing modifications back into the Anki database is currently disabled,
31 | > in particular because of issue [#137](https://github.com/klieret/AnkiPandas/issues/137).
32 | > Please reach out to me if you are interested in getting involved!
33 |
34 | [Anki](https://apps.ankiweb.net/) is one of the most popular flashcard
35 | system for spaced repetition learning,
36 | [pandas](https://pandas.pydata.org/) is the most popular python package
37 | for data analysis and manipulation. So what could be better than to
38 | bring both together?
39 |
40 | With `AnkiPandas` you can use `pandas` to easily analyze or manipulate
41 | your Anki flashcards.
42 |
43 | **Features**:
44 |
45 | - **Select**: Easily select arbitrary subsets of your cards, notes or
46 | reviews using `pandas` ([one of many
47 | introductions](https://medium.com/dunder-data/6fcd0170be9c),
48 | [official
49 | documentation](https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html))
50 | - **Visualize**: Use pandas\' powerful [built in
51 | tools](https://pandas.pydata.org/pandas-docs/stable/user_guide/visualization.html)
52 | or switch to the even more versatile
53 | [seaborn](https://seaborn.pydata.org/) (statistical analysis) or
54 | [matplotlib](https://matplotlib.org/) libraries
55 | - **Manipulate**: Apply fast bulk operations to the table (e.g. add
56 | tags, change decks, set field contents, suspend cards, \...) or
57 | iterate over the table and perform these manipulations step by step.
58 | **⚠️ This functionality is currently disabled until [#137](https://github.com/klieret/AnkiPandas/issues/137) has been resolved! ⚠️**
59 | - **Import and Export**: Pandas can export to (and import from) csv,
60 | MS Excel, HTML, JSON, \... ([io
61 | documentation](https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html))
62 |
63 | **Pros**:
64 |
65 | - **Easy installation**: Install via python package manager
66 | (independent of your Anki installation)
67 | - **Simple**: Just one line of code to get started
68 | - **Convenient**: Bring together information about
69 | [cards](https://apps.ankiweb.net/docs/manual.html#cards),
70 | [notes](https://apps.ankiweb.net/docs/manual.html#notes-&-fields),
71 | [models](https://apps.ankiweb.net/docs/manual.html#note-types),
72 | [decks](https://apps.ankiweb.net/docs/manual.html#decks) and more in
73 | just one table!
74 | - **Fully documented**: Documentation on [readthedocs](https://ankipandas.readthedocs.io/)
75 | - **Well tested**: More than 100 unit tests to keep everything in
76 | check
77 |
78 | Alternatives: If your main goal is to add new cards, models and more,
79 | you can also take a look at the
80 | [genanki](https://github.com/kerrickstaley/genanki) project.
81 |
82 | ## 📦 Installation
83 |
84 | `AnkiPandas` is available as [pypi
85 | package](https://pypi.org/project/ankipandas/) and can be installed or
86 | upgrade with the [python package
87 | manager](https://pip.pypa.io/en/stable/):
88 |
89 | ```sh
90 | pip3 install --user --upgrade ankipandas
91 | ```
92 |
93 | ### Development installation
94 |
95 | For the latest development version you can also work from a cloned
96 | version of this repository:
97 |
98 | ```sh
99 | git clone https://github.com/klieret/ankipandas/
100 | cd ankipandas
101 | pip3 install --user --upgrade --editable .
102 | ```
103 |
104 | If you want to help develop this package further, please also install the
105 | [pre-commit](https://pre-commit.ci/) hooks and use [gitmoji](https://gitmoji.dev/):
106 |
107 | ```sh
108 | pre-commit install
109 | gitmoji -i
110 | ```
111 |
112 | ## 🔥 Let's get started!
113 |
114 | Starting up is as easy as this:
115 |
116 | ```python
117 | from ankipandas import Collection
118 |
119 | col = Collection()
120 | ```
121 |
122 | And `col.notes` will be dataframe containing all notes, with additional
123 | methods that make many things easy. Similarly, you can access cards or
124 | reviews using `col.cards` or `col.revs`.
125 |
126 | If called without any argument `Collection()` tries to find your Anki
127 | database by itself. However this might take some time. To make it
128 | easier, simply supply (part of) the path to the database and (if you
129 | have more than one user) your Anki user name, e.g.
130 | `Collection(".local/share/Anki2/", user="User 1")` on many Linux
131 | installations.
132 |
133 | To get information about the interpretation of each column, use
134 | `print(col.notes.help_cols())`.
135 |
136 | Take a look at the [documentation](https://ankipandas.readthedocs.io/)
137 | to find out more about more about the available methods!
138 |
139 | Some basic examples:
140 |
141 | ## 📈 Analysis
142 |
143 | **More examples**: [Analysis
144 | documentation](https://ankipandas.readthedocs.io/en/latest/examples.html),
145 | [projects that use `AnkiPandas`](https://ankipandas.readthedocs.io/en/latest/projects_with_ap.html).
146 |
147 | Show a histogram of the number of reviews (repetitions) of each card for
148 | all decks:
149 |
150 | ```python
151 | col.cards.hist(column="creps", by="cdeck")
152 | ```
153 |
154 | Show the number of leeches per deck as pie chart:
155 |
156 | ```python
157 | cards = col.cards.merge_notes()
158 | selection = cards[cards.has_tag("leech")]
159 | selection["cdeck"].value_counts().plot.pie()
160 | ```
161 |
162 | Find all notes of model `MnemoticModel` with empty `Mnemotic` field:
163 |
164 | ```python
165 | notes = col.notes.fields_as_columns()
166 | notes.query("model=='MnemoticModel' and 'Mnemotic'==''")
167 | ```
168 |
169 | ## 🛠️ Manipulations
170 |
171 | > **Warning**
172 | > Writing the database has currently been disabled until
173 | > [#137](https://github.com/klieret/AnkiPandas/issues/137) has been resolved.
174 | > Help is much appreciated!
175 |
176 | > **Warning**
177 | > **Please be careful and test this well!**
178 | > Ankipandas will create a backup of your database before writing, so you can always restore the previous state. Please make sure that everything is working before continuing to use Anki normally!
179 |
180 | Add the `difficult-japanese` and `marked` tag to all notes that contain
181 | the tags `Japanese` and `leech`:
182 |
183 | ```python
184 | notes = col.notes
185 | selection = notes[notes.has_tags(["Japanese", "leech"])]
186 | selection = selection.add_tag(["difficult-japanese", "marked"])
187 | col.notes.update(selection)
188 | col.write(modify=True) # Overwrites your database after creating a backup!
189 | ```
190 |
191 | Set the `language` field to `English` for all notes of model
192 | `LanguageModel` that are tagged with `English`:
193 |
194 | ```python
195 | notes = col.notes
196 | selection = notes[notes.has_tag(["English"])].query("model=='LanguageModel'").copy()
197 | selection.fields_as_columns(inplace=True)
198 | selection["language"] = "English"
199 | col.notes.update(selection)
200 | col.write(modify=True)
201 | ```
202 |
203 | Move all cards tagged `leech` to the deck `Leeches Only`:
204 |
205 | ```python
206 | cards = col.cards
207 | selection = cards[cards.has_tag("leech")]
208 | selection["cdeck"] = "Leeches Only"
209 | col.cards.update(selection)
210 | col.write(modify=True)
211 | ```
212 |
213 | ## 🐞 Troubleshooting
214 |
215 | See the [troubleshooting section in the
216 | documentation](https://ankipandas.readthedocs.io/en/latest/troubleshooting.html).
217 |
218 | ## 💖 Contributing
219 |
220 | Your help is greatly appreciated! Suggestions, bug reports and feature
221 | requests are best opened as [github
222 | issues](https://github.com/klieret/ankipandas/issues). You could also
223 | first discuss in the [gitter
224 | community](https://matrix.to/#/#AnkiPandas_community:gitter.im). If you want to code
225 | something yourself, you are very welcome to submit a [pull
226 | request](https://github.com/klieret/AnkiPandas/pulls)!
227 |
228 | Bug reports and pull requests are credited with the help of the [allcontributors bot](https://allcontributors.org/).
229 |
230 | ## 📃 License & Disclaimer
231 |
232 | This software is licenced under the [MIT
233 | license](https://github.com/klieret/ankipandas/blob/master/LICENSE.txt)
234 | and (despite best testing efforts) comes **without any warranty**. The
235 | logo is inspired by the [Anki
236 | logo](https://github.com/ankitects/anki/blob/main/qt/aqt/data/web/imgs/anki-logo-thin.png)
237 | ([license](https://github.com/ankitects/anki/blob/main/LICENSE)) and
238 | the logo of the pandas package
239 | ([license2](https://github.com/pandas-dev/pandas/blob/main/LICENSE)).
240 | This library and its author(s) are not affiliated/associated with the
241 | main Anki or pandas project in any way.
242 |
243 | ## ✨ Contributors
244 |
245 | Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
246 |
247 |
248 |
249 |
250 |