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

uv를 통한 설치

# 글로벌 도구로 설치
uv tool install semantic-complexity

# 또는 일회성 실행
uvx semantic-complexity path/to/file.py

MCP 서버 설치

Claude Code에서 MCP 서버로 사용하려면:

# MCP 서버 추가 (Python 버전)
claude mcp add sc-py "uvx --from semantic-complexity semantic-complexity-py-mcp"

기존 MCP 업데이트/재설치

# 1. 기존 MCP 삭제
claude mcp remove sc-py

# 2. 캐시 정리 (최신 버전 반영)
uv cache clean semantic-complexity --force

# 3. 재설치
claude mcp add sc-py "uvx --from semantic-complexity semantic-complexity-py-mcp"

# 설치 확인
claude mcp list

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.23.tar.gz (190.9 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.23-py3-none-any.whl (108.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: semantic_complexity-0.0.23.tar.gz
  • Upload date:
  • Size: 190.9 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.23.tar.gz
Algorithm Hash digest
SHA256 b4b2c5458f2d7e12dcaafd61ff367ad0de9b7ce3587a8501d1dcd29e3a8c897b
MD5 b04dceedf136c0c2b8d8d3e1738647a6
BLAKE2b-256 3e47623a2f6290e302163f7c69b3208f36a0a78edc6959d267251c82e6d38e67

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for semantic_complexity-0.0.23-py3-none-any.whl
Algorithm Hash digest
SHA256 16fb9f6f2f5a00dae5fa3f35a05281a5a3542ef7d95ee7e2005ca560c18c5620
MD5 2adacf5e77ef01985a00a7504e7bbde7
BLAKE2b-256 0885f13ba8174ec06b9ab9dd593b5916c1bf6a914a91ff4e7e60b0dc84dcc17a

See more details on using hashes here.

Provenance

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