{"id":15015177,"url":"https://github.com/cknoll/ipydex","last_synced_at":"2025-06-20T13:35:27.797Z","repository":{"id":4552235,"uuid":"5693043","full_name":"cknoll/ipydex","owner":"cknoll","description":"IPython-based debugging and exploring - a collection of auxiliary functions","archived":false,"fork":false,"pushed_at":"2025-05-07T22:05:49.000Z","size":472,"stargazers_count":16,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-07T23:19:40.681Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cknoll.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":"2012-09-05T20:28:52.000Z","updated_at":"2025-05-07T22:05:54.000Z","dependencies_parsed_at":"2024-09-11T01:52:21.127Z","dependency_job_id":"6f4daac8-5a7c-4bf8-be28-5269a235ec91","html_url":"https://github.com/cknoll/ipydex","commit_stats":{"total_commits":151,"total_committers":6,"mean_commits":"25.166666666666668","dds":0.152317880794702,"last_synced_commit":"89f86632287d69135697be8c550c21095f108737"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/cknoll/ipydex","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cknoll%2Fipydex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cknoll%2Fipydex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cknoll%2Fipydex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cknoll%2Fipydex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cknoll","download_url":"https://codeload.github.com/cknoll/ipydex/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cknoll%2Fipydex/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260953678,"owners_count":23088077,"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":"2024-09-24T19:46:35.542Z","updated_at":"2025-06-20T13:35:22.779Z","avatar_url":"https://github.com/cknoll.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ipydex – **ipy**thon based **de**bugging and **ex**ploring\n\n\n[![CircleCI](https://circleci.com/gh/cknoll/ipydex/tree/main.svg?style=shield)](https://circleci.com/gh/cknoll/ipydex/tree/main)\n[![PyPI version](https://badge.fury.io/py/ipydex.svg)](https://badge.fury.io/py/ipydex)\n\n\nThe module contains two main components:\n\n## Component 1: displaytools\n\n\n-   a jupyter-notebook-extension (`%loadext ipydex.displaytools`)\n-   introduces magic comments (like `##:`, `##:T`, `##:S`) which cause\n    that either the return value or the right hand side of an assignment\n    of a line is displayed (`T` means additional transposition and `S`\n    means only `.shape` attribute is displayed)\n-   display intermediate results (→ more readable notebooks), without\n    introducing additional `print` or `display` statements\n-   Example invocation: `x = np.random.rand() ##:`\n    -   inserts the line `display(\"x := {}\".format(x))` to the source\n        code of the cell (before its execution)\n-   see\n    [documentation-notebook](http://nbviewer.jupyter.org/github/cknoll/ipydex/blob/main/examples/displaytools-example.ipynb)\n\n**Security advice**: Because the extension manipulates the source code\nbefore its execution, it might cause unwanted and strange behavior.\nThus, this program is distributed in the hope that it will be useful,\n*but without any warranty*.\n\n## Component 2: Useful Python functions and classes\n\n\nThe following functions are meant to be used in ordinary python-scripts:\n\n-   `IPS()`\n    -   start an embedded IPython shell in the calling scope\n    -   useful to explore what objects are available and what are their\n        abilities\n    -   some additional features compared to `IPython.embed()`\n-   `ST()`\n    -   start the IPython debugger\n-   `activate_ips_on_exception()`\n    -   activate an embedded IPython shell in the scope where an\n        exception occurred\n    -   useful to investigate what happened\n    -   see below how to make use of in connection with [pytest](https://pypi.org/project/pytest/)\n    - set magic variable `__mu` to `1` and exit the shell (CTRL+D) in order to move up one level in the frame stack\n        - useful to determine the reason of an exception (which is often not in the same frame as where the exception finally happened)\n-   `dirsearch(name, obj)`\n    -   search the keys of a dict or the attributes of an object\n    -   useful to explore semi known modules, classes and\n        data-structures\n-   `Container`\n    - versatile class for debugging and convenient creation of case-specific data structures\n\n## Notes\n\nThis package has grown over more than a decade. It is only partially covered by unittests. Its internals are not exemplary for recommended coding practice. It certainly contains bugs. No warranty for any purpose is given.\n\nNevertheless it might be useful.\n\n### ipydex Usage in Unittests (Using pytest)\n\nIn your test directory add a file `conftest.py`:\n\n```python\n\n# This file enables the ipydex excepthook together with pytest.\n# The custom excepthook can be activated by `activate_ips_on_exception()`\n# in your test-file.\n\n# To prevent unwanted dependencies the custom excepthook is only active if a\n# special environment variable is \"True\". Use the following command for this:\n#\n# export PYTEST_IPS=True\n\n\nimport os\nif os.getenv(\"PYTEST_IPS\") == \"True\":\n\n    import ipydex\n\n    # This function is just an optional reminder\n    def pytest_runtest_setup(item):\n        print(\"This invocation of pytest is customized\")\n\n\n    def pytest_exception_interact(node, call, report):\n        # the option `leave_ut=True` causes the excepthook to leave functions\n        # from the unittest package. This is a convenience feature such that\n        # the code wakes up in your own testcode\n        ipydex.ips_excepthook(\n            call.excinfo.type, call.excinfo.value, call.excinfo.tb, leave_ut=True\n        )\n```\n\n\n### Use `ipydex.Container` for Debugging e.g. in Jupyter Notebooks\n\n```python\nfrom ipydex import Container\n\n# ...\n\ndef func1(x, debug_container=None):\n    y = complicated_func1(x)\n    res = complicated_func2(x, y)\n\n    # convenient way to non-intrusively gather internal information\n    if debug_container is not None:\n        debug_container.fetch_locals()\n        # now the following attributes exists:\n        # debug_container.x\n        # debug_container.y\n        # debug_container.res\n\n    return res\n\n# create debug container\ndc = Container()\n\n# call the function which should be debugged, pass the container\n# as keyword argument\nres = func1(100, debug_container=dc)\n\n# after the function returned dc contains new attributes which allow to\n# investigate *internal* behavior of func1\nprint(C.x)\nprint(C.y)\nprint(C.res)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcknoll%2Fipydex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcknoll%2Fipydex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcknoll%2Fipydex/lists"}