apyanki 0.15.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT license
2
+
3
+ Copyright (c) 2020 Karl Yngve Lervåg
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,366 @@
1
+ Metadata-Version: 2.1
2
+ Name: apyanki
3
+ Version: 0.15.0
4
+ Summary: CLI script for interacting with local Anki collection
5
+ Author: Karl Yngve Lervåg
6
+ Author-email: karl.yngve@lervag.net
7
+ Requires-Python: >=3.9,<4.0
8
+ Classifier: Environment :: Console
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Requires-Dist: anki (>=23.10,<24.0)
17
+ Requires-Dist: beautifulsoup4 (>=4.12.2,<5.0.0)
18
+ Requires-Dist: click (>=8.1.3,<9.0.0)
19
+ Requires-Dist: html5lib (>=1.1,<2.0)
20
+ Requires-Dist: markdown (>=3.4.3,<4.0.0)
21
+ Requires-Dist: markdownify (>=0.11.6,<0.12.0)
22
+ Requires-Dist: readchar (>=4.0.5,<5.0.0)
23
+ Requires-Dist: rich (>=13.7.1,<14.0.0)
24
+ Description-Content-Type: text/markdown
25
+
26
+ # apy
27
+
28
+ [Anki](https://apps.ankiweb.net/index.html) is a flash card program which makes
29
+ remembering things easy. `apy` is a Python script for easily adding cards to
30
+ Anki. It does not require Anki to be running at the same time.
31
+
32
+ ### Important
33
+
34
+ * This script and its author(s) are not affiliated/associated with the main
35
+ Anki project in any way.
36
+ * Use this software entirely at your own risk. Frequent backups are encouraged.
37
+
38
+ ### Table of Contents
39
+
40
+ * [Install instructions](#install-instructions)
41
+ * [Usage](#usage)
42
+ * [Configuration](#configuration)
43
+ * [Zsh completion](#zsh-completion)
44
+ * [Changelog](#changelog)
45
+ * [Relevant resources](#relevant-resources)
46
+ * [Alternatives](#alternatives)
47
+
48
+ ## Install instructions
49
+
50
+ `apy` can be installed in the "usual" way with `pip`:
51
+
52
+ ```bash
53
+ pip install apyanki
54
+ ```
55
+
56
+ **However**, note that installing Python packages outside [virtual
57
+ environments](https://docs.python.org/3/library/venv.html) is not recommended,
58
+ even at the user level! If you do this, then be aware that you may experience
59
+ issues due to conflicts with other packages/tools installed in the same manner.
60
+
61
+ Instead, the best way to install `apy` for normal usage is with
62
+ [`pipx`](https://pypa.github.io/pipx/). This will ensure `apy` doesn't
63
+ interfere with other Python packages already on your system.
64
+
65
+ If you don't already have `pipx`, install it with your distribution's package
66
+ manager. For instance, on Ubuntu:
67
+
68
+ ```bash
69
+ sudo apt update
70
+ sudo apt install pipx
71
+ ```
72
+
73
+ Then, install `apy` with:
74
+
75
+ ```bash
76
+ pipx install apyanki
77
+ ```
78
+
79
+ ### Requirements
80
+
81
+ `apy` should work for Python 3.9 and later.
82
+
83
+ Technically, `apy` does **not** depend on any existing Anki installation, since
84
+ it pulls in a copy of the non-GUI components of Anki as a separate dependency.
85
+ However, you still need to have an Anki database with collections and profile
86
+ settings already existing on your machine, since `apy` can't create one from
87
+ nothing.
88
+
89
+ ## Usage
90
+
91
+ ```sh
92
+ apy --help
93
+ ```
94
+
95
+ Some examples:
96
+
97
+ ```sh
98
+ # Add card with interactive editor session
99
+ apy add
100
+
101
+ # Add single card with specified preset (see configuration for more info on
102
+ # presets)
103
+ apy add-single -s preset "Question/Front" "Answer/Back"
104
+
105
+ # List leech cards (will show cid values for each card). Note that the query
106
+ # should be similar to a search query in the Anki browser.
107
+ apy list -v tag:leech
108
+
109
+ # Review and possibly edit file with given cid
110
+ apy review cid:12345678
111
+ ```
112
+
113
+ `apy` can be combined with editor specific configuration and workflows to
114
+ improve the process of adding and editing cards. For more information about
115
+ this, see [the Wiki](https://github.com/lervag/apy/wiki/Vim).
116
+
117
+ ## Configuration
118
+
119
+ `apy` loads configuration from `~/.config/apy/apy.json`. The following keys are
120
+ currently recognized:
121
+
122
+ - `base_path`: Specify where `apy` should look for your Anki database. This is
123
+ usually something like `/home/your_name/.local/share/Anki2/`.
124
+ - `img_viewers`: Specify a dictionary of image viewer commands. Each key is
125
+ a file extension. The value is a command list, e.g. `['display', 'density',
126
+ '300']` which specifies the command and its options to use for the
127
+ corresponding key (file extension).
128
+ - `img_viewers_default`: Specify the default command to show an image. Must be
129
+ provided as a list of the command and desired options, such as `['feh',
130
+ '-d']`.
131
+ - `markdown_models`: Specify a list of models for which `apy` will use
132
+ a markdown converter.
133
+ - `pngCommands`/`svgCommands`: Set LaTeX commands to generate PNG/SVG files.
134
+ This is inspired by the [Edit LaTeX build
135
+ process](https://ankiweb.net/shared/info/937148547) addon to Anki.
136
+ - `presets`: Specify preset combination of model and tags for use with `apy
137
+ add-single`.
138
+ - `profile_name`: Specify which profile to load by default.
139
+ - `query`: Specify default query for `apy list`, `apy review` and `apy tag`.
140
+ - `review_show_cards`: Whether to show list of cards by default during note
141
+ review
142
+
143
+ An example configuration:
144
+
145
+ ```json
146
+ {
147
+ "base_path": "/home/your_name/.local/share/Anki2/",
148
+ "profile_name": "MyAnkiProfile",
149
+ "query": "tag:leech",
150
+ "presets": {
151
+ "default": { "model": "Custom", "tags": ["marked"] }
152
+ },
153
+ "pngCommands": [
154
+ ["latex", "-interaction=nonstopmode", "tmp.tex"],
155
+ ["dvipng", "-D", "150", "-T", "tight", "-bg", "Transparent",
156
+ "tmp.dvi", "-o", "tmp.png"]
157
+ ],
158
+ "svgCommands": [
159
+ ["lualatex", "-interaction=nonstopmode", "tmp.tex"],
160
+ ["pdfcrop", "tmp.pdf", "tmp.pdf"],
161
+ ["pdf2svg", "tmp.pdf", "tmp.svg"]
162
+ ],
163
+ "review_show_cards": true
164
+ }
165
+ ```
166
+
167
+ ## Zsh completion
168
+
169
+ There is also a zsh completion file available. To use it, one may symlink or
170
+ copy it to a location that is already in ones `fpath` variable, or one may add
171
+ the `apy/completion` directory to the `fpath` list.
172
+
173
+ As an example, one may first symlink the `_apy` file:
174
+
175
+ ```sh
176
+ mkdir -p ~/.local/zsh-functions
177
+ ln -s /path/to/apy/completion/_apy ~/.local/zsh-functions
178
+ ```
179
+
180
+ Then add the following line to ones `.zshrc` file:
181
+
182
+ ```sh
183
+ fpath=($HOME/.local/zsh-functions $fpath)
184
+ ```
185
+
186
+ ## Changelog
187
+
188
+ See the [release history on GitHub](https://github.com/lervag/apy/releases).
189
+ For details, feel free to inspect the commity history.
190
+
191
+ ## Relevant resources
192
+
193
+ Here are a list of relevant resources for learning how to work with the Anki
194
+ databases and code:
195
+ * [AnkiDroid: Database
196
+ Structure](https://github.com/ankidroid/Anki-Android/wiki/Database-Structure)
197
+ * [AnkiConnect.py](https://github.com/FooSoft/anki-connect/blob/master/AnkiConnect.py)
198
+ * [The Anki Manual](https://docs.ankiweb.net)
199
+
200
+ ## Alternatives
201
+
202
+ Here are some alternatives to `apy` from which I've drawn inspiration. I've
203
+ also added a short note on why I did not just settle for the alternative.
204
+
205
+ ### Ankiconnect
206
+
207
+ [Ankiconnect](https://foosoft.net/projects/anki-connect/) is an Anki plugin [2055492159](https://ankiweb.net/shared/info/2055492159)) hosted on [github](https://github.com/FooSoft/anki-connect).
208
+
209
+ > Ankiconnect enables external applications to communicate with Anki over
210
+ > a network interface. The exposed API makes it possible to execute queries
211
+ > against the user’s card deck, automatically create new vocabulary and Kanji
212
+ > flash cards, and more.
213
+
214
+ A couple of relevant applications that use Ankiconnect:
215
+
216
+ * [Anki Quick Adder](https://codehealthy.com/chrome-anki-quick-adder/):
217
+ A Chrome extension to add words to Anki desktop quickly.
218
+
219
+ * [Anki-editor](https://github.com/louietan/anki-editor) is an emacs plugin for
220
+ making Anki cards with Org.
221
+
222
+ * [anki-cli](https://github.com/towercity/anki-cli) is a simple nodejs based
223
+ command-line interface for Anki.
224
+
225
+ * [trrc](https://github.com/Constantin1489/trrc) is a command-line program to
226
+ add a card to Anki using AnkiConnect API.
227
+
228
+ _The Dealbreaker_: I wanted a script that does not require Anki to be running.
229
+
230
+ ### Anki::Import - Anki note generation made easy
231
+
232
+ [Anki::Import](https://github.com/sdondley/Anki-Import) (see also
233
+ [here](https://metacpan.org/pod/Anki::Import)) allows one to "Efficiently
234
+ generate Anki notes with your text editor for easy import into Anki". Quote:
235
+
236
+ > Inputting notes into Anki can be a tedious chore. Anki::Import lets you you
237
+ > generate Anki notes with your favorite text editor (e.g. vim, BBEdit, Atom,
238
+ > etc.) so you can enter formatted notes into Anki's database more
239
+ > efficiently.
240
+
241
+ _The Dealbreaker_: This sounds very good, except there are too many steps.
242
+ I didn't want to have to open Anki desktop. It should work flawlessly directly
243
+ from the terminal.
244
+
245
+ ### AnkiVim
246
+
247
+ [AnkiVim](https://github.com/MFreidank/AnkiVim) may be used to "Use vim to
248
+ rapidly write textfiles immediately importable into anki(1)."
249
+
250
+ _The Dealbreaker_: Similar to `Anki::Import`: I didn't want to have to open
251
+ Anki desktop. It should work flawlessly directly from the terminal.
252
+
253
+ ### Knowledge (Vim plugin)
254
+
255
+ [Knowledge](https://github.com/tbabej/knowledge) is a Vim plugin for generating
256
+ flash cards to either Anki or Mnemosyne.
257
+
258
+ _The Dealbreaker_: It has [a single, open
259
+ issue](https://github.com/tbabej/knowledge/issues/1), which seems to indicate
260
+ that the application does not work very well and/or is not well maintained.
261
+
262
+ ### Ankisync
263
+
264
+ [Ankisync](https://github.com/patarapolw/ankisync) seems somewhat promising, in
265
+ that it exposes an API for working with Anki collections from Python. It is
266
+ a successor to [AnkiTools](https://github.com/patarapolw/AnkiTools), which is
267
+ stated to be "an Anki *.apkg and collection.anki2 reader and editor".
268
+
269
+ _The Dealbreaker_: It does not include any features to add or edit notes (as
270
+ far as I could tell).
271
+
272
+ ### Genanki
273
+
274
+ [Genanki](https://github.com/kerrickstaley/genanki) is a library for generating
275
+ Anki decks.
276
+
277
+ _The Dealbreaker_: It is quite close to being something I wanted, except that
278
+ it needs to run as a plugin to Anki desktop to generate notes to a local
279
+ collection. It does not seem to allow editing/adding to a local collection
280
+ outside of Anki desktop.
281
+
282
+ ### inka
283
+
284
+ [inka](https://github.com/lazy-void/inka) is a CLI utility for adding
285
+ flashcards from Markdown files to Anki.
286
+
287
+ _The Dealbreaker_: This did not exist when apy was created. It seems to be
288
+ close to what I would personally be interested in, but today I find apy solves
289
+ all (or most) of my requirements. Also, `inka` requires the AnkiConnect plugin.
290
+
291
+ ### Obsidian_to_Anki
292
+
293
+ [Obsidian_to_Anki](https://github.com/Pseudonium/Obsidian_to_Anki) is a plugin to add flashcards from a text or markdown file to Anki. It can also be run from the command-line as a python script. Built with Obsidian markdown syntax in mind.
294
+
295
+ _The Dealbreaker_: Requires AnkiConnect.
296
+
297
+ ### Markdown2Anki
298
+
299
+ [Markdown2Anki](https://github.com/Mochitto/Markdown2Anki) is a Python script that allows you to easily format your cards
300
+ using Markdown syntax, and then import them into Anki while retaining the
301
+ structure you gave them.
302
+
303
+ As many other alternatives, you need to manually import cards. It may provide
304
+ support for AnkiConnect.
305
+
306
+ ## Contributing
307
+
308
+ The following is a short and simple guide to getting started with contributing
309
+ and developing the `apy` code.
310
+
311
+ ### Setup
312
+
313
+ This project uses [Poetry](https://python-poetry.org/) as the build system and
314
+ to manage dependencies.
315
+
316
+ Install Poetry first if you don't have it already. Fork the repository, then
317
+ clone your fork and install a local development build of the project using
318
+ Poetry.
319
+
320
+ ```sh
321
+ # Clone the forked repo
322
+ git clone git@github.com:<username>/apy.git
323
+ cd apy/
324
+
325
+ # Install the project with Poetry
326
+ poetry install
327
+ ```
328
+
329
+ Poetry will create a virtual environment for you (see
330
+ [here](https://python-poetry.org/docs/configuration/#virtualenvsin-project) for
331
+ where the environment is created). You can either activate this environment
332
+ yourself then issue commands in the usual way, or you can prefix your commands
333
+ with `poetry run`. Example:
334
+
335
+ ```sh
336
+ poetry run apy --version
337
+ ```
338
+
339
+ ### Tests
340
+
341
+ To run the tests, activate the virtual environment and run:
342
+
343
+ ```sh
344
+ pytest
345
+ ```
346
+
347
+ Alternatively, without activating the environment:
348
+
349
+ ```sh
350
+ poetry run pytest
351
+ ```
352
+
353
+ ### Linting
354
+
355
+ To format the code, run:
356
+
357
+ ```sh
358
+ poetry run black .
359
+ ```
360
+
361
+ To type-check the code, run:
362
+
363
+ ```sh
364
+ poetry run mypy src
365
+ ```
366
+