{"library":"staticfg","title":"StaticFG","type":"library","description":"StaticFG is a Python library (current version 0.9.5) designed to generate control flow graphs (CFGs) for Python 3 programs. It parses Python source code, builds an Abstract Syntax Tree (AST), and then transforms it into a CFG, which can be visualized using Graphviz. The project is actively maintained with a moderate release cadence.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install staticfg","pip install graphviz"],"cli":{"name":"staticfg","version":"sh: 1: staticfg: not found"}},"imports":["from staticfg import CFGBuilder","from staticfg.cfg import CFG"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/coetaur0/staticfg","docs":null,"changelog":null,"pypi":"https://pypi.org/project/staticfg/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import os\nfrom staticfg import CFGBuilder\n\n# Define a simple Python function as a string\ncode = \"\"\"\ndef greet(name):\n    if name:\n        message = f\"Hello, {name}!\"\n    else:\n        message = \"Hello, World!\"\n    print(message)\n\"\"\"\n\n# Build the CFG from the source string\n# The first argument 'greet_cfg' is the name of the CFG (often the function name)\n# The second argument is the source code string\ncfg = CFGBuilder().build_from_src('greet_cfg', code)\n\n# To visualize, you need the Graphviz system tool installed and in your PATH.\n# The output will be 'greet_cfg.pdf' in the current directory.\ntry:\n    cfg.build_visual('greet_cfg', 'pdf')\n    print(\"CFG 'greet_cfg.pdf' generated successfully.\")\nexcept Exception as e:\n    print(f\"Could not build visual graph. Make sure Graphviz (dot command) is installed and in your PATH. Error: {e}\")\n    # In a real application, you might log this error or notify the user.","lang":"python","description":"Demonstrates how to build a control flow graph from a Python string and attempt to visualize it as a PDF. Note that the Graphviz *system tool* (providing the `dot` command) must be installed and in your system's PATH for visualization to succeed.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}