{"id":15106933,"url":"https://github.com/alexriina/anki-sqlalchemy","last_synced_at":"2025-09-27T05:31:27.665Z","repository":{"id":54843287,"uuid":"277944966","full_name":"AlexRiina/anki-sqlalchemy","owner":"AlexRiina","description":"Python ORM for interacting with Anki's database. Aliases cryptic columns, parses confusing data structures. Designed to be the base of your Anki analysis project.","archived":true,"fork":false,"pushed_at":"2021-08-01T20:25:48.000Z","size":34,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-16T04:07:03.444Z","etag":null,"topics":["anki","python","sqlalchemy"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlexRiina.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-07T23:41:57.000Z","updated_at":"2023-01-27T22:35:15.000Z","dependencies_parsed_at":"2022-08-14T04:31:06.809Z","dependency_job_id":null,"html_url":"https://github.com/AlexRiina/anki-sqlalchemy","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexRiina%2Fanki-sqlalchemy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexRiina%2Fanki-sqlalchemy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexRiina%2Fanki-sqlalchemy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlexRiina%2Fanki-sqlalchemy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlexRiina","download_url":"https://codeload.github.com/AlexRiina/anki-sqlalchemy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234391380,"owners_count":18824809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["anki","python","sqlalchemy"],"created_at":"2024-09-25T21:03:25.505Z","updated_at":"2025-09-27T05:31:27.359Z","avatar_url":"https://github.com/AlexRiina.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![PyPi Version](https://img.shields.io/pypi/v/anki_sqlalchemy.svg)](https://pypi.python.org/pypi/anki_sqlalchemy/)\n\nAnki SQLAlchemy is an interface for interacting with the\n[Anki](https://apps.ankiweb.net/) sqlite database from python without having to\neither hack an Anki install or figure out the database structure and field\nserialization from scratch.\n\nThe goal of this project is not to support every version of Anki entirely. The\ncurrent version supports at a signficant amount of the Anki 2.1.38.\n\nHere is a small code snippet written first without `anki_sqlalchemy` to show\nhow unintuivite the data format and columns names are without an wrapper.\n\n```python\n# plain python without anki-sqlalchemy\nimport sqlite3\n\nconn = sqlite3.connect('backup.db')\ncursor = conn.execute(\"SELECT id, tags FROM notes WHERE mod \u003e= ?\", [1445394366])\nnote = cursor.fetchone()\nnote[0]  # 1428143940996\nnote[1]  # ' edit math probability wikipedia '\n\ncursor = conn.execute(\"SELECT mod, type FROM cards WHERE nid = ?\", [nid])\ncard = cursor.fetchone()\ncard[0]  # 1445394366\ncard[1]  # 2\n```\n\n```python\n# with anki-sqlalchemy\nimport datetime\nfrom sqlalchemy import create_engine\nfrom sqlalchemy.orm import sessionmaker\nfrom anki_sqlalchemy import Card\n\nengine = create_engine(\"sqlite:///backup.db\", echo=True)\nSession = sessionmaker(bind=engine)\nsession = Session()\n\nnote = session.query(Note).filter(Note.modification_time \u003e= datetime.datetime(2017, 2, 5, 21, 29, 49)).first()\nnote.id  # 1428143940996\nnote.modification_time  # datetime.datetime(2017, 2, 5, 21, 29, 49)\n\ncard = note.cards[0]\ncard.modification_time  # datetime.datetime(2019, 11, 5, 22, 23, 3)\ncard.type  # \u003cCardType.due: 2\u003e\n```\n\nAnki SQLAlchemy also plays nicely with types too.\n\n```python\ncard: Card = session.query(Card).first()\nreveal_type(card.modification_time)\n# Revealed type is 'datetime.datetime*'\n\nreveal_type(card.note.tags)\n# Revealed type is 'builtins.list*[builtins.str]'\n```\n\n# BEWARE!\n\nThis package can be used to make changes to your anki database. Before\nproceeding, please make a backup of your database file. You don't want to lose\nall your work with a bad query.\n\nThe Anki database typically lives in a `collection.anki2` file.\n\n# Install\n\n```\npip install anki_sqlalchemy\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexriina%2Fanki-sqlalchemy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexriina%2Fanki-sqlalchemy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexriina%2Fanki-sqlalchemy/lists"}