{"id":13419277,"url":"https://github.com/vitsalis/PyCG","last_synced_at":"2025-03-15T05:30:43.367Z","repository":{"id":36998575,"uuid":"321773354","full_name":"vitsalis/PyCG","owner":"vitsalis","description":"Static Python call graph generator","archived":true,"fork":false,"pushed_at":"2023-11-26T07:28:36.000Z","size":281,"stargazers_count":317,"open_issues_count":0,"forks_count":58,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-10-01T07:37:27.102Z","etag":null,"topics":["call-graphs","callgraph","program-analysis","pycg","python","static-analysis"],"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/vitsalis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-12-15T19:50:07.000Z","updated_at":"2024-09-17T04:23:41.000Z","dependencies_parsed_at":"2024-06-18T18:28:57.441Z","dependency_job_id":"f7bf26ce-686b-4a7b-8d5c-85632b380444","html_url":"https://github.com/vitsalis/PyCG","commit_stats":{"total_commits":227,"total_committers":8,"mean_commits":28.375,"dds":0.1541850220264317,"last_synced_commit":"8d5dc40837803beef1d8d379fbf2cdad6cd94641"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitsalis%2FPyCG","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitsalis%2FPyCG/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitsalis%2FPyCG/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vitsalis%2FPyCG/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vitsalis","download_url":"https://codeload.github.com/vitsalis/PyCG/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243690113,"owners_count":20331726,"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":["call-graphs","callgraph","program-analysis","pycg","python","static-analysis"],"created_at":"2024-07-30T22:01:13.734Z","updated_at":"2025-03-15T05:30:43.006Z","avatar_url":"https://github.com/vitsalis.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# PyCG - Practical Python Call Graphs\n\n[![Linters](https://github.com/vitsalis/PyCG/actions/workflows/linters.yml/badge.svg)](https://github.com/vitsalis/PyCG/actions/workflows/linters.yml)\n[![Tests](https://github.com/vitsalis/PyCG/actions/workflows/test.yaml/badge.svg)](https://github.com/vitsalis/PyCG/actions/workflows/test.yaml)\n\nPyCG generates call graphs for Python code using static analysis.\nIt efficiently supports\n* Higher order functions\n* Twisted class inheritance schemes\n* Automatic discovery of imported modules for further analysis\n* Nested definitions\n\nYou can read the full methodology as well as a complete evaluation on the\n[ICSE 2021 paper](https://arxiv.org/pdf/2103.00587.pdf).\n\nYou can cite PyCG as follows.\nVitalis Salis, Thodoris Sotiropoulos, Panos Louridas, Diomidis Spinellis and Dimitris Mitropoulos.\nPyCG: Practical Call Graph Generation in Python.\nIn _43rd International Conference on Software Engineering, ICSE '21_,\n25–28 May 2021.\n\n\u003e **PyCG** is archived. Due to limited availability, no further development\n\u003e improvements are planned. Happy to help anyone that wants to create a fork to\n\u003e continue development.\n\n# Installation\n\nPyCG is implemented in Python3 and requires Python version 3.4 or higher.\nIt also has no dependencies. Simply:\n```\npip install pycg\n```\n\n# Usage\n\n```\n~ \u003e\u003e\u003e pycg -h\nusage: __main__.py [-h] [--package PACKAGE] [--fasten] [--product PRODUCT]\n                        [--forge FORGE] [--version VERSION] [--timestamp TIMESTAMP]\n                        [--max-iter MAX_ITER] [--operation {call-graph,key-error}]\n                        [--as-graph-output AS_GRAPH_OUTPUT] [-o OUTPUT]\n                        [entry_point ...]\n\npositional arguments:\n  entry_point           Entry points to be processed\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --package PACKAGE     Package containing the code to be analyzed\n  --fasten              Produce call graph using the FASTEN format\n  --product PRODUCT     Package name\n  --forge FORGE         Source the product was downloaded from\n  --version VERSION     Version of the product\n  --timestamp TIMESTAMP\n                        Timestamp of the package's version\n  --max-iter MAX_ITER   Maximum number of iterations through source code. If not specified a fix-point iteration will be performed.\n  --operation {call-graph,key-error}\n                        Operation to perform. Choose call-graph for call graph generation (default) or key-error for key error detection on dictionaries.\n  --as-graph-output AS_GRAPH_OUTPUT\n                        Output for the assignment graph\n  -o OUTPUT, --output OUTPUT\n                        Output path\n```\n\nThe following command line arguments should used only when `--fasten` is\nprovied:\n\n- `--product`: The name of the package.\n- `--forge`: Source the package was downloaded from.\n- `--version`: The version of the package.\n- `--timestamp` : The timestamp of the package's version.\n\n# Call Graph Output\n\n## Simple JSON format\n\nThe call edges are in the form of an adjacency list where an edge `(src, dst)`\nis represented as an entry of `dst` in the list assigned to key `src`:\n\n```\n{\n    \"node1\": [\"node2\", \"node3\"],\n    \"node2\": [\"node3\"],\n    \"node3\": []\n}\n```\n\n## FASTEN Format\n\nFor an up-to-date description of the FASTEN format refer to the\n[FASTEN\nwiki](https://github.com/fasten-project/fasten/wiki/Extended-Revision-Call-Graph-format#python).\n\n# Key Errors Output\n\nWe are currently experimenting on identifying potential invalid dictionary\naccesses on Python dictionaries (key errors).\nThe output format for key errors is a list of dictionaries containing:\n- The file name in which the key error was identified\n- The line number inside the file\n- The namespace of the accessed dictionary\n- The key used to access the dictionary\n\n```\n[{\n    \"filename\": \"mod.py\",\n    \"lineno\": 2,\n    \"namespace\": \"mod.\u003cdict1\u003e\",\n    \"key\": \"key2\"\n},\n{\n    \"filename\": \"mod.py\",\n    \"lineno\": 8,\n    \"namespace\": \"mod.\u003cdict1\u003e\",\n    \"key\": \"nokey\"\n}]\n```\n\n# Examples\n\nAll the entry points are known and we want the simple JSON format\n```\n~ \u003e\u003e\u003e pycg --package pkg_root pkg_root/module1.py pkg_root/subpackage/module2.py -o cg.json\n```\n\nAll entry points are not known and we want the simple JSON format\n```\n~ \u003e\u003e\u003e pycg --package django $(find django -type f -name \"*.py\") -o django.json\n```\n\nWe want the FASTEN format:\n```\n~ \u003e\u003e\u003e pycg --package pypi_pkg --fasten --product \"pypipkg\" --forge \"PyPI\" \\\n        --version \"0.1\" --timestamp 42 \\\n        pypi_pkg/module1.py pkg_root/subpackage/module2.py -o cg.json\n```\n\n# Running Tests\n\nFrom the root directory, first install the [mock](https://pypi.org/project/mock/) package:\n```\npip3 install mock\n```\nΤhen, simply run the tests by executing:\n```\nmake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitsalis%2FPyCG","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvitsalis%2FPyCG","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvitsalis%2FPyCG/lists"}