beniget
Extract semantic information about static Python code
Decision gist · record as of 2026-08-14
Yes. Beniget is a solid, actively maintained library for static Python code analysis with low install friction and no known vulnerabilities. It fills a specific niche—semantic AST analysis—and is well-suited for anyone building linters, compilers, or code transformation tools. The permissive BSD license poses no barrier. Install it if you need to reason about Python code structure and data flow.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.6 or later; gast is a runtime dependency.
- Low friction: pure Python wheel with a single runtime dependency (gast).
- Active maintenance with a recent release (258 days ago) and steady repository activity.
License · maintenance · safety
BSD 3-Clause (permissive) — BSD 3-Clause is permissive; you can use, modify, and distribute beniget with minimal restrictions, provided you include the license notice.
last release 2025-11-29 (258 days) · last repo commit 2026-07-04 · 85 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 802,315 downloads/mo, #5,020 on PyPI
Alternatives
Verify before relying
import beniget
import gast as ast
code = "from math import cos, sin; print(cos(3))"
module = ast.parse(code)
duc = beniget.DefUseChains()
duc.visit(module)
for name in module.body[0].names:
if not duc.chains[name].users():
print(f"Unused: {name.name}")- Whether the standard library ast support (added in 0.5.0) is production-ready or still experimental.
- Performance characteristics on large codebases or deeply nested AST structures.
What it is and what it does
Beniget is a static analysis library that extracts semantic information from Python abstract syntax trees. It provides three main analyses: Ancestors (maps each node to its enclosing nodes), DefUseChains (maps definitions to their uses), and UseDefChains (maps uses back to their definitions). It works across Python 3.6+ by relying on gast for cross-version AST abstraction, and as of version 0.5.0 also supports the standard library ast module.
The library is designed as a building block for writing static analyzers, compilers, and code transformation tools. Common use cases include detecting unused imports, finding decorated functions, gathering class attributes, computing variable capture in closures, and tracing instruction dependencies. It handles the semantic complexity of Python's scoping rules and name binding, though it cannot track dynamic lookups through eval() or globals().
Use it for
- Detect unused imports and dead code by analyzing definition-use chains at module scope.
- Find all functions decorated with a specific decorator by traversing decorator uses and their parent nodes.
- Gather all attributes assigned to self in a class by walking method parameters and attribute accesses.
- Compute identifiers captured by inner functions and lambdas from outer scopes.
- Trace the set of statements required to compute a function by combining use-def chains with ancestor analysis.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
Beniget is a solid, actively maintained library for static Python code analysis with low install friction and no known vulnerabilities. It fills a specific niche—semantic AST analysis—and is well-suited for anyone building linters, compilers, or code transformation tools. The permissive BSD license poses no barrier. Install it if you need to reason about Python code structure and data flow.
Install
beniget on PyPI
Before you install
Low friction: pure Python wheel with a single runtime dependency (gast). Active maintenance with a recent release (258 days ago) and steady repository activity.
Requires Python 3.6 or later; gast is a runtime dependency.
License in practice
BSD 3-Clause is permissive; you can use, modify, and distribute beniget with minimal restrictions, provided you include the license notice.
Quickstart
import beniget
import gast as ast
code = "from math import cos, sin; print(cos(3))"
module = ast.parse(code)
duc = beniget.DefUseChains()
duc.visit(module)
for name in module.body[0].names:
if not duc.chains[name].users():
print(f"Unused: {name.name}")
Verify before relying
- Whether the standard library ast support (added in 0.5.0) is production-ready or still experimental.
- Performance characteristics on large codebases or deeply nested AST structures.
Package facts
| License | BSD 3-Clause permissive |
| Python support | Supports the current Python release >=3.6 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packagegast |
| Maintenance | Actively maintained 258 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 802,315 / month, #5,020 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 4 - BetaEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseNatural Language :: EnglishProgramming Language :: Python :: 3 |
Evidence: beniget-0.5.0-py3-none-any.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 ast analysis”
- benigetBeniget performs compile-time analysis on Python abstract syntax…
- ast-serializeParses Python source files and serializes their AST to mypy's native…
- astroidAstroid builds an extended abstract syntax tree (AST) representation…
Give your agent the search over MCP, or paste the wish link into any chat.
More Software Development packages
Provides backported and experimental type hints for Python 3.9+, allowing use of newer typing features on older Python versions and enabling early experimentation with type system PEPs before they enter the standard library.
NumPy provides an N-dimensional array object and a comprehensive suite of mathematical, linear algebra, Fourier transform, and random number functions for scientific computing in Python.
FastAPI is a Python web framework for building REST APIs using type hints, with automatic request validation, serialization, and interactive API documentation.
Provides a way to document function parameters, class attributes, return types, and variables inline using Python's `Annotated` type hint syntax instead of traditional docstrings.
Typer builds command-line applications from Python functions using type hints, automatically generating help text, argument parsing, and shell completion.
Install it if you are building CLIs in Python.
Distlib provides low-level packaging utilities for building, distributing, and managing Python software—including metadata handling, version specifiers, wheel support, script installation, and dependency resolution.
See also gast · ast-decompiler · mr-proper · trailmark · ast-comments · astunparse · luaparser · asttokens · astpretty · pyan3