Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Library to calculate Python functions cognitive complexity via code

Project description


Build Status Maintainability Test Coverage PyPI version PyPI - Python Version

Library to calculate Python functions cognitive complexity via code.


pip install cognitive_complexity

Tested on python 3.7 and 3.6.


>>> import ast

>>> funcdef = ast.parse("""
... def f(a):
...     return a * f(a - 1)  # +1 for recursion
... """).body[0]

>>> from cognitive_complexity.api import get_cognitive_complexity
>>> get_cognitive_complexity(funcdef)

What is cognitive complexity

Here are some readings about cognitive complexity:

Realization details

This is not precise realization of original algorithm proposed by G. Ann Campbell, but it gives rather similar results. The algorithm gives complexity points for breaking control flow, nesting, recursion, stacks logic operation etc.

Project details

Download files

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

Files for cognitive-complexity, version 0.0.4
Filename, size File type Python version Upload date Hashes
Filename, size cognitive_complexity-0.0.4.tar.gz (3.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page