AnkiAPI
A simple Python wrapper for interacting with the AnkiConnect API to create and manage Anki flashcards programmatically.
Overview
AnkiAPI provides a clean interface to interact with Anki through the AnkiConnect add-on. It allows you to:
- Create new decks
- Add flashcards to decks
- Add audio media to Anki
- Test connectivity to the Anki application
Prerequisites
- Anki application installed
- AnkiConnect add-on installed in Anki
Installation
pip install ankiapi
Or with Poetry:
poetry add ankiapi
Usage
Basic Example
from ankiapi import AnkiApi
# Initialize the API (make sure Anki is running with AnkiConnect add-on)
anki = AnkiApi()
# Create a new deck
anki.create_deck("Python Programming")
# Add a flashcard
anki.add_flashcard(
deck_name="Python Programming",
front="What is a Python list comprehension?",
back="A concise way to create lists using a single line of code with a for loop and optional conditions."
)
Adding Audio to Anki
# Add an audio file
anki.add_audio(
path="/path/to/audio/file.mp3",
filename="pronunciation.mp3"
)
API Reference
AnkiApi
AnkiApi(url="http://localhost:8765", version=6)
The main class for interacting with the AnkiConnect API.
Parameters
url(str): The URL of the AnkiConnect API. Default is "http://localhost:8765".version(int): The version of the AnkiConnect API. Default is 6.
Methods
check_server()
Checks whether the AnkiConnect server is running.
create_deck(deck_name)
Creates a new deck in Anki if it doesn't already exist.
deck_name(str): The name of the deck to create.
add_flashcard(deck_name, front, back)
Adds a flashcard to the specified deck in Anki.
deck_name(str): The name of the deck to add the card to.front(str): The content for the front side of the card.back(str): The content for the back side of the card.
add_audio(path, filename)
Adds media content to Anki.
path(str): The path to the media file.filename(str): The filename to use for the media file in Anki.
Troubleshooting
- Make sure Anki is running before using the API
- Ensure AnkiConnect add-on is properly installed
- Check that you're using the correct port (default: 8765)
License
See the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Metadata
Release files for ankiapi 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ankiapi-0.2.1.tar.gz | 4.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ankiapi-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.7 kB
Release files / ankiapi-0.2.1.tar.gz
| Download URL | ankiapi-0.2.1.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b12e8e926d394aa17a1daa441ba206a1b976ca295b98ba5ec0af22d40aa71d89
|
|
BLAKE2b-256 checksum How to use checksums |
bf5336115225b6ac71217ade6e1b949354020ac697a3dd133a7ebb0c170d0460
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|
Release files / ankiapi-0.2.1-py3-none-any.whl
| Download URL | ankiapi-0.2.1-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
47179439f904de6358493712a6ebd4bcb22894dd49c35e318d67eace8bd3e110
|
|
BLAKE2b-256 checksum How to use checksums |
83901695275093aa2ffe0ab401ae5a17c610ef6a9dbc968844ca02f321eba4d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.10
|
Security for ankiapi 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.