Multi-dimensional code complexity analyzer
Project description
semantic-complexity (Python)
Multi-dimensional code complexity analyzer for Python.
Installation
pip install semantic-complexity
Usage
CLI
# Analyze a file
semantic-complexity path/to/file.py
# Analyze a directory
semantic-complexity path/to/project/
# Output as Markdown report
semantic-complexity path/to/project/ -f markdown -o report.md
# Filter by threshold
semantic-complexity path/to/project/ --threshold 20
Python API
from semantic_complexity import analyze_source, analyze_functions
# Analyze source code
result = analyze_source("""
def complex_function(x):
if x > 0:
for i in range(x):
if i % 2 == 0:
print(i)
""")
print(f"Weighted complexity: {result.weighted}")
print(f"Control: {result.control}")
print(f"Nesting: {result.nesting}")
print(f"Contributions: {result.contributions}")
# Analyze functions individually
functions = analyze_functions(source)
for fn in functions:
print(f"{fn.name}: McCabe={fn.cyclomatic}, Dimensional={fn.dimensional.weighted}")
Domains
| Domain | Weight | Description |
|---|---|---|
| Control (C) | 1.0 | Cyclomatic complexity (branches, loops) |
| Nesting (N) | 1.5 | Depth penalty |
| State (S) | 2.0 | State mutations and transitions |
| Async (A) | 2.5 | Async/await, coroutines |
| Coupling (Λ) | 3.0 | Hidden dependencies, side effects |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file semantic_complexity-0.0.8.tar.gz.
File metadata
- Download URL: semantic_complexity-0.0.8.tar.gz
- Upload date:
- Size: 115.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97fc56814ea2158ef15bae17c3176004e1c2d18a70be1413ec29656c6255b416
|
|
| MD5 |
5cf915fabe9ef16dca6235b2200e667d
|
|
| BLAKE2b-256 |
2ceec182897eb461696b5e62e5cb5f1ae85910d7ea1a451ae5ff54e43833c237
|
Provenance
The following attestation bundles were made for semantic_complexity-0.0.8.tar.gz:
Publisher:
publish-pypi.yml on yscha88/semantic-complexity
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
semantic_complexity-0.0.8.tar.gz -
Subject digest:
97fc56814ea2158ef15bae17c3176004e1c2d18a70be1413ec29656c6255b416 - Sigstore transparency entry: 779820311
- Sigstore integration time:
-
Permalink:
yscha88/semantic-complexity@ae86d165b1891960805688cf671df01d0c6b2319 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/yscha88
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@ae86d165b1891960805688cf671df01d0c6b2319 -
Trigger Event:
push
-
Statement type:
File details
Details for the file semantic_complexity-0.0.8-py3-none-any.whl.
File metadata
- Download URL: semantic_complexity-0.0.8-py3-none-any.whl
- Upload date:
- Size: 53.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2078a910f4fd0199f90a190239eaa8bd7b175ad93b15f077d612901901dc0a95
|
|
| MD5 |
ec6aa3c7a6de0924e04eef3e24ab5a16
|
|
| BLAKE2b-256 |
ad6debebcff912cb60ee1b578927cf07a67d38b5cfc69bf71ccad7044a0f1762
|
Provenance
The following attestation bundles were made for semantic_complexity-0.0.8-py3-none-any.whl:
Publisher:
publish-pypi.yml on yscha88/semantic-complexity
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
semantic_complexity-0.0.8-py3-none-any.whl -
Subject digest:
2078a910f4fd0199f90a190239eaa8bd7b175ad93b15f077d612901901dc0a95 - Sigstore transparency entry: 779820312
- Sigstore integration time:
-
Permalink:
yscha88/semantic-complexity@ae86d165b1891960805688cf671df01d0c6b2319 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/yscha88
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@ae86d165b1891960805688cf671df01d0c6b2319 -
Trigger Event:
push
-
Statement type: