LibCST is a Concrete Syntax Tree (CST) parser, analyzer, and transformation framework for Python 3.9–3.15, developed by Meta (Instagram). Unlike an AST, the CST preserves every byte of the original source—including whitespace, comments, parentheses, and formatting—enabling lossless round-trips and precise automated refactoring. The library provides a rich node hierarchy (expressions, statements, operators, whitespace), a full parser with both a pure-Python fallback and a high-performance Rust native implementation via PyO3, and a visitor/transformer system with typed visit/leave methods. It also includes a reusable metadata system with providers for source positions, scopes, qualified names, expression context, and type inference (via Pyre), as well as a pattern-matching DSL (“matchers”) for declarative node queries and a CLI tool for running codemods. The codemod framework is a major feature: it offers base classes for writing automated code transformations (VisitorBasedCodemodCommand, MagicArgsCodemodCommand), bundled commands for common refactoring tasks (removing unused imports, converting type comments, migrating format strings to f-strings, renaming symbols, adding trailing commas, etc.), and a testing harness (CodemodTest). The library is designed for tooling such as linters, formatters, and large-scale migration scripts—and is used internally at Meta for exactly these purposes. It is distributed as a pip package with pre-built wheels, supports multiple operating systems and Python free-threaded builds, and is actively maintained with a mature CI pipeline. Architecturally, LibCST is a library, not a standalone application, though it exposes a CLI via ‘python -m libcst.tool’. It has no API endpoints, databases, or data pipelines. The codebase is well-structured, heavily tested (93%+ coverage), and includes code generation for typed visitor and matcher classes from node definitions. While the dual parser (Python vs. Rust) introduces some maintenance complexity, the overall craftsmanship is high—clean abstractions, immutable nodes, dependency-injected metadata, and a robust visitor pattern make this a reference implementation for CST processing.
CodeGraph is a Python command-line tool that performs static analysis on Python source code to generate dependency graphs. It parses Python files to extract functions, classes, and import statements, then builds a graph showing how these entities depend on each other. The tool outputs an interactive HTML visualization (using D3.js by default) or can export the data to CSV or print it to the console. The architecture is modular, consisting of a parser (using Python's tokenize module), a core module that builds the dependency graph, utility functions for file discovery, and a visualizer that supports both D3.js (interactive) and matplotlib (legacy) backends. The tool does not execute the code being analyzed, making it safe and fast for large codebases. Key strengths include a robust parser that handles various import styles and class inheritance, and a flexible visualization system that provides features like search, collapsing/expanding nodes, and detailed tooltips. The project is actively maintained with comprehensive tests and supports multiple Python versions.