{
 "kind": "tool",
 "slug": "pycparser",
 "path": "tools/pycparser/",
 "name": "pycparser",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Languages, types and runtimes",
   "tools/languages-types/"
  ]
 ],
 "lead": "Read C code from Python scripts.",
 "chips": [
  {
   "label": "Languages, types and runtimes",
   "path": "tools/languages-types/"
  },
  {
   "label": "PYPI"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "pip install pycparser"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/eliben/pycparser"
  },
  {
   "label": "Website",
   "href": "https://github.com/eliben/pycparser"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "BSD-3-Clause",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met",
   "note": "BSD 3-Clause allows commercial use; do not use the author's or contributors' names to promote your product.",
   "src": "https://github.com/eliben/pycparser/blob/main/LICENSE"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Nov 12, 2026",
   "note": "Latest GitHub release Oct 22, 2026. ",
   "src": "https://github.com/eliben/pycparser"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "39 projects",
   "status": "info",
   "sub": "#10 of 70 in its category",
   "note": "Dependency in 39 public GitHub projects set up for AI coding agents that we scanned (0.6%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Install only",
   "status": "info",
   "sub": null,
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 11, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What pycparser does",
   "parts": [
    {
     "t": "prose",
     "text": "pycparser is a free Python library that reads C source code and turns it into a tree of parts a script can walk, like every function, type and parameter. It is for tools that check, document or change C code. Most people get it without asking, because CFFI uses it."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "List the functions in a C header",
       "text": "Your script reads a library's header file and prints every function with its parameters, for docs or a wrapper.",
       "idea": false
      },
      {
       "title": "Check C code for house rules",
       "text": "A small checker flags code that breaks your team's rules, such as a banned function or a missing return type, before review.",
       "idea": false
      },
      {
       "title": "Find tests in C projects",
       "text": "Scan C test files for functions named test_* and build the list your test runner calls.",
       "idea": false
      },
      {
       "title": "Generate bindings for other languages",
       "text": "Read a header once and write matching declarations for Python, Rust or JavaScript code that calls the same C library.",
       "idea": false
      },
      {
       "title": "Rewrite C code automatically",
       "text": "Change the tree, for example rename a function everywhere, and print it back as C source with the built-in code generator.",
       "idea": true
      },
      {
       "title": "Teach how C declarations read",
       "text": "Show students or teammates how a confusing declaration like a pointer to an array of functions breaks down, part by part.",
       "idea": true
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "pycparser popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "73",
       "of": "/ 100",
       "l": "Gid Score, #270 overall"
      },
      {
       "n": "282M",
       "l": "downloads a week, pypi"
      },
      {
       "n": "3,583",
       "l": "GitHub stars"
      },
      {
       "n": "39",
       "l": "agent projects use it"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How pycparser is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "pycparser is a dependency in 39 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (2.4% of the 1,623 Python ones), #10 of 70 in languages, types and runtimes.",
      "Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,024; those are left out of every share on this page.",
      "The most used alternative in our scan is Cython (4 projects).",
      "Projects that use it most often also use CFFI (97.4%), Pydantic (94.9%), Click (89.7%)."
     ]
    },
    {
     "t": "h3",
     "text": "By coding agent"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "26 projects, 0.9%",
       "v": "GitHub Copilot",
       "path": "agents/github-copilot/"
      },
      {
       "l": "21 projects, 0.6%",
       "v": "Claude Code",
       "path": "agents/claude-code/"
      },
      {
       "l": "11 projects, 0.5%",
       "v": "Cursor",
       "path": "agents/cursor/"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 97.4% of its projects",
       "v": "CFFI",
       "path": "tools/cffi/"
      },
      {
       "l": "In 94.9% of its projects",
       "v": "Pydantic",
       "path": "tools/pydantic/"
      },
      {
       "l": "In 89.7% of its projects",
       "v": "Click",
       "path": "tools/click-py/"
      },
      {
       "l": "In 89.7% of its projects",
       "v": "urllib3",
       "path": "tools/urllib3/"
      },
      {
       "l": "In 87.2% of its projects",
       "v": "cryptography",
       "path": "tools/cryptography/"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "usage",
   "h2": "More about pycparser",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "More in Languages, types and runtimes",
       "path": "tools/languages-types/",
       "items": [
        {
         "text": "TypeScript",
         "path": "tools/typescript/"
        },
        {
         "text": "tsx",
         "path": "tools/tsx/"
        },
        {
         "text": "ts-node",
         "path": "tools/ts-node/"
        },
        {
         "text": "jiti",
         "path": "tools/jiti/"
        },
        {
         "text": "vue-tsc",
         "path": "tools/vue-tsc/"
        },
        {
         "text": "Cloudflare Workers Types",
         "path": "tools/cloudflare-workers-types/"
        },
        {
         "text": "mypy",
         "path": "tools/mypy/"
        },
        {
         "text": "tsconfig-paths",
         "path": "tools/tsconfig-paths/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "pycparser",
       "me": true,
       "facts": [
        "BSD-3-Clause",
        "Gid 73",
        "282M/wk"
       ]
      },
      {
       "name": "libclang",
       "why": "Pick libclang when you need the real Clang compiler's view of the code, including C++, and can install LLVM.",
       "path": "tools/libclang/",
       "facts": []
      },
      {
       "name": "tree-sitter-c",
       "why": "Pick the Tree-sitter C grammar for editors and code search that must cope with half-written code and skip the preprocessor.",
       "path": "tools/tree-sitter-c/",
       "facts": []
      },
      {
       "name": "PLY",
       "why": "Pick PLY when you want to build a parser for your own small language rather than read C.",
       "path": "tools/ply/",
       "facts": []
      },
      {
       "name": "Cython",
       "why": "Compiles Python to C for performance-critical code and C extensions.",
       "path": "tools/cython/",
       "facts": [
        "Apache-2.0",
        "Gid 69",
        "23.8M/wk"
       ]
      }
     ],
     "more": "Compare pycparser with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "Use pycparser (pin pycparser==3.12, Python 3.11+) to parse this C header with parse_file(path, use_cpp=True) and a c_ast.NodeVisitor, then list every function with its parameters; run the C preprocessor first, never feed raw files with include lines or comments."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Install it with pip into your project's environment; it has no other packages of its own.",
       "code": "> pip install pycparser",
       "src": "https://github.com/eliben/pycparser/blob/main/README.rst"
      },
      {
       "text": "Parse a short piece of C directly, or a real file through the C preprocessor with parse_file(use_cpp=True).",
       "code": "from pycparser import CParser, parse_file\n\nast = parse_file(\n    \"example.c\",\n    use_cpp=True,\n    cpp_args=[\"-std=c23\"],\n    parser=CParser(dialect=\"c23\"),\n)\n",
       "src": "https://github.com/eliben/pycparser/blob/main/README.rst"
      },
      {
       "text": "Walk the tree with a NodeVisitor subclass and pick the parts you need.",
       "code": null,
       "src": "https://github.com/eliben/pycparser/blob/main/README.rst"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "CParser().parse(open(\"file.c\").read()) on a real file with #include, #define or comments",
       "fix": "parse_file(\"file.c\", use_cpp=True), or run gcc -E / clang -E first and parse the output",
       "why": "In our run the raw header failed with \"ParseError - :1:1: Directives not supported yet\"; through cpp it parsed."
      },
      {
       "dont": "Preprocessing with the system's real headers (stdio.h and friends) and hitting errors on compiler extras",
       "fix": "Point the preprocessor at the fake headers from the project's utils/fake_libc_include with -I",
       "why": "The real system headers are full of compiler extensions; the fake ones hold only what parsing needs."
      },
      {
       "dont": "Expecting pip install pycparser to bring utils/fake_libc_include",
       "fix": "Fetch that folder from the project's source (a release archive) and keep it in your repository",
       "why": "The fake headers are not part of the pip package."
      },
      {
       "dont": "Parsing C23 code with bool or other new keywords using the default parser",
       "fix": "CParser(dialect=\"c23\") together with cpp_args=[\"-std=c23\"]",
       "why": "C23 support is off by default because its new keywords clash with older code."
      },
      {
       "dont": "pip install pycparser==3.12 on Python 3.10",
       "fix": "Use Python 3.11+ for 3.x, or let pip pick an older 2.x release on Python 3.10",
       "why": "pycparser 3.12 declares Python 3.11 as the minimum."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Why did I get pycparser without installing it?",
       "a": "CFFI uses pycparser to read C declarations, so installing CFFI (or a package built on it) brings it in.",
       "evidence": {
        "url": "https://github.com/eliben/pycparser/blob/main/README.rst",
        "quote": "One of the most popular uses of pycparser is in the cffi library, which uses it to parse the declarations of C functions and types in order to auto-generate FFIs."
       }
      },
      {
       "q": "Does it need anything else installed?",
       "a": "No other Python packages. For real files you also need a C preprocessor such as cpp, gcc -E or clang -E on your PATH.",
       "evidence": {
        "url": "https://github.com/eliben/pycparser/blob/main/README.rst",
        "quote": "Note also that you can use gcc -E or clang -E instead of cpp."
       }
      },
      {
       "q": "Did version 3 change how I use it?",
       "a": "Version 3.00 rewrote the parser by hand and dropped the PLY dependency; the release notes say the same tree comes out.",
       "evidence": {
        "url": "https://github.com/eliben/pycparser/releases/tag/release_v3.00",
        "quote": "No API changes / functionality changes intended - the same AST is produced."
       }
      },
      {
       "q": "Can it read C23 code?",
       "a": "Yes, when you create the parser with dialect=\"c23\" and pass -std=c23 to the preprocessor yourself.",
       "evidence": {
        "url": "https://github.com/eliben/pycparser/blob/main/README.rst",
        "quote": "The parser's dialect does not configure the external preprocessor; select its language mode separately through cpp_args."
       }
      },
      {
       "q": "Can I use it in a commercial product?",
       "a": "Yes. The BSD 3-Clause license allows it if you keep the notice and do not use the author's name for promotion.",
       "evidence": {
        "url": "https://github.com/eliben/pycparser/blob/main/LICENSE",
        "quote": "Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met"
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "pypi pycparser"
  ],
  [
   "Category",
   "Languages, types and runtimes"
  ],
  [
   "License",
   "BSD-3-Clause"
  ],
  [
   "Gid Score",
   "73.1"
  ],
  [
   "Rank in category",
   "#10 of 70"
  ],
  [
   "GitHub",
   "eliben/pycparser"
  ],
  [
   "Last change",
   "Nov 12, 2026"
  ]
 ],
 "good": [
  "Real C files must go through the C preprocessor first; plain text with include or define lines or comments fails to parse.",
  "It reads C only, up to C11 by default, with C23 behind a setting; it does not read C++.",
  "Code full of GCC-specific extras needs extra setup before it parses."
 ],
 "checked_line": "Read by AgentGid from 5 official pages, card checked Nov 11, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/eliben.png"
}