Skip to main content

A spaced repetition Python library.

Project description

SpacedRepPy

Build status Python Version License Code style: ruff Security: bandit Pre-commit Coverage Report

A spaced repetition Python library implementing SM-2, Leitner, and FSRS-6 algorithms.

Installation

Use uv or pip to install spacedreppy.

uv add spacedreppy
# or
pip install spacedreppy

Usage

SM-2

from datetime import datetime, timezone
from spacedreppy import SM2Scheduler

scheduler = SM2Scheduler()

# Each call returns the next due timestamp and interval.
due_timestamp, interval = scheduler.compute_next_due_interval(
    attempted_at=datetime.now(timezone.utc), result=4
)

The result parameter is a quality score from the SM-2 algorithm:

Score Meaning
0 Complete blackout — no recall at all
1 Incorrect response, but the correct answer seemed easy to recall once seen
2 Incorrect response, but the correct answer was remembered upon seeing it
3 Correct response with serious difficulty
4 Correct response after some hesitation
5 Perfect response with no hesitation

Scores of 3 or higher count as correct and advance the repetition schedule. Scores below 3 reset the interval.

Leitner System

from datetime import datetime, timezone
from spacedreppy import LeitnerScheduler

scheduler = LeitnerScheduler()

# result=1 for correct, result=0 for incorrect
due_timestamp, interval = scheduler.compute_next_due_interval(
    attempted_at=datetime.now(timezone.utc), result=1
)

The result parameter is a binary score:

Score Meaning
0 Incorrect
1 Correct

Correct answers promote the card to the next box; incorrect answers send it back to the first box. The default box intervals (in days) are [1, 3, 7, 14, 30], but you can provide your own:

scheduler = LeitnerScheduler(intervals=[2, 5, 10])

FSRS-6

from datetime import datetime, timezone
from spacedreppy import FSRSScheduler

scheduler = FSRSScheduler()

# result: 1=Again, 2=Hard, 3=Good, 4=Easy
due_timestamp, interval = scheduler.compute_next_due_interval(
    attempted_at=datetime.now(timezone.utc), result=3
)

The result parameter is a rating from the FSRS algorithm:

Rating Meaning
1 (Again) Forgot the card
2 (Hard) Remembered with serious difficulty
3 (Good) Remembered after some hesitation
4 (Easy) Remembered easily

FSRS-6 models memory with Stability (S) and Difficulty (D), using a power-law forgetting curve with 21 trainable parameters. You can customize the scheduler:

scheduler = FSRSScheduler(
    request_retention=0.85,   # target retention (default: 0.9)
    maximum_interval=365,     # max interval in days (default: 36500)
)

Custom model weights (e.g., from the FSRS optimizer) can also be provided:

scheduler = FSRSScheduler(weights=my_optimized_weights)

Development

This project uses uv for dependency management and just as a command runner.

# Install dependencies
just install

# Run tests
just test

# Run formatters
just codestyle

# Run all linting (tests + style + mypy + safety)
just lint

License

MIT

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

spacedreppy-0.5.0.tar.gz (71.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spacedreppy-0.5.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file spacedreppy-0.5.0.tar.gz.

File metadata

  • Download URL: spacedreppy-0.5.0.tar.gz
  • Upload date:
  • Size: 71.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spacedreppy-0.5.0.tar.gz
Algorithm Hash digest
SHA256 9cead9e799c7f75652c991c0ff09a4b1adb253158368a2ac7513e3adeda4d504
MD5 a1bbacf571a581eb7fe8f1cb28901e94
BLAKE2b-256 8398fabe9b2fc172cf3b1207d7bc33d78bc8f592aa92e3dd554ed0b8eb80300f

See more details on using hashes here.

Provenance

The following attestation bundles were made for spacedreppy-0.5.0.tar.gz:

Publisher: publish.yml on lschlessinger1/spacedreppy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spacedreppy-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: spacedreppy-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for spacedreppy-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8106b69c4c0eb81499dcd81b4e05f181e07c3e2172227028752ed45d905589c
MD5 a80d116a8d4bfb06927773c5beca250e
BLAKE2b-256 d25e9ec7753d94cacc0fc2daf633a5a81acf34f6b0924bdbbe9e4986eb425cb5

See more details on using hashes here.

Provenance

The following attestation bundles were made for spacedreppy-0.5.0-py3-none-any.whl:

Publisher: publish.yml on lschlessinger1/spacedreppy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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