Skip to main content

A simple Python wrapper for interacting with the AnkiConnect API

Project description

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

  1. Anki application installed
  2. 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

  1. Make sure Anki is running before using the API
  2. Ensure AnkiConnect add-on is properly installed
  3. 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ankiapi-0.2.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ankiapi-0.2.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file ankiapi-0.2.1.tar.gz.

File metadata

  • Download URL: ankiapi-0.2.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for ankiapi-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b12e8e926d394aa17a1daa441ba206a1b976ca295b98ba5ec0af22d40aa71d89
MD5 e60eab388adabca2f24866af651b6846
BLAKE2b-256 bf5336115225b6ac71217ade6e1b949354020ac697a3dd133a7ebb0c170d0460

See more details on using hashes here.

File details

Details for the file ankiapi-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: ankiapi-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for ankiapi-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 47179439f904de6358493712a6ebd4bcb22894dd49c35e318d67eace8bd3e110
MD5 805c60437373f5fd483b61d30c2534e3
BLAKE2b-256 83901695275093aa2ffe0ab401ae5a17c610ef6a9dbc968844ca02f321eba4d2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page