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 (1D): {result.control}")
print(f"Nesting (2D): {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}")

Dimensions

Dimension Weight Description
1D Control 1.0 Cyclomatic complexity (branches, loops)
2D Nesting 1.5 Depth penalty
3D State 2.0 State mutations and transitions
4D Async 2.5 Async/await, coroutines
5D Coupling 3.0 Hidden dependencies, side effects

License

MIT

\x00 \x00 \x00 \x00 \x00 \x00

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.2.tar.gz (39.3 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.2-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: semantic_complexity-0.0.2.tar.gz
  • Upload date:
  • Size: 39.3 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.2.tar.gz
Algorithm Hash digest
SHA256 8a65fbc72982fbdbe63ebc86a657fd9c874c23e6662f5d672bd29b32c7de27c8
MD5 aec21004ce6a4aebf415745cf0b24702
BLAKE2b-256 b983625336d44c238b155f6b8bdd4910ae6e1ff704d4bc518a5dd118f2451507

See more details on using hashes here.

Provenance

The following attestation bundles were made for semantic_complexity-0.0.2.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.2-py3-none-any.whl.

File metadata

File hashes

Hashes for semantic_complexity-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 766f7aa0f702a57dd2c523bf64764747ccdbd0c96cd0800f5abf3906d2beac29
MD5 de147ecdcdccacd062da4a92491906a4
BLAKE2b-256 a82aa95b07afcbd762711c3d03e59ec2219f62080806b63baac88fa177e59c1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for semantic_complexity-0.0.2-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