Anki SQLAlchemy is an interface for interacting with the Anki sqlite database from python without having to either hack an Anki install or figure out the database structure and field serialization from scratch.
The goal of this project is not to support every version of Anki entirely. The current version supports at a signficant amount of the Anki 2.1.38.
Here is a small code snippet written first without anki_sqlalchemy to show
how unintuivite the data format and columns names are without an wrapper.
# plain python without anki-sqlalchemy
import sqlite3
conn = sqlite3.connect('backup.db')
cursor = conn.execute("SELECT id, tags FROM notes WHERE mod >= ?", [1445394366])
note = cursor.fetchone()
note[0] # 1428143940996
note[1] # ' edit math probability wikipedia '
cursor = conn.execute("SELECT mod, type FROM cards WHERE nid = ?", [nid])
card = cursor.fetchone()
card[0] # 1445394366
card[1] # 2
# with anki-sqlalchemy
import datetime
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from anki_sqlalchemy import Card
engine = create_engine("sqlite:///backup.db", echo=True)
Session = sessionmaker(bind=engine)
session = Session()
note = session.query(Note).filter(Note.modification_time >= datetime.datetime(2017, 2, 5, 21, 29, 49)).first()
note.id # 1428143940996
note.modification_time # datetime.datetime(2017, 2, 5, 21, 29, 49)
card = note.cards[0]
card.modification_time # datetime.datetime(2019, 11, 5, 22, 23, 3)
card.type # <CardType.due: 2>
Anki SQLAlchemy also plays nicely with types too.
card: Card = session.query(Card).first()
reveal_type(card.modification_time)
# Revealed type is 'datetime.datetime*'
reveal_type(card.note.tags)
# Revealed type is 'builtins.list*[builtins.str]'
BEWARE!
This package can be used to make changes to your anki database. Before proceeding, please make a backup of your database file. You don't want to lose all your work with a bad query.
The Anki database typically lives in a collection.anki2 file.
Install
pip install anki_sqlalchemy
Metadata
Release files for anki-sqlalchemy 0.3.0
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 | Actions |
|---|---|---|---|---|
| anki-sqlalchemy-0.3.0.tar.gz | 7.0 kB | Without provenance | Details for anki-sqlalchemy-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| anki_sqlalchemy-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for anki_sqlalchemy-0.3.0-py3-none-any.whl |
Total release size: 14.5 kB
Release files / anki-sqlalchemy-0.3.0.tar.gz
| Download URL | anki-sqlalchemy-0.3.0.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5307127713416f1a0b47e5d28c9ccefb9e03b4f14eb668e9989b5b3180907b5d
|
|
BLAKE2b-256 checksum How to use checksums |
886e32e9a8039e967931ba83174c89f5751fc0eb0ad8a54dc02edefe890fd428
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
|
Release files / anki_sqlalchemy-0.3.0-py3-none-any.whl
| Download URL | anki_sqlalchemy-0.3.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
31b01dd3e6f6d1a506e911a15fee9615017a22dd8448dcf95d021513879b7090
|
|
BLAKE2b-256 checksum How to use checksums |
f1cef32218eff44f0aa94c470c91328eeeded18752339791adbc30035d0ee77e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.6
|
Security for anki-sqlalchemy 0.3.0
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.