Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

semantic_complexity-0.0.9.tar.gz (116.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

semantic_complexity-0.0.9-py3-none-any.whl (55.4 kB view details)

Uploaded Python 3

File details

Details for the file semantic_complexity-0.0.9.tar.gz.

File metadata

  • Download URL: semantic_complexity-0.0.9.tar.gz
  • Upload date:
  • Size: 116.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for semantic_complexity-0.0.9.tar.gz
Algorithm Hash digest
SHA256 3a50ccf98bb08e0a18add4580158d451b3b5b5b7bd0ae17eafca45d824f0894a
MD5 434b1e7c9d482c7c6f017c29f7df76fc
BLAKE2b-256 20969a416f8da36f842f68feb22479b457a05817dd22a59b4aaa9d873ee0c3ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for semantic_complexity-0.0.9.tar.gz:

Publisher: publish-pypi.yml on yscha88/semantic-complexity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file semantic_complexity-0.0.9-py3-none-any.whl.

File metadata

File hashes

Hashes for semantic_complexity-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 64f7f3f1850eccf03d7f50d51921ad23696533e112a5bf36901fa73b2ad4add9
MD5 a221bfc9f7e91c340151cb50c4fbf8f1
BLAKE2b-256 00b2c8c4d62d18a67ddb74d3eb488717f7fc409ab1ef77a912c5ac0a833f589f

See more details on using hashes here.

Provenance

The following attestation bundles were made for semantic_complexity-0.0.9-py3-none-any.whl:

Publisher: publish-pypi.yml on yscha88/semantic-complexity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page