Skip to main content
Open Spaced Repetition logo

SM-2

🧠🔄 Build your own Spaced Repetition System in Python 🧠🔄


Python package implementing the classic SM-2 algorithm for spaced repetition scheduling.

Installation

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

pip install sm-2

Quickstart

Import and initialize the SM-2 scheduler

from sm_2 import Scheduler, Card, ReviewLog

scheduler = Scheduler()

Create a new Card object

card = Card()

Choose a rating and review the card

"""
5 - perfect response
4 - correct response after a hesitation
3 - correct response recalled with serious difficulty
2 - incorrect response; where the correct one seemed easy to recall
1 - incorrect response; the correct one remembered
0 - complete blackout.
"""

rating = 5

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

print(f"Card rated {review_log.rating} at {review_log.review_datetime}")
# > Card rated 5 at 2024-10-24 02:14:20.802958+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 {repr(due)}")
print(f"Card due in {time_delta.seconds / 3600} hours")
# > Card due: at datetime.datetime(2024, 10, 25, 2, 14, 20, 799320, tzinfo=datetime.timezone.utc)
# > Card due in 23.99972222222222 hours

Usage

Timezone

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

from sm_2 import Scheduler, Card, ReviewLog
from datetime import datetime, timezone

scheduler = Scheduler()

# create a new due card 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

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

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

# deserialize from 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 or a new feature is added.

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 sm-2!

Metadata

Release files for sm-2 0.3.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 sm-2 0.3.0
File Size Uploaded
sm_2-0.3.0.tar.gz 7.0 kB Details

Built distribution (wheel)

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

Total release size: 13.6 kB

Release files / sm_2-0.3.0.tar.gz

Download URL sm_2-0.3.0.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
35943918a81720b18ae90bde712b812429c6afe967d1d171462aa239baa46d50
BLAKE2b-256 checksum
How to use checksums
ac2f23951eb5d7fa300d2d614a86a432103ea947bf4d1ad4d67d3fd8c062fa83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.21

Release files / sm_2-0.3.0-py3-none-any.whl

Download URL sm_2-0.3.0-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
031864c89dad9c681786016ff616df1cdb6826f9a5b3ac98fcece95c424c4333
BLAKE2b-256 checksum
How to use checksums
32dd746fa57b583019f337d5a9cc9f05d2c37e5c4ebd6e2f8f60fae8815fb7ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.9.21

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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