libcst
A concrete syntax tree with AST-like properties for Python 3.0 through 3.15 programs.
Decision gist · record as of 2026-08-14
Yes. libcst is actively maintained, has no known vulnerabilities, and is widely used (top 1000 on PyPI with ~52M monthly downloads). Install friction is moderate due to the native extension, but binary wheels cover common platforms. Choose it if you need to parse and modify Python code while preserving formatting; skip it if you only need syntax analysis and don't care about whitespace or comments.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.9 or later; if a binary wheel is unavailable for your platform, you need a Rust toolchain (cargo) to build the native parser extension.
- Medium install friction due to a native Rust extension; binary wheels are provided for Linux/Windows x86/x64 and macOS x64/arm64, but systems without a matching wheel require a Rust toolchain.
- The package is actively maintained with a recent release and no known vulnerabilities.
License · maintenance · safety
permissive license (permissive) — Permissive multi-license: MIT for all contributions, with dual MIT/PSF licensing for files derived from Python's standard library and Apache 2.0 for dataclasses-derived code. No restrictions on commercial or proprietary use.
last release 2026-07-29 (16 days) · last repo commit 2026-08-11 · 1,935 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 51,948,301 downloads/mo, #566 on PyPI
Alternatives
Verify before relying
import libcst as cst
from libcst.tool import dump
code = "1 + 2"
tree = cst.parse_expression(code)
print(dump(tree))- Performance characteristics and scalability limits for parsing very large codebases or deeply nested expressions.
- Memory overhead compared to the standard ast module for typical use cases.
- Specific version support claim for Python 3.15 (marked as supported but may be in pre-release).
What it is and what it does
libcst is a lossless parser that converts Python source code into a concrete syntax tree (CST) while preserving every formatting detail—comments, whitespace, parentheses, and line breaks. Unlike Python's built-in ast module, which discards formatting information, libcst reconstructs the original source exactly, making it ideal for tools that need to modify code and write it back without losing style or comments.
The library is designed for building automated refactoring tools (codemods) and linters that must understand code structure while respecting the developer's formatting choices. It depends on pyyaml, pyyaml-ft, and typing-extensions, and ships with a native Rust parser for performance. It supports Python 3.9 through 3.15 and is actively maintained by Meta.
Use it for
- Build automated refactoring tools that rewrite Python code while preserving comments and formatting.
- Implement linters that analyze code structure and report issues without losing the original source layout.
- Create code migration scripts that transform legacy Python to modern syntax while maintaining readability.
- Develop IDE plugins or language servers that need to understand and modify Python source with fidelity.
- Write code generation or templating tools that must integrate generated code into existing files cleanly.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
libcst is actively maintained, has no known vulnerabilities, and is widely used (top 1000 on PyPI with ~52M monthly downloads). Install friction is moderate due to the native extension, but binary wheels cover common platforms. Choose it if you need to parse and modify Python code while preserving formatting; skip it if you only need syntax analysis and don't care about whitespace or comments.
Install
libcst on PyPI
Before you install
Medium install friction due to a native Rust extension; binary wheels are provided for Linux/Windows x86/x64 and macOS x64/arm64, but systems without a matching wheel require a Rust toolchain. The package is actively maintained with a recent release and no known vulnerabilities.
Requires Python 3.9 or later; if a binary wheel is unavailable for your platform, you need a Rust toolchain (cargo) to build the native parser extension.
License in practice
Permissive multi-license: MIT for all contributions, with dual MIT/PSF licensing for files derived from Python's standard library and Apache 2.0 for dataclasses-derived code. No restrictions on commercial or proprietary use.
Quickstart
import libcst as cst
from libcst.tool import dump
code = "1 + 2"
tree = cst.parse_expression(code)
print(dump(tree))
Verify before relying
- Performance characteristics and scalability limits for parsing very large codebases or deeply nested expressions.
- Memory overhead compared to the standard ast module for typical use cases.
- Specific version support claim for Python 3.15 (marked as supported but may be in pre-release).
Package facts
| License | permissive license permissive |
| Python support | Supports the current Python release >=3.9 |
| Install friction | Medium. Platform-specific wheel |
| Runtime dependencies | 3 packagespyyamlpyyaml-fttyping-extensions |
| Maintenance | Actively maintained 16 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 51,948,301 / month, #566 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | License :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.15Programming Language :: Python :: 3.9Programming Language :: Python :: Free ThreadingTopic :: Software Development :: LibrariesTyping :: Typed |
Evidence: libcst-1.9.0-cp310-cp310-macosx_11_0_arm64.whl; libcst-1.9.0-cp310-cp310-manylinux_2_28_aarch64.whl; libcst-1.9.0-cp310-cp310-manylinux_2_28_x86_64.whl; libcst-1.9.0-cp310-cp310-musllinux_1_2_aarch64.whl; libcst-1.9.0-cp310-cp310-musllinux_1_2_x86_64.whl; libcst-1.9.0-cp310-cp310-win_amd64.whl; libcst-1.9.0-cp310-cp310-win_arm64.whl; libcst-1.9.0-cp311-cp311-macosx_11_0_arm64.whl; libcst-1.9.0-cp311-cp311-manylinux_2_28_aarch64.whl; libcst-1.9.0-cp311-cp311-manylinux_2_28_x86_64.whl; libcst-1.9.0-cp311-cp311-musllinux_1_2_aarch64.whl; libcst-1.9.0-cp311-cp311-musllinux_1_2_x86_64.whl; libcst-1.9.0-cp311-cp311-win_amd64.whl; libcst-1.9.0-cp311-cp311-win_arm64.whl; libcst-1.9.0-cp312-cp312-macosx_11_0_arm64.whl; libcst-1.9.0-cp312-cp312-manylinux_2_28_aarch64.whl; libcst-1.9.0-cp312-cp312-manylinux_2_28_x86_64.whl; libcst-1.9.0-cp312-cp312-musllinux_1_2_aarch64.whl; libcst-1.9.0-cp312-cp312-musllinux_1_2_x86_64.whl; libcst-1.9.0-cp312-cp312-win_amd64.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “python code parser with formatting”
- libcstlibcst parses Python source code into a concrete syntax tree that…
- baronBaron parses Python source code into a Full Syntax Tree (FST) that…
- ssfFormats numbers and dates using ECMA-376 spreadsheet format codes,…
Give your agent the search over MCP, or paste the wish link into any chat.
More Libraries packages
urllib3 is an HTTP client library that provides thread-safe connection pooling, SSL/TLS verification, multipart file uploads, request retries, compression support, and proxy handling for Python applications.
Requests is a Python HTTP library that simplifies sending HTTP/1.1 requests with automatic handling of headers, authentication, cookies, and response parsing.
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
Provides parsing, arithmetic, and recurrence rule computation for dates and times, with timezone support and iCalendar RFC compliance.
Install it if you need to parse flexible date strings, compute relative dates, handle timezones, or work with recurrence rules—it's the de facto choice for these tasks.
Six provides utility functions to write Python code that runs on both Python 2.7 and Python 3.3+, smoothing over language differences between the two versions.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
See also fixit · parso · json5kit · astunparse · ast-decompiler · ast-grep-cli · ast-comments · imperfect · ast-serialize · ast-grep-py