Skip to main content

SM-2 spaced repetition scheduler

Project description

sm-2

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

Quickstart

Import and initialize the SM-2 scheduler

from sm_2 import SM2Scheduler, Card, ReviewLog

scheduler = SM2Scheduler()

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 SM2Scheduler, Card, ReviewLog
from datetime import datetime, timezone

scheduler = SM2Scheduler()

# create a new card on Jan. 1, 2024
card = Card(created_at=datetime(2024, 1, 1, 0, 0, 0, 0, timezone.utc)) # right
#card = Card(created_at=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=5, review_datetime=datetime(2024, 1, 1, 0, 0, 0, 0, timezone.utc)) # right
#card, review_log = scheduler.review_card(card=card, rating=5, review_datetime=datetime(2024, 1, 1, 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.

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

sm_2-0.1.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

sm_2-0.1.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sm_2-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for sm_2-0.1.0.tar.gz
Algorithm Hash digest
SHA256 67193e8ab4e7434a5c0daf43dd0d0fd0fd2af3128462b4cb9f5373aaf280cfa2
MD5 bd46e6cbe6be4bfce8b487bf915e806d
BLAKE2b-256 c5330a10b758bde6becfe65a80687cde68758c0d8a4d5e62096b364da4e857f9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sm_2-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for sm_2-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90277601d3d84372c7eed21526ab11ea9763e56bacdc6783c202ee54323acb17
MD5 c91e1f63cc8c3549367c4a13ecdc6b46
BLAKE2b-256 a460c770f61dd6935a08208a340f675dbd62c510798e23113ab3d3adc731388d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page