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.1.0.tar.gz (4.8 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.1.0-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ankiapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4f77f80fbd8e71e93d23da139b68262a98cc79819d8a4a01420ae6370f8452fd
MD5 4077bd62cb0f4dca2645b6fc3430d578
BLAKE2b-256 b9afd34d84007d8d465356755cb2c611b3871038bc180af95b28576687af9154

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ankiapi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.0 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc51fd998152bdc3e1b4807f4bddcc984af5f6d2d53dc505eafdbcefce858c3e
MD5 f94039359343ccbe63dada9d1282efe2
BLAKE2b-256 0d9ce075e0bd4241d505f7a16c8afc54dffe45ca7bbada4e1fd02b6d672ff472

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