Skip to main content

Compare generated Anki APKG files with a live Anki collection.

Project description

anki-collection-diff

PyPI

anki-collection-diff compares APKG files on disk with the live Anki collection through AnkiConnect.

It is meant for generated deck projects where the build output is an .apkg, and you want a cheap repeatable audit of what differs from the copy currently installed in Anki.

The library is intentionally cheap: it reads the package SQLite database and media manifest, fetches only the selected live deck through AnkiConnect, and reports structural differences. It does not render cards and it never writes to Anki.

What It Can Compare

  • note and card counts
  • added and missing notes
  • note field values, keyed by stable fields
  • model field order and field names
  • card template fronts and backs
  • shared note-type CSS
  • card counts by model/template
  • APKG media files missing from the live collection media folder

Quick Start

Install from PyPI:

python -m pip install anki-collection-diff

Anki must be open with AnkiConnect enabled.

anki-collection-diff inspect-apkg ../brazil-ddd-codes/out/brazil-ddd-codes.apkg

Then compare the APKG to the live deck. Pass a stable key field when note ids are not expected to match between the package and your collection:

anki-collection-diff compare-apkg \
  ../brazil-ddd-codes/out/brazil-ddd-codes.apkg \
  --deck-name "Brazilian DDD Codes" \
  --key-field ddd_code

Deck selection can come from:

  • --deck-name
  • ANKI_COLLECTION_DIFF_DECK, or a custom --deck-env
  • --deck-agent codex or --deck-agent claude, which asks the installed CLI to choose from APKG candidate deck names and live deck names
  • exact automatic match when the APKG has a single unambiguous deck candidate

Runtime Permissions

APKG inspection is offline and only reads the package file.

APKG-vs-live comparison requires:

  • Anki running locally
  • AnkiConnect installed and reachable at http://127.0.0.1:8765
  • permission for the process to open localhost HTTP connections

When running from Codex Desktop or another sandboxed agent, filesystem access to the project may not imply network access to AnkiConnect. If localhost requests fail from Python with "Could not reach AnkiConnect" while curl or the Anki UI looks healthy, rerun the comparison with the agent's unsandboxed/escalated permission flow.

The optional --deck-agent codex and --deck-agent claude modes shell out to the corresponding CLI. They do not require this package to know API keys, but the chosen CLI must already be installed, authenticated, and allowed to access its normal state directory and model service. For Codex CLI this commonly means access to ~/.codex, session files, and the network. If the installed Codex CLI rejects a local service_tier config value, pass a CLI config override when you run Codex directly, or fix the user-level Codex config before using --deck-agent codex.

For repeatable audits, put APKG targets in a TOML config:

anki-collection-diff audit --config examples/brazil-ddd-codes.toml

By default, diff commands exit with status 1 when differences are found so they can be used in scripts. Add --no-fail-on-diff for exploratory runs.

Library Use

from pathlib import Path

from anki_collection_diff.ankiconnect import AnkiConnectClient
from anki_collection_diff.apkg import load_apkg_snapshot
from anki_collection_diff.diff import compare_collection_snapshots

client = AnkiConnectClient()
apkg = load_apkg_snapshot(Path("out/my-deck.apkg"))
live = client.fetch_deck_snapshot("My Deck")
report = compare_collection_snapshots(apkg, live, key_fields=("slug",))

print(report.to_markdown())

Design Boundary

This project is a diff library, not a deck authoring or sync framework. Write-back commands should live elsewhere until a repeated workflow proves they belong here. Project-specific source workflows, such as Markdown bidirectional sync or local AnkiConnect rollout snapshots, should remain in those projects.

Releasing

Releases are published to PyPI by GitHub Actions when a version tag is pushed. The workflow uses PyPI Trusted Publishing, so there is no PyPI token in the repository.

One-time PyPI setup:

  • Project name: anki-collection-diff
  • Owner: elvis-sik
  • Repository: anki-collection-diff
  • Workflow: workflow.yml
  • Environment: pypi

Release checklist:

make check
make build
make twine-check
git tag v0.1.0
git push origin main v0.1.0

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

anki_collection_diff-0.1.0.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

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

anki_collection_diff-0.1.0-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: anki_collection_diff-0.1.0.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for anki_collection_diff-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3c4d523b4a43e770cd2ff5680eab5511a9630f1314f2e18fad320b339a77b1fb
MD5 33e899e0ae74637a5c1399398d6d2874
BLAKE2b-256 dcc09a8bb95d2d205e758a8d9cb04bbb13ab178ff90a49966acbaf4b73653c7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for anki_collection_diff-0.1.0.tar.gz:

Publisher: workflow.yml on elvis-sik/anki-collection-diff

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for anki_collection_diff-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 024dc3558daa61d5047d2f80ccf0391b3842007434a0c40d0aa0ceac65e19496
MD5 5c79719aae9880d2d5da916e5601abfd
BLAKE2b-256 8156e9c02e5a00c9371167a0a764f7fcdd428a7c25e2be799de222828f10d45e

See more details on using hashes here.

Provenance

The following attestation bundles were made for anki_collection_diff-0.1.0-py3-none-any.whl:

Publisher: workflow.yml on elvis-sik/anki-collection-diff

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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