{"id":15898738,"url":"https://github.com/rusmux/ipython-memory-magics","last_synced_at":"2025-03-20T17:30:33.114Z","repository":{"id":65681450,"uuid":"556009214","full_name":"rusmux/ipython-memory-magics","owner":"rusmux","description":"IPython magic commands for tracking memory usage","archived":false,"fork":false,"pushed_at":"2024-08-05T23:04:25.000Z","size":69,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-07T06:55:08.934Z","etag":null,"topics":["ipython-magic","jupyter-notebook","memory-profiler"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/ipython-memory-magics","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/rusmux.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-10-22T21:22:42.000Z","updated_at":"2023-07-17T07:16:04.000Z","dependencies_parsed_at":"2024-02-13T01:34:26.193Z","dependency_job_id":"93b51daf-0fc5-4c86-94e4-4dcd5566f918","html_url":"https://github.com/rusmux/ipython-memory-magics","commit_stats":{"total_commits":5,"total_committers":3,"mean_commits":"1.6666666666666667","dds":0.6,"last_synced_commit":"48909082c88cb8afbfb5670ff32e7ba72a166b82"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusmux%2Fipython-memory-magics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusmux%2Fipython-memory-magics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusmux%2Fipython-memory-magics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rusmux%2Fipython-memory-magics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rusmux","download_url":"https://codeload.github.com/rusmux/ipython-memory-magics/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221784744,"owners_count":16879641,"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":["ipython-magic","jupyter-notebook","memory-profiler"],"created_at":"2024-10-06T10:08:18.241Z","updated_at":"2024-10-28T05:20:45.588Z","avatar_url":"https://github.com/rusmux.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IPython memory magic commands\n\n[![PyPI](https://img.shields.io/pypi/v/ipython-memory-magics?color=brightgreen)](https://pypi.org/project/ipython-memory-magics/)\n[![codecov](https://codecov.io/gh/rusmux/ipython-memory-magics/branch/main/graph/badge.svg?token=HSOSLG5B19)](https://codecov.io/gh/rusmux/ipython-memory-magics)\n\n[![wemake-python-styleguide](https://img.shields.io/badge/style-wemake-000000.svg)](https://wemake-python-styleguide.readthedocs.io/en/latest/)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)\n[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/rusmux/ipython-memory-magics/main.svg)](https://results.pre-commit.ci/latest/github/rusmux/ipython-memory-magics/main)\n\nSimple tool to trace memory usage of a Python statement or expression execution.\n\nMemory equivalent of IPython\nbuilt-in [time magics](https://github.com/ipython/ipython/blob/66aeb3fc55c8ac04242e566172af5de5cc6fe71e/IPython/core/magics/execution.py#L1193).\n\nExisting tools like [memory-profiler](https://github.com/pythonprofilers/memory_profiler)\nor [ipython-memory-usage](https://github.com/ianozsvald/ipython_memory_usage) mainly use psutil package to measure\nmemory usage, which may give inaccurate results. This package\nuses [tracemalloc](https://docs.python.org/3/library/tracemalloc.html) module to trace Python memory allocations.\nMemory-profiler provides tracemalloc backend, but it does not allow to use it for magic commands. This packages offers\nline `%memory` and cell `%%memory` magic commands, which were intended to complement the `%time` and `%%time` magic\ncommands.\n\n# Installation\n\nInstall from pip:\n\n```\npip install ipython-memory-magics\n```\n\nOr install directly from GitHub:\n\n```\npip install git+https://github.com/rusmux/ipython-memory-magics.git\n```\n\nAfter the installation load the extension via:\n\n```\n%load_ext memory_magics\n```\n\nTo activate it whenever you start IPython, edit the configuration file for your IPython\nprofile `~/.ipython/profile_default/ipython_config.py`. Register the extension like this:\n\n```\nc.InteractiveShellApp.extensions = [\n    'memory_magics',\n]\n```\n\nIf the file does not already exist, run `ipython profile create` in a terminal.\n\n# Usage\n\nUse `%memory [options] statement` to measure `statement`'s memory consumption:\n\n```python\n%memory -q\nlist(range(10 ** 6))\n```\n\nThe output in the format `current / peak` will follow:\n\n```\nRAM usage: line: 34.33 MiB / 34.33 MiB\n```\n\nHere `-q` is the `quiet` flag set to suppress the output. You can use other options to get data on the notebook and\njupyter memory usage, or to print the statistics in a table. For example, you can use `-n` or `--notebook` flag to get\nthe information about the notebook current memory consumption:\n\n```python\n%memory -n\n```\n\n```\nRAM usage: notebook: 101.41 MiB\n```\n\nIn the same way, `-j` or `--jupyter` flag will give you the information about the total Jupyter memory usage.\n\nPut `%%memory [options]` on top of a cell to measure its memory consumption:\n\n```python\nIn[1]: %%memory -n -j -t\nsum(list(range(10 ** 6)))\n```\n\nThis will print:\n\n```\nRAM usage |   current   |     peak     |\n----------------------------------------\n cell     | 2.62 KiB    | 34.33 MiB    |\n notebook | 123.08 MiB  | 155.53 MiB   |\n jupyter  | 170.19 MiB  | 202.55 MiB   |\n\nOut [1]: 499999500000\n```\n\n# Options\n\nFive options are available in full and short versions:\n\n`-n \u003cnotebook\u003e`: If present, show current notebook memory usage\n\n`-j \u003cjupyter\u003e`: If present, show current jupyter memory usage\n\n`-i \u003cinterval\u003e`: Interval in milliseconds for updating memory usage information\n\n`-t \u003ctable\u003e`: If present, print statistics in a table\n\n`-q \u003cquiet\u003e`: If present, do not return the output\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusmux%2Fipython-memory-magics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frusmux%2Fipython-memory-magics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frusmux%2Fipython-memory-magics/lists"}