Skip to main content
Open Spaced Repetition logo

Anki SM-2

🌟 Anki's legacy SM-2-based spaced repetition algorithm 🌟


Python package implementing Anki's SM-2-based algorithm for spaced repetition scheduling.

Installation

You can install the anki-sm-2 python package from PyPI using pip:

pip install anki-sm-2

Quickstart

Import and initialize the Anki SM-2 Scheduler

from anki_sm_2 import Scheduler, Card, Rating

scheduler = Scheduler()

Create a new Card object

card = Card()

Choose a rating and review the card

"""
Rating.Again # (==0) forgot the card
Rating.Hard # (==1) remembered the card, but with serious difficulty
Rating.Good # (==2) remembered the card after a hesitation
Rating.Easy # (==3) remembered the card easily
"""

rating = Rating.Good

card, review_log = scheduler.review_card(card, rating)

print(f"Card rated {review_log.rating} at {review_log.review_datetime}")
# > Card rated 3 at 2024-10-31 01:36:57.080934+00:00

See when the card is due next

from datetime import datetime, timezone

due = card.due

# how much time between when the card is due and now
time_delta = due - datetime.now(timezone.utc)

print(f"Card due: at {due}")
print(f"Card due in {time_delta.seconds / 60} minutes")
# > Card due: at 2024-10-31 01:46:57.080934+00:00
# > Card due in 9.983333333333333 minutes

Usage

Timezone

Anki SM-2 uses UTC time only. You can still specify custom datetimes, but they must be UTC.

from anki_sm_2 import Scheduler, Card, Rating, ReviewLog
from datetime import datetime, timezone

scheduler = Scheduler()

# create a new card to be due on Jan. 1, 2024
card = Card(due=datetime(2024, 1, 1, 0, 0, 0, 0, timezone.utc)) # right
#card = Card(due=datetime(2024, 1, 1, 0, 0, 0, 0)) # wrong

# review the card on Jan. 2, 2024
card, review_log = scheduler.review_card(card=card, rating=Rating.Good, review_datetime=datetime(2024, 1, 2, 0, 0, 0, 0, timezone.utc)) # right
#card, review_log = scheduler.review_card(card=card, rating=Rating.Good, review_datetime=datetime(2024, 1, 2, 0, 0, 0, 0)) # wrong

Serialization

Scheduler, Card and ReviewLog objects are all json-serializable via their to_dict and from_dict methods for easy database storage:

# serialize before storage
scheduler_dict = scheduler.to_dict()
card_dict = card.to_dict()
review_log_dict = review_log.to_dict()

# deserialize from dict
scheduler = Scheduler.from_dict(scheduler_dict)
card = Card.from_dict(card_dict)
review_log = ReviewLog.from_dict(review_log_dict)

Versioning

This python package is currently unstable and adheres to the following versioning scheme:

  • Minor version will increase when a backward-incompatible change is introduced.
  • Patch version will increase when a bug is fixed, a new feature is added or when anything else backward compatible warrants a new release.

Once this package is considered stable, the Major version will be bumped to 1.0.0 and will follow semver.

Contribute

Checkout CONTRIBUTING to help improve Anki SM-2!

Official implementation

You can find the code for Anki's official Rust-based scheduler here.

Metadata

Release files for anki-sm-2 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for anki-sm-2 0.2.0
File Size Uploaded Provenance
anki_sm_2-0.2.0.tar.gz 46.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for anki-sm-2 0.2.0
File Interpreter ABI Platform
anki_sm_2-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 77.7 kB

Release files / anki_sm_2-0.2.0.tar.gz

Download URL anki_sm_2-0.2.0.tar.gz
Size 46.0 kB
Tags Source
SHA-256 checksum
How to use checksums
777accca948fefe0f61e652e83ba4daf326c1aec8807e35537dd8316401a93b2
BLAKE2b-256 checksum
How to use checksums
4fdf3aedea17440fcd4ad9d3a40a353882195dab7349492c8abd14c96f5d4a96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.21

Release files / anki_sm_2-0.2.0-py3-none-any.whl

Download URL anki_sm_2-0.2.0-py3-none-any.whl
Size 31.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8173bd14da4137c86a7c5f1a61a99afa8806ea37bb5642e979165c784ef0eac5
BLAKE2b-256 checksum
How to use checksums
d34748ee9326eac9961e5b70373b3e028dbdc6a6f53beb201a8a074300a87b0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.21

Security for anki-sm-2 0.2.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page