{"id":15443882,"url":"https://github.com/gaogaotiantian/coredumpy","last_synced_at":"2025-05-14T22:08:34.216Z","repository":{"id":235019066,"uuid":"789870534","full_name":"gaogaotiantian/coredumpy","owner":"gaogaotiantian","description":"coredumpy saves your crash site for post-mortem debugging","archived":false,"fork":false,"pushed_at":"2025-04-01T02:40:49.000Z","size":1295,"stargazers_count":610,"open_issues_count":2,"forks_count":15,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-13T21:33:58.094Z","etag":null,"topics":["coredump","debugging","postmortem","python","tools"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gaogaotiantian.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,"zenodo":null}},"created_at":"2024-04-21T19:19:34.000Z","updated_at":"2025-04-13T13:16:28.000Z","dependencies_parsed_at":"2024-05-01T03:26:35.159Z","dependency_job_id":"51b6feca-0d0e-48a9-b7a1-0b98b0b4fb0a","html_url":"https://github.com/gaogaotiantian/coredumpy","commit_stats":null,"previous_names":["gaogaotiantian/coredumpy"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaogaotiantian%2Fcoredumpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaogaotiantian%2Fcoredumpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaogaotiantian%2Fcoredumpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gaogaotiantian%2Fcoredumpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gaogaotiantian","download_url":"https://codeload.github.com/gaogaotiantian/coredumpy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235700,"owners_count":22036964,"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":["coredump","debugging","postmortem","python","tools"],"created_at":"2024-10-01T19:37:24.015Z","updated_at":"2025-05-14T22:08:29.196Z","avatar_url":"https://github.com/gaogaotiantian.png","language":"Python","funding_links":["https://github.com/sponsors/gaogaotiantian"],"categories":["Python"],"sub_categories":[],"readme":"# coredumpy\n\n[![build](https://github.com/gaogaotiantian/coredumpy/actions/workflows/build_test.yaml/badge.svg)](https://github.com/gaogaotiantian/coredumpy/actions/workflows/build_test.yaml)\n[![coverage](https://img.shields.io/codecov/c/github/gaogaotiantian/coredumpy)](https://codecov.io/gh/gaogaotiantian/coredumpy)\n[![pypi](https://img.shields.io/pypi/v/coredumpy.svg)](https://pypi.org/project/coredumpy/)\n[![support-version](https://img.shields.io/pypi/pyversions/coredumpy)](https://img.shields.io/pypi/pyversions/coredumpy)\n[![Visual Studio Marketplace Version](https://img.shields.io/visual-studio-marketplace/v/gaogaotiantian.coredumpy-vscode)](https://marketplace.visualstudio.com/items?itemName=gaogaotiantian.coredumpy-vscode)\n[![sponsor](https://img.shields.io/badge/%E2%9D%A4-Sponsor%20me-%23c96198?style=flat\u0026logo=GitHub)](https://github.com/sponsors/gaogaotiantian)\n\ncoredumpy saves your crash site for post-mortem debugging.\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"img/showcase.gif\" /\u003e\n\u003c/p\u003e\n\n\n## Highlights\n\n* Easy to use\n* Native support for unittest, pytest and run-time exceptions\n* Portable and safe dump\n* Support VSCode and pdb interface\n* Support multi-threading with VSCode\n\n## Usage\n\n### dump\n\nFor `pytest`, you can use `coredumpy` as a plugin\n\n```\n# Create a dump in \"./dumps\" when there's a pytest failure/error\npytest --enable-coredumpy --coredumpy-dir ./dumps\n```\n\nFor `Exception` and `unittest`, you can use `coredumpy run` command.\nA dump will be generated when there's an unhandled exception or a test failure\n\n```\n# with no argument coredumpy run will generate the dump in the current dir\ncoredumpy run my_script.py\ncoredumpy run my_script.py --directory ./dumps\ncoredumpy run -m unittest --directory ./dumps\n```\n\nOr you can patch explicitly in your code and execute the script/module as usual\n\n```python\nimport coredumpy\n# Create a dump in \"./dumps\" when there's an unhandled exception\ncoredumpy.patch_except(directory='./dumps')\n# Create a dump in \"./dumps\" when there's a unittest failure/error\ncoredumpy.patch_unittest(directory='./dumps')\n# Create a dump in \"./dumps\" when there's a pytest failure/error\ncoredumpy.patch_pytest(directory='./dumps')\n```\n\n\u003cdetails\u003e\n\n\u003csummary\u003e\nOr you can dump the current frame stack manually\n\u003c/summary\u003e\n\n```python\nimport coredumpy\n\n# Without frame argument, top frame will be the caller of coredumpy.dump()\ncoredumpy.dump()\n# Specify a specific frame as the top frame to dump\ncoredumpy.dump(frame)\n# Set the search depth to 2 to reduce the dump size\ncoredumpy.dump(depth=2)\n# Specify a filename to save the dump, without it a unique name will be generated\ncoredumpy.dump(path='coredumpy.dump')\n# You can use a function for path\ncoredumpy.dump(path=lambda: f\"coredumpy_{time.time()}.dump\")\n# Specify a directory to keep the dump\ncoredumpy.dump(directory='./dumps')\n# Specify the description of the dump for peek\ncoredumpy.dump(description=\"a random dump\")\n```\n\n\u003c/details\u003e\n\nA [github action](https://github.com/gaogaotiantian/upload-coredumpy) is available\nto upload your coredumpy dumps and generate a load link to open the dumps in VSCode\ndirectly.\n\n### load\n\nLoad your dump with\n\n```\n# This will bring up pdb\ncoredumpy load \u003cyour_dump_file\u003e\n# This will bring up ipdb, ipython is required\ncoredumpy load --ipdb \u003cyour_dump_file\u003e\n```\n\nA debugger will be brought up and of course not everything is supported.\n\n### peek\n\nIf you only need some very basic information of the dump (to figure out which dump\nyou actually need), you can use `peek` command.\n\n```\ncoredumpy peek \u003cyour_dump_directory\u003e\ncoredumpy peek \u003cyour_dump_file1\u003e \u003cyour_dump_file2\u003e\n```\n\n### VSCode Extension\n\nDownload the [VSCode Extension](https://marketplace.visualstudio.com/items?itemName=gaogaotiantian.coredumpy-vscode)\nand right click your dump file - choose `Load with coredumpy`.\n\n### Configuration\n\nAll configurations should be done through `coredumpy.config`.\nThe default value is listed below and you can change them as you need.\n\n```python\nfrom coredumpy import config\n# The dump depth if not specified\nconfig.default_recursion_depth: int = 10\n# Best effort timeout for dump - not guaranteed. Only checked for each new depth.\nconfig.dump_timeout: int = 60\n# Whether dump all threads\nconfig.dump_all_threads: bool = True\n# Whether hide strings that match config.secret_patterns\nconfig.hide_secret: bool = True\n# The patterns for secrets\nconfig.secret_patterns: list[re.Pattern] = [re.compile(r\"[A-Za-z0-9]{32,1024}\")]\n# Whether hide strings that match os.environ.values()\nconfig.hide_environ: bool = True\n# The filter to determine whether an environ should be hidden\nconfig.environ_filter: Callable = lambda env: len(env) \u003e 8\n```\n\n## Type support\n\n`coredumpy` supports the common built-in types like `float`, `int`, `str`, `list`,\n`dict` etc. For all the other types that it can't recognize, it will treat them as\na Python object, which means `coredumpy` will iterate and store all the attributes\nof the object.\n\nYou can add support for any arbitrary types by creating a class that inherits\n`coredumpy.TypeSupportBase`. You need to finish the following class methods in\norder to make it work:\n\n```python\n@classmethod\ndef get_type(cls) -\u003e tuple[Union[type, Callable], str]:\n    # returns a tuple with two elements:\n    # 0. type (or a callable for lazy load) for dump\n    #    coredumpy will dispatch the objects with this type to the dump method\n    # 1. a type string for load\n    #    coredumpy will dispatch the data with this type to the load method\n\n@classmethod\ndef dump(cls, obj) -\u003e tuple[dict, Optional[list]]:\n    # takes the object to be dumped\n    # returns a tuple with two elements:\n    # 0. a json-serializable dict, which will be stored in the dump file\n    # 1. a list that contains the objects needed to be dumped for this object\n    #    if none needed (the object is not a container), use None\n\n@classmethod\ndef load(cls, data: dict, objects: dict) -\u003e tuple[object, Optional[list[str]]]:\n    # takes the dict data from `dump` method and a dict of all objects with the ids\n    # as keys\n    # returns a tuple with two elements:\n    # 0. the restored object. If not ready, return coredumpy.NotReady\n    # 1. a list of the ids of dependent objects, if not applicable, use None\n```\n\nIf the type is a container, inherit `coredumpy.TypeSupportContainerBase` and\nimplement an extra method:\n\n```python\n@classmethod\ndef reload(cls, container, data, objects: dict) -\u003e tuple[object, Optional[list[str]]]:\n    # takes the already built container, the other arguments are the same as `load`\n    # returns the same as `load`\n    # This is helpful to create a placeholder first with `load` so the other objects\n    # can reference to it, and build the placeholder later\n```\n\nYou only need to create the class, it will be automatically registered.\n\n## Startup script\n\nIn order to import the type supports and do some customization, `coredumpy` provides\na way to run an arbitrary script after importing `coredumpy`. You can put a\n`conf_coredumpy.py` file in your current working directory. If `coredumpy` discovers\nit, the script will be executed. You can put anything you need in the script.\n\nOr if you prefer to do it explicitly, you can pass `--conf your_conf_file.py` to\n`coredumpy run` or `coredumpy load` command to run that specified file.\n\n## About the data\n\nBesides a couple of builtin types, coredumpy treats almost every object as an\nPython object with attributes, and that's what it records in the dump.\n\nThat being said, most of the objects will not be \"restored\" as they were when\nbeing dumped. You are in an observer mode where you can inspect attributes of\nall objects. None of the methods of the objects would work, nor would any\ndymanic features.\n\n### Why not `pickle`?\n\n* Most importantly, `pickle` does not always work. You can't partially pickle\n  something, which means if you have an unpickleable object, you are doomed.\n* `pickle` requires the same environment to deserialize the objects, which\n  defeats the original purpose of loading the dump anywhere.\n* `pickle` is unsafe by design and we don't want unnecessary hesitation when\n  users try to load a dump from an untrusted source.\n\n### Security concerns\n\nBecause coredumpy dumps the whole frame stack, you should take care of your\nsensitive information.\n\n#### API Keys\n\ncoredumpy has a default-on filter for strings that looks like API keys\n(`\"[A-Za-z0-9]{32,1024}\"`), but if you know what your key looks like,\nyou should add the pattern to protect your keys.\n\n```python\nfrom coredumpy import config\nconfig.secret_patterns.append(re.compile(\"\u003cyour API key pattern\u003e\"))\n```\n\nYou can edit `config.secret_patterns` as you wish, it's a list of\n`re.Pattern`s that coredumpy will use to match against all strings.\n\nIf you need to turn off this feature:\n\n```python\nfrom coredumpy import config\nconfig.hide_secret = False\n```\n\n#### Environs\n\nIt's common to store sensitive data in your environment variables, so coredumpy\nalso has a default-on filter for environs. It will redact all strings if they\nare in `os.environ` and their length \u003e 8. You can change the filter by\n\n```python\nfrom coredumpy import config\n# Only redact if the length \u003e 16\nconfig.environ_filter = lambda env: len(env) \u003e 16\n```\n\nTurn this filter off with\n```python\nfrom coredumpy import config\nconfig.hide_environ = False\n```\n\n\n## License\n\nCopyright 2024-2025 Tian Gao.\n\nDistributed under the terms of the  [Apache 2.0 license](https://github.com/gaogaotiantian/coredumpy/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaogaotiantian%2Fcoredumpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgaogaotiantian%2Fcoredumpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgaogaotiantian%2Fcoredumpy/lists"}