Registry / testing / lizard

lizard

JSON →
library1.24.0pypypi✓ verified 22d ago

Lizard is an extensible Cyclomatic Complexity Analyzer for multiple programming languages, including C/C++, Java, JavaScript, Python, Ruby, Swift, and Objective C. It calculates metrics such as cyclomatic complexity number (CCN), lines of code (NLOC), token count, and parameter count. Version 1.21.3 is currently active, with a regular release cadence addressing bug fixes and improvements.

pip install lizard
INSTALL
IMPORT
SIG · LIZARD
L
lizard
testingpythonv1.24.0
Install
2.3s avg
Import
75ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.24.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.076s · 27.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.3s · import 0.074s · 28MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lizard
import lizard
The primary way to interact with the library programmatically is by importing the top-level `lizard` module.

This quickstart demonstrates how to use `lizard` to analyze a Python file programmatically. It creates a dummy Python file, analyzes it, and prints out key metrics for each function found. It also shows how to analyze a source code string directly.

import lizard import os # Create a dummy Python file for analysis code_to_analyze = ''' def calculate_something(a, b): if a > 0: if b > 0: return a + b else: return a - b elif a < 0: return b else: return 0 class MyClass: def __init__(self, val): self.val = val def get_val(self): return self.val ''' file_path = "example_for_lizard.py" with open(file_path, "w") as f: f.write(code_to_analyze) # Analyze the file # lizard.analyze_file returns a 'FileInformation' object file_info = lizard.analyze_file(file_path) print(f"\n--- Analysis for {file_info.filename} ---") print(f"Total lines of code (NLOC): {file_info.nloc}") for func_info in file_info.function_list: print(f"\n Function: {func_info.name}") print(f" Cyclomatic Complexity (CCN): {func_info.cyclomatic_complexity}") print(f" NLOC: {func_info.nloc}") print(f" Parameter Count: {func_info.parameters}") print(f" Token Count: {func_info.token_count}") # Clean up the dummy file os.remove(file_path) # Example of analyzing a string directly (requires a filename hint for language detection) string_code = "def simple_func():\n pass" string_info = lizard.analyze_source_code("temp.py", string_code) print(f"\n--- Analysis for string code (temp.py) ---") for func_info in string_info.function_list: print(f" Function: {func_info.name}, CCN: {func_info.cyclomatic_complexity}")
lizard --version
Debug
Known issues
gotchaWhen running `lizard` from the command line, the tool will exit with a non-zero status code if any warnings are generated (e.g., functions exceeding complexity thresholds). This is intended for CI/CD pipelines but might be unexpected if not accounted for.
fix
Check the exit code in scripts and configure your CI/CD to handle warnings as desired (e.g., fail on warnings or ignore them if above a certain threshold using the `-i` option).
affects: All versions
gotchaWhen using the `--exclude` option (or `-x`) for file exclusion patterns, ensure to wrap patterns with quotation marks (e.g., `-x "./tests/*"`) to prevent shell expansion issues.
fix
Always quote exclusion patterns, especially those containing wildcards, to ensure they are passed correctly to `lizard`.
affects: All versions
breakingOlder versions of `lizard` (e.g., 1.7.x and earlier) supported Python 2.6/2.7/3.x. However, recent versions (like 1.21.3) are built for Python 3.8 and newer. Attempting to install or run the latest `lizard` on older Python 3 versions or Python 2 will result in errors.
fix
Ensure your environment uses Python 3.8 or a newer compatible version (e.g., Python 3.10+ is typically recommended for new development).
affects: From ~1.8.0 onwards (specifically 1.20.0+ requires Python 3.8+).
gotchaIn C/C++ code, preprocessor directives like `#if` will increase the cyclomatic complexity count by default. This might lead to higher complexity scores than expected if you are not aware of this behavior.
fix
Be aware of how preprocessor directives impact complexity. If specific functions are intentionally complex due to such constructs, consider using the `#lizard forgives` comment within or before the function to suppress warnings for it.
affects: All versions
Errors
Common errors & fixes
lizard: command not found
The 'lizard' executable is not in your system's PATH, or the installation was not completed successfully.
fix
Ensure `lizard` is installed via `pip install lizard` and that your Python scripts directory (e.g., `~/.local/bin` on Linux, or the Python `Scripts` folder on Windows) is included in your system's PATH environment variable.
Errors when running lizard on older Python versions (e.g., Python 2 or Python < 3.8)
Recent versions of the `lizard` library (like 1.21.3) require Python 3.8 or newer, and will not run on older Python environments.
fix
Upgrade your Python environment to version 3.8 or higher. It is generally recommended to use Python 3.10+ for new development.
RecursionError: maximum recursion depth exceeded
This error occurs when `lizard` processes a very large or deeply nested code structure, leading to Python's recursion limit being hit.
fix
This is often a limitation with deeply nested code. While there isn't a direct `lizard` option to mitigate it, increasing Python's recursion limit (`sys.setrecursionlimit()`) before running `lizard` might help, or refactoring the problematic code to reduce nesting. Be cautious when increasing the recursion limit significantly as it can consume more memory.
AttributeError: 'FunctionInfo' object has no attribute 'max_nesting_depth'
This specific `AttributeError` has been reported as a crash when using the `-w` (warnings) flag with certain versions of `lizard` due to an incompatibility with how function information is accessed.
fix
Upgrade `lizard` to the latest version, as this was a bug that might have been fixed in subsequent releases. If the issue persists with the latest version, avoid using the `-w` flag or consider downgrading to a known stable version where this issue was not present (e.g., v1.17.14 as per one report).
Cannot find the lizard_languages module.
This error indicates that `lizard` cannot locate its internal `lizard_languages` module, which is essential for parsing different programming languages. This usually points to an incomplete or corrupted installation.
fix
Reinstall the `lizard` library using `pip install --no-cache-dir --force-reinstall lizard` to ensure all necessary modules are downloaded and installed correctly. If running from source, ensure `lizard_languages.py` (or its compiled form) is accessible in the Python path relative to `lizard.py`.
Upgrade
Version history
1.24.0latest on PyPI · released Aug 19, 2026
Audit
Dependencies
PythonrequiredRequired runtime for the library. Modern versions (1.x.x) typically require Python 3.8+.
Agent activity
26 hits · last 30 days
node
24
Amazon
1
Resources
lizard — pip install lizard · libregistry