{"id":25995192,"url":"https://github.com/ethho/memoize","last_synced_at":"2026-06-05T17:32:06.397Z","repository":{"id":89667432,"uuid":"538578393","full_name":"ethho/memoize","owner":"ethho","description":"Python3 memoization decorator","archived":false,"fork":false,"pushed_at":"2024-01-09T18:19:30.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-01-09T19:51:13.782Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ethho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-09-19T15:50:35.000Z","updated_at":"2022-09-19T15:54:47.000Z","dependencies_parsed_at":"2024-01-09T19:46:36.892Z","dependency_job_id":"56f4c04a-c8a3-4035-ba64-f5b2f4417585","html_url":"https://github.com/ethho/memoize","commit_stats":null,"previous_names":[],"tags_count":4,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethho%2Fmemoize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethho%2Fmemoize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethho%2Fmemoize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ethho%2Fmemoize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ethho","download_url":"https://codeload.github.com/ethho/memoize/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242048555,"owners_count":20063404,"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":[],"created_at":"2025-03-05T15:19:38.638Z","updated_at":"2025-03-05T15:19:39.155Z","avatar_url":"https://github.com/ethho.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# memoize.py\n\nThis repo contains a decorator factory `memoize` that manages a local file cache of function results.\nThe cache is stored as a JSON file.\n\n## Quick Start\n\nInstall using pip:\n```bash\npython3 -m pip install git+https://github.com/ethho/memoize.git\n```\n\nBy default, `memoize` stores its cache in `/tmp/memoize/\u003cdate\u003e.json`, but this can be overridden by passing optional kwargs to the decorator factory.\n\n```python\nfrom memoize import memoize\nfrom functools import lru_cache\n\n\n@lru_cache() # Optionally, use with LRU cache to also cache in RAM\n# All are optional kwargs\n@memoize(stub='my_cache',               # file stub override\n         cache_dir='/tmp/my_cache_dir', # cache directory override\n         log_func=logger.info           # logging function override, print by default\n         ignore_invalid=True)           # ignore cache if not JSON serializable\ndef my_func(s: str, b: bool = True, opt=None):\n    return {\"s\": s, \"b\": b, \"opt\": opt}\n```\n\n## Memoize Pandas DataFrames\n\nThe `memoize_df` decorator caches the `pandas.DataFrame` returned from a function to a CSV file.\nThe `pandas` module must be installed to use this feature:\n\n```bash\npython3 -m pip install pandas\n```\n\nThe `memoize_df` decorator factory can be used for any function that returns a `pandas.DataFrame`.\nWhile `memoize` stores the results of many calls in one cache file, `memoize_df` writes a separate cache file for each unique call.\nAlso note that DataFrame index will be written to the CSV cache _if and only if_ the index has a non-null `name` attribute.\n\n```python\nimport pandas as pd\nfrom memoize.dataframe import memoize_df\n\n\n@memoize_df(cache_dir='/tmp/memoize')\ndef make_dataframe(foo: int):\n    df = pd.DataFrame(data=reversed(range(foo)), index=range(foo), columns=['my_column'])\n    df.index.name = 'my_index'\n    return df\n\n\nprint(make_dataframe(4))\n# Using cache fp='/tmp/memoize/make_dataframe_44566a0_20230120.csv' to write results of function make_dataframe\n#           my_column\n# my_index\n# 0                 3\n# 1                 2\n# 2                 1\n# 3                 0\n\nprint(make_dataframe(3))\n# Using cache fp='/tmp/memoize/make_dataframe_3c15101_20230120.csv' to write results of function make_dataframe\n#           my_column\n# my_index\n# 0                 2\n# 1                 1\n# 2                 0\n\nprint(make_dataframe(4))\n# Using cache fp='/tmp/memoize/make_dataframe_44566a0_20230120.csv' to write results of function make_dataframe\n# Using cached call from /tmp/memoize/make_dataframe_44566a0_20230120.csv\n#    my_index  my_column\n# 0         0          3\n# 1         1          2\n# 2         2          1\n# 3         3          0\n```\n\n## License\n\nMIT\n\n## Limitations\n\nArgs, kwargs, and function return value must be JSON-serializable if using the `memoize` decorator.\nThe return value of the wrapped function must be a `pandas.DataFrame` when using the `memoize_df` decorator.\nThe entire contents of the date-stamped cache file will be read and written on every function call, which may post I/O challenges.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethho%2Fmemoize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fethho%2Fmemoize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fethho%2Fmemoize/lists"}