{"id":26988340,"url":"https://github.com/open-spaced-repetition/py-fsrs","last_synced_at":"2025-04-03T20:08:50.705Z","repository":{"id":64036912,"uuid":"571532439","full_name":"open-spaced-repetition/py-fsrs","owner":"open-spaced-repetition","description":"Python Package for FSRS","archived":false,"fork":false,"pushed_at":"2024-06-08T18:29:21.000Z","size":39,"stargazers_count":94,"open_issues_count":0,"forks_count":18,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-06-15T09:57:36.696Z","etag":null,"topics":["fsrs","python-library","spaced-repetition-algorithm"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/fsrs/","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/open-spaced-repetition.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-11-28T10:41:11.000Z","updated_at":"2024-07-08T03:00:10.870Z","dependencies_parsed_at":"2024-04-25T03:28:29.876Z","dependency_job_id":"b93c8f76-5faa-424c-93f4-146770cd5724","html_url":"https://github.com/open-spaced-repetition/py-fsrs","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-spaced-repetition%2Fpy-fsrs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-spaced-repetition%2Fpy-fsrs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-spaced-repetition%2Fpy-fsrs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/open-spaced-repetition%2Fpy-fsrs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/open-spaced-repetition","download_url":"https://codeload.github.com/open-spaced-repetition/py-fsrs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247070923,"owners_count":20878586,"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":["fsrs","python-library","spaced-repetition-algorithm"],"created_at":"2025-04-03T20:08:45.852Z","updated_at":"2025-04-03T20:08:50.684Z","avatar_url":"https://github.com/open-spaced-repetition.png","language":"Python","funding_links":[],"categories":["Implementation","Python"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://avatars.githubusercontent.com/u/96821265?s=200\u0026v=4\" height=\"100\" alt=\"Open Spaced Repetition logo\"/\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n\n# Py-FSRS\n\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cem\u003e🧠🔄 Build your own Spaced Repetition System in Python 🧠🔄   \u003c/em\u003e\n\u003c/div\u003e\n\u003cbr /\u003e\n\u003cdiv align=\"center\" style=\"text-decoration: none;\"\u003e\n    \u003ca href=\"https://pypi.org/project/fsrs/\"\u003e\u003cimg src=\"https://img.shields.io/pypi/v/fsrs\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/fsrs/\"\u003e\u003cimg src=\"https://img.shields.io/badge/python-3.10%2B-blue\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/open-spaced-repetition/py-fsrs/blob/main/LICENSE\" style=\"text-decoration: none;\"\u003e\u003cimg src=\"https://img.shields.io/badge/License-MIT-brightgreen.svg\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://github.com/astral-sh/ruff\"\u003e\u003cimg src=\"https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json\"\u003e\u003c/a\u003e\n\u003c/div\u003e\n\u003cbr /\u003e\n\n\n**Py-FSRS is a python package that allows developers to easily create their own spaced repetition system using the \u003ca href=\"https://github.com/open-spaced-repetition/free-spaced-repetition-scheduler\"\u003eFree Spaced Repetition Scheduler algorithm\u003c/a\u003e.**\n\n\n## Table of Contents\n- [Installation](#installation)\n- [Quickstart](#quickstart)\n- [Usage](#usage)\n- [Optimizer (optional)](#optimizer-optional)\n- [Reference](#reference)\n- [Other FSRS implementations](#other-fsrs-implementations)\n- [Other SRS python packages](#other-srs-python-packages)\n- [Contribute](#contribute)\n\n## Installation\nYou can install the `fsrs` python package from [PyPI](https://pypi.org/project/fsrs/) using pip:\n```\npip install fsrs\n```\n\n## Quickstart\n\nImport and initialize the FSRS scheduler\n\n```python\nfrom fsrs import Scheduler, Card, Rating, ReviewLog\n\nscheduler = Scheduler()\n```\n\nCreate a new Card object\n```python\n# note: all new cards are 'due' immediately upon creation\ncard = Card()\n```\n\nChoose a rating and review the card with the scheduler\n```python\n# Rating.Again (==1) forgot the card\n# Rating.Hard (==2) remembered the card with serious difficulty\n# Rating.Good (==3) remembered the card after a hesitation\n# Rating.Easy (==4) remembered the card easily\n\nrating = Rating.Good\n\ncard, review_log = scheduler.review_card(card, rating)\n\nprint(f\"Card rated {review_log.rating} at {review_log.review_datetime}\")\n# \u003e Card rated 3 at 2024-11-30 17:46:58.856497+00:00\n```\n\nSee when the card is due next\n```python\nfrom datetime import datetime, timezone\n\ndue = card.due\n\n# how much time between when the card is due and now\ntime_delta = due - datetime.now(timezone.utc)\n\nprint(f\"Card due on {due}\")\nprint(f\"Card due in {time_delta.seconds} seconds\")\n\n# \u003e Card due on 2024-11-30 18:42:36.070712+00:00\n# \u003e Card due in 599 seconds\n```\n\n## Usage\n\n### Custom parameters\n\nYou can initialize the FSRS scheduler with your own custom parameters.\n\n```python\nfrom datetime import timedelta\n\n# note: the following arguments are also the defaults\nscheduler = Scheduler(\n    parameters = (\n            0.40255,\n            1.18385,\n            3.173,\n            15.69105,\n            7.1949,\n            0.5345,\n            1.4604,\n            0.0046,\n            1.54575,\n            0.1192,\n            1.01925,\n            1.9395,\n            0.11,\n            0.29605,\n            2.2698,\n            0.2315,\n            2.9898,\n            0.51655,\n            0.6621,\n        ),\n    desired_retention = 0.9,\n    learning_steps = (timedelta(minutes=1), timedelta(minutes=10)),\n    relearning_steps = (timedelta(minutes=10),),\n    maximum_interval = 36500,\n    enable_fuzzing = True\n)\n```\n\n#### Explanation of parameters\n\n`parameters` are a set of 19 model weights that affect how the FSRS scheduler will schedule future reviews. If you're not familiar with optimizing FSRS, it is best not to modify these default values.\n\n`desired_retention` is a value between 0 and 1 that sets the desired minimum retention rate for cards when scheduled with the scheduler. For example, with the default value of `desired_retention=0.9`, a card will be scheduled at a time in the future when the predicted probability of the user correctly recalling that card falls to 90%. A higher `desired_retention` rate will lead to more reviews and a lower rate will lead to fewer reviews.\n\n`learning_steps` are custom time intervals that schedule new cards in the Learning state. By default, cards in the Learning state have short intervals of 1 minute then 10 minutes. You can also disable `learning_steps` with `Scheduler(learning_steps=())`\n\n`relearning_steps` are analogous to `learning_steps` except they apply to cards in the Relearning state. Cards transition to the Relearning state if they were previously in the Review state, then were rated Again - this is also known as a 'lapse'. If you specify `Scheduler(relearning_steps=())`, cards in the Review state, when lapsed, will not move to the Relearning state, but instead stay in the Review state.\n\n`maximum_interval` sets the cap for the maximum days into the future the scheduler is capable of scheduling cards. For example, if you never want the scheduler to schedule a card more than one year into the future, you'd set `Scheduler(maximum_interval=365)`.\n\n`enable_fuzzing`, if set to True, will apply a small amount of random 'fuzz' to calculated intervals. For example, a card that would've been due in 50 days, after fuzzing, might be due in 49, or 51 days.\n\n### Timezone\n\n**Py-FSRS uses UTC only.** \n\nYou can still specify custom datetimes, but they must use the UTC timezone.\n\n### Retrievability\n\nYou can calculate the current probability of correctly recalling a card (its 'retrievability') with\n\n```python\nretrievability = card.get_retrievability()\n\nprint(f\"There is a {retrievability} probability that this card is remembered.\")\n# \u003e There is a 0.94 probability that this card is remembered.\n```\n\n### Serialization\n\n`Scheduler`, `Card` and `ReviewLog` objects are all JSON-serializable via their `to_dict` and `from_dict` methods for easy database storage:\n\n```python\n# serialize before storage\nscheduler_dict = scheduler.to_dict()\ncard_dict = card.to_dict()\nreview_log_dict = review_log.to_dict()\n\n# deserialize from dict\nnew_scheduler = Scheduler.from_dict(scheduler_dict)\nnew_card = Card.from_dict(card_dict)\nnew_review_log = ReviewLog.from_dict(review_log_dict)\n```\n\n## Optimizer (optional)\n\nIf you have a collection of `ReviewLog` objects, you can optionally reuse them to compute an optimal set of parameters for the `Scheduler` to make it more accurate at scheduling reviews. You can also compute an optimal retention rate to reduce the future workload of your reviews.\n\n### Installation\n\n```\npip install \"fsrs[optimizer]\"\n```\n\n### Optimize scheduler parameters\n\n```python\nfrom fsrs import ReviewLog, Optimizer, Scheduler\n\n# load your ReviewLog objects into a list (order doesn't matter)\nreview_logs = [ReviewLog1, ReviewLog2, ...]\n\n# initialize the optimizer with the review logs\noptimizer = Optimizer(review_logs)\n\n# compute a set of optimized parameters\noptimal_parameters = optimizer.compute_optimal_parameters()\n\n# initialize a new scheduler with the optimized parameters\nscheduler = Scheduler(optimal_parameters)\n```\n\n### Optimize desired retention\n\n```python\noptimal_retention = optimizer.compute_optimal_retention(optimal_parameters)\n\n# initialize a new scheduler with both optimized parameters and retention\nscheduler = Scheduler(optimal_parameters, optimal_retention)\n```\n\nNote: The computed optimal parameters and retention may be slightly different than the numbers computed by Anki for the same set of review logs. This is because the two implementations are slightly different and updated at different times. If you're interested in the official Rust-based Anki implementation, please see [here](https://github.com/open-spaced-repetition/fsrs-rs).\n\n## Reference\n\nCard objects have one of three possible states\n```python\nState.Learning # (==1) new card being studied for the first time\nState.Review # (==2) card that has \"graduated\" from the Learning state\nState.Relearning # (==3) card that has \"lapsed\" from the Review state\n```\n\nThere are four possible ratings when reviewing a card object:\n```python\nRating.Again # (==1) forgot the card\nRating.Hard # (==2) remembered the card with serious difficulty\nRating.Good # (==3) remembered the card after a hesitation\nRating.Easy # (==4) remembered the card easily\n```\n\n## Other FSRS implementations\n\nYou can find various other FSRS implementations and projects [here](https://github.com/orgs/open-spaced-repetition/repositories?q=fsrs+sort%3Astars).\n\n## Other SRS python packages\n\nThe following spaced repetition schedulers are also available as python packages:\n\n- [SM-2](https://github.com/open-spaced-repetition/sm-2)\n- [Leitner System](https://github.com/open-spaced-repetition/leitner-box)\n- [Anki Default Scheduler](https://github.com/open-spaced-repetition/anki-sm-2)\n\n## Contribute\n\nIf you encounter issues with py-fsrs or would like to contribute code, please see [CONTRIBUTING](https://github.com/open-spaced-repetition/py-fsrs/blob/main/CONTRIBUTING.md).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-spaced-repetition%2Fpy-fsrs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopen-spaced-repetition%2Fpy-fsrs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopen-spaced-repetition%2Fpy-fsrs/lists"}