{"id":25869957,"url":"https://github.com/melevir/cognitive_complexity","last_synced_at":"2026-03-11T07:33:58.856Z","repository":{"id":41322084,"uuid":"218568372","full_name":"Melevir/cognitive_complexity","owner":"Melevir","description":"Library to calculate Python functions cognitive complexity via code.","archived":false,"fork":false,"pushed_at":"2022-08-09T07:45:50.000Z","size":32,"stargazers_count":40,"open_issues_count":3,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-29T09:07:41.501Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Melevir.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-30T16:07:54.000Z","updated_at":"2024-12-27T08:20:17.000Z","dependencies_parsed_at":"2022-08-10T01:54:16.560Z","dependency_job_id":null,"html_url":"https://github.com/Melevir/cognitive_complexity","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Melevir%2Fcognitive_complexity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Melevir%2Fcognitive_complexity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Melevir%2Fcognitive_complexity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Melevir%2Fcognitive_complexity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Melevir","download_url":"https://codeload.github.com/Melevir/cognitive_complexity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241464996,"owners_count":19967237,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-02T05:29:20.348Z","updated_at":"2026-03-11T07:33:58.812Z","avatar_url":"https://github.com/Melevir.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# congnitive-complexity\n\n[![Build Status](https://travis-ci.org/Melevir/cognitive_complexity.svg?branch=master)](https://travis-ci.org/Melevir/cognitive_complexity)\n[![Maintainability](https://api.codeclimate.com/v1/badges/853d47d353e7becc9f09/maintainability)](https://codeclimate.com/github/Melevir/cognitive_complexity/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/853d47d353e7becc9f09/test_coverage)](https://codeclimate.com/github/Melevir/cognitive_complexity/test_coverage)\n[![PyPI version](https://badge.fury.io/py/cognitive-complexity.svg)](https://badge.fury.io/py/cognitive-complexity)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/cognitive-complexity)\n\nLibrary to calculate Python functions cognitive complexity via code.\n\n## Installation\n\n```bash\npip install cognitive_complexity\n```\n\n## Usage\n\n```python\n\u003e\u003e\u003e import ast\n\n\u003e\u003e\u003e funcdef = ast.parse(\"\"\"\n... def f(a):\n...     return a * f(a - 1)  # +1 for recursion\n... \"\"\").body[0]\n\n\u003e\u003e\u003e from cognitive_complexity.api import get_cognitive_complexity\n\u003e\u003e\u003e get_cognitive_complexity(funcdef)\n1\n```\n\n### Flake8-Cognitive-Complexity Extension\n\nPerhaps the most common way to use this library (especially if you are\nalready using the [Flake8 linter](https://flake8.pycqa.org/en/latest/))\nis to use the\n[flake8-cognitive-complexity extension](https://github.com/Melevir/flake8-cognitive-complexity).\nIf you run Flake8 with this extension installed, Flake8 will let you know\nif your code is too complex. For more details and documentation, visit the\n[flake8-cognitive-complexity extension repository](https://github.com/Melevir/flake8-cognitive-complexity).\n\n## What is cognitive complexity\n\nHere are some readings about cognitive complexity:\n\n- [Cognitive Complexity, Because Testability != Understandability](https://blog.sonarsource.com/cognitive-complexity-because-testability-understandability);\n- [Cognitive Complexity: A new way of measuring understandability](https://www.sonarsource.com/docs/CognitiveComplexity.pdf),\n  white paper by G. Ann Campbell;\n- [Cognitive Complexity: the New Guide to Refactoring for Maintainable Code](https://www.youtube.com/watch?v=5C6AGTlKSjY);\n- [Cognitive Complexity](https://docs.codeclimate.com/docs/cognitive-complexity)\n  from CodeClimate docs;\n- [Is Your Code Readable By Humans? Cognitive Complexity Tells You](https://www.tomasvotruba.cz/blog/2018/05/21/is-your-code-readable-by-humans-cognitive-complexity-tells-you/).\n\n## Realization details\n\nThis is not precise realization of original algorithm\nproposed by [G. Ann Campbell](https://github.com/ganncamp),\nbut it gives rather similar results.\nThe algorithm gives complexity points for breaking control flow, nesting,\nrecursion, stacks logic operation etc.\n\n## Contributing\n\nWe would love you to contribute to our project. It's simple:\n\n- Create an issue with bug you found or proposal you have. Wait for\n  approve from maintainer.\n- Create a pull request. Make sure all checks are green.\n- Fix review comments if any.\n- Be awesome.\n\nHere are useful tips:\n\n- You can run all checks and tests with `make check`. Please do it\n  before TravisCI does.\n- We use [BestDoctor python styleguide](https://github.com/best-doctor/guides/blob/master/guides/python_styleguide.md).\n  Sorry, styleguide is available only in Russian for now.\n- We respect [Django CoC](https://www.djangoproject.com/conduct/).\n  Make soft, not bullshit.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmelevir%2Fcognitive_complexity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmelevir%2Fcognitive_complexity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmelevir%2Fcognitive_complexity/lists"}