{"id":19752748,"url":"https://github.com/spoorn/nemoize","last_synced_at":"2025-04-30T10:32:25.568Z","repository":{"id":57690719,"uuid":"493986537","full_name":"spoorn/nemoize","owner":"spoorn","description":"Python Memoizer for classes, functions, and methods","archived":false,"fork":false,"pushed_at":"2022-05-20T12:03:28.000Z","size":17,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T17:16:59.656Z","etag":null,"topics":["cache","decorator","decorators","decorators-python","memoize","memoize-decorator","memoized","memoizer","python","python3"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/nemoize/","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/spoorn.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}},"created_at":"2022-05-19T08:32:55.000Z","updated_at":"2024-05-03T15:26:55.000Z","dependencies_parsed_at":"2022-09-26T20:52:42.459Z","dependency_job_id":null,"html_url":"https://github.com/spoorn/nemoize","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spoorn%2Fnemoize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spoorn%2Fnemoize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spoorn%2Fnemoize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spoorn%2Fnemoize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spoorn","download_url":"https://codeload.github.com/spoorn/nemoize/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251684532,"owners_count":21627148,"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":["cache","decorator","decorators","decorators-python","memoize","memoize-decorator","memoized","memoizer","python","python3"],"created_at":"2024-11-12T02:49:54.181Z","updated_at":"2025-04-30T10:32:25.317Z","avatar_url":"https://github.com/spoorn.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nemoize\nSimple Python Memoizer decorator for classes, functions, and methods.\n\n# Installation\nnemoize is available on PyPi\n\n```commandline\npython3 -m pip install nemoize\n```\n\nOr you can install manually via the built distribution (wheel)/source dist from [PyPi](pypi.org/project/nemoize) or [github](https://github.com/spoorn/nemoize).\n\n\n# How to Use\n\nImport\n\n```python\nfrom nemoize import memoize\n```\n\nThen use the `@memoize` decorator on various entities as seen below\n\n### Using on a Class\n\n```python\n@memoize\nclass Test:\n    def __init__(self, value):\n        self._value = value\n\n    @property\n    def value(self):\n        return self._value\n```\n\n### Using on a function\n\n```python\n@memoize\ndef test_func():\n    return \"hoot\"\n```\n\n### Using on an instance method\n\n```python\nclass Owl:\n    def __init__(self):\n        self.food = 1337\n        pass\n\n    @memoize(max_size=5)\n    def eat(self, num):\n        self.food -= num\n```\n\n## Configuration\n\nThere are also various configuration parameters to `memoize()`:\n\n- `@memoize(max_size=13)` : Max number of entries to keep in the cache: \n- `@memoize(cache_exceptions=True)` : Also cache exceptions, so any raised Exceptions will be the exact same Exception instance: \n- `@memoize(max_size=13, cache_exceptions=True)` : Together\n- `@memoize(arg_hash_function=str)` : Changes the hash function on arg and each keyword-arg to use the str() function, which can make lists \"hashable\"\n\n# Testing\nThe unit tests in `test/unit/test_memoize.py` run through various use cases of using the @memoize annotation on classes, functions, and instance methods.\n\n# Benchmarking\nThere is a benchmarking utility under [`benchmark/`](https://github.com/spoorn/nemoize/tree/main/benchmark) that is used for benchmarking nemoize performance against other options and non-memoized scenarios.\n\nExample numbers:\n\n```commandline\nBenchmark test for Memoized vs Non-memoized classes with [1000] computations in their__init__() methods for [1000000] iterations\nNon-memoized class creation + empty method call average time (ms): 0.01550699806213379\nMemoized class creation + empty method call average time (ms): 0.0012589995861053468\n\nBenchmark test for @memoize, non-memoized, a @simplified_memoize, and @functools.lru_cache comparison usingfunction calculating fibonacci sum for [100] fib numbers, for [10000000] iterations\n@simplified_memoize fib average time (ms): 0.0001555999994277954\n@memoize fib average time (ms): 4.4699978828430175e-05\n@memoize(cache_exceptions=True) (to avoid delegation to functools.lru_cache) fib average time (ms): 0.00034309999942779544\n@functools.lru_cache fib average time (ms): 4.440000057220459e-05\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspoorn%2Fnemoize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspoorn%2Fnemoize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspoorn%2Fnemoize/lists"}