{"id":13702083,"url":"https://github.com/osteele/callgraph","last_synced_at":"2025-03-16T18:32:31.633Z","repository":{"id":50189034,"uuid":"116083801","full_name":"osteele/callgraph","owner":"osteele","description":"Magic to display dynamic call graphs of Python function calls","archived":false,"fork":false,"pushed_at":"2021-10-21T18:29:45.000Z","size":197,"stargazers_count":78,"open_issues_count":5,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-15T22:56:14.073Z","etag":null,"topics":["education","ipython-magic","jupyter-notebook-extension","python","visualizations"],"latest_commit_sha":null,"homepage":"","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/osteele.png","metadata":{"files":{"readme":"README.rst","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":"2018-01-03T02:57:38.000Z","updated_at":"2025-02-17T11:39:27.000Z","dependencies_parsed_at":"2022-09-26T20:53:49.889Z","dependency_job_id":null,"html_url":"https://github.com/osteele/callgraph","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/osteele%2Fcallgraph","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osteele%2Fcallgraph/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osteele%2Fcallgraph/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/osteele%2Fcallgraph/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/osteele","download_url":"https://codeload.github.com/osteele/callgraph/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243826780,"owners_count":20354220,"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":["education","ipython-magic","jupyter-notebook-extension","python","visualizations"],"created_at":"2024-08-02T21:00:30.991Z","updated_at":"2025-03-16T18:32:27.645Z","avatar_url":"https://github.com/osteele.png","language":"Python","funding_links":[],"categories":["Collaboration/Education"],"sub_categories":[],"readme":"Callgraph Magic\n===============\n\n|PyPI version| |Doc Status| |License| |Supported Python|\n\nCallgraph is a Python package that defines a decorator, and Jupyter magic,\nto draw `dynamic call graphs`_ of Python function calls.\n\nIt’s intended for classroom use, but may also be useful for self-guided\nexploration.\n\nThe package defines a Jupyter `IPython`_ `magic`_, ``%callgraph``, that\ndisplays a call graph within a Jupyter cell:\n\n.. code:: python\n\n    from functools import lru_cache\n\n    @lru_cache()\n    def lev(a, b):\n        if \"\" in (a, b):\n            return len(a) + len(b)\n\n        candidates = []\n        if a[0] == b[0]:\n            candidates.append(lev(a[1:], b[1:]))\n        else:\n            candidates.append(lev(a[1:], b[1:]) + 1)\n        candidates.append(lev(a, b[1:]) + 1)\n        candidates.append(lev(a[1:], b) + 1)\n        return min(candidates)\n\n    %callgraph -w10 lev(\"big\", \"dog\"); lev(\"dig\", \"dog\")\n\n|image0|\n\nIt also provides a Python decorator, ``callgraph.decorator``, that\ninstruments a function to collect call graph information and render the\nresult.\n\nJupyter / IPython Usage\n-----------------------\n\n.. code:: bash\n\n    $ pip install callgraph\n\nIn a Jupyter IPython notebook:\n\n.. code:: python\n\n    %load_ext callgraph\n\n    def nchoosek(n, k):\n        if k == 0:\n            return 1\n        if n == k:\n            return 1\n        return nchoosek(n - 1, k - 1) + nchoosek(n - 1, k)\n\n    %callgraph nchoosek(4, 2)\n\nAs an alternative to including ``%load_ext callgraph`` in each notebook that\nuses ``%callgraph``, you can add the extension to the Notebook\nconfiguration file in your IPython profile.\n\nYour configuration file is probably called ``~/.ipython/profile_default/ipython_config.py``.\n(You can run ``ipython profile locate`` to find it.)\nEdit this file to include the following line::\n\n    c.InteractiveShellApp.extensions = [\"callgraph.extension\"]\n\n(If your configuration file already includes an uncommented statement\n``c.InteractiveShellApp.extensions = […]``, edit the list of extensions in\nthat line to include ``\"callgraph.extension\"``.\n\nSee `extension example notebook`_ for additional examples.\n\nDecorator Usage\n---------------\n\n.. code:: bash\n\n    $ pip install callgraph\n\n.. code:: python\n\n    from functools import lru_cache\n    import callgraph.decorator as callgraph\n\n    @callgraph()\n    @lru_cache()\n    def nchoosek(n, k):\n        if k == 0:\n            return 1\n        if n == k:\n            return 1\n        return nchoosek(n - 1, k - 1) + nchoosek(n - 1, k)\n\n    nchoosek(5, 2)\n\n    nchoosek.__callgraph__.view()\n\nSee the `API documentation`_ for additional documentation.\n\nSee the `decorator example notebook`_ for additional instructions and examples.\n\nDevelopment\n-----------\n\nInstall dev tools, and set up a Jupyter kernel for the current python\nenviromnent:\n\n.. code:: bash\n\n    $ pip install -r requirements-dev.txt\n    $ python -m ipykernel install --user\n\nInstall locally:\n\n.. code:: bash\n\n    flit install --symlink\n\nAcknowledgements\n----------------\n\nCallgraph uses the Python `graphviz package`_. Python graphviz uses\nthe `Graphviz`_ package.\n\nLicense\n-------\n\nMIT\n\n.. |PyPI version| image:: https://img.shields.io/pypi/v/callgraph.svg\n    :target: https://pypi.python.org/pypi/callgraph\n    :alt: Latest PyPI Version\n.. |Doc Status| image:: https://readthedocs.org/projects/callgraph/badge/?version=latest\n    :target: http://callgraph.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n.. |License| image:: https://img.shields.io/pypi/l/callgraph.svg\n    :target: https://pypi.python.org/pypi/callgraph\n    :alt: License\n.. |Supported Python| image:: https://img.shields.io/pypi/pyversions/callgraph.svg\n    :target: https://pypi.python.org/pypi/callgraph\n    :alt: Supported Python Versions\n\n.. _dynamic call graphs: https://en.wikipedia.org/wiki/Call_graph\n.. _IPython: https://ipython.org\n.. _magic: http://ipython.readthedocs.io/en/stable/interactive/magics.html\n.. _graphviz package: https://github.com/xflr6/graphviz\n.. _Graphviz: https://www.graphviz.org\n\n.. |image0| image:: ./docs/images/lev.svg\n.. _API documentation: http://callgraph.readthedocs.io/en/latest/?badge=latest#module-callgraph\n.. _extension example notebook: https://github.com/osteele/callgraph/blob/master/examples/callgraph-magic-examples.ipynb\n.. _decorator example notebook: https://github.com/osteele/callgraph/blob/master/examples/callgraph-decorator-examples.ipynb\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosteele%2Fcallgraph","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fosteele%2Fcallgraph","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fosteele%2Fcallgraph/lists"}