Skip to main content

PyCyclo

py-cyclo is a general-purpose command-line tool for analyzing and validating cyclomatic complexity in Python code. Designed for developers who want to maintain clean, testable, and maintainable code, py-cyclo provides detailed reports and enforcement mechanisms to ensure your codebase doesn't spiral out of control.

License Continuous Integration Release PyPI


🚀 Features

  • Measure cyclomatic complexity of Python functions and methods
  • Set complexity thresholds and enforce them via CLI
  • Supports per-file, per-function, or project-wide analysis
  • JSON, plain-text, or colorized output formats
  • Integrates easily into CI/CD pipelines

📦 Installation

You can install py-cyclo via pip:

pip install py-cyclo

Or install directly from GitHub:

pip install git+https://github.com/ocrosby/py-cyclo.git

🛠️ Usage

Usage: cyclo [OPTIONS] PATH

Example Command

# Validate the cyclomatic complexity of all Python files in the current directory
# and its subdirectories is less than or equal to 10
cyclo --max-complexity 10 --exclude-dirs .venv,tests .

or

Example Command

# Validate the cyclomatic complexity of all Python files in the current directory
# and its subdirectories is less than or equal to 10
cyclo -m 10 -e .venv,tests .

Example Output

Checking cyclomatic complexity in "/path/to/project"...

2 functions exceed the maximum complexity of 4:
+-------------------------------+--------------+-----------+-----------------------------------------------+
| Name                          |   Complexity |   Line No | Filename                                      |
+===============================+==============+===========+===============================================+
| example_function              |            6 |        10 | example_module.py                             |
+-------------------------------+--------------+-----------+-----------------------------------------------+
| another_function              |            5 |        20 | another_module.py                             |
+-------------------------------+--------------+-----------+-----------------------------------------------+

5 functions with a complexity < 4:
+-------------------------------+--------------+-----------+-----------------------------------------------+
| Name                          |   Complexity |   Line No | Filename                                      |
+===============================+==============+===========+===============================================+
| simple_function               |            3 |        15 | simple_module.py                              |
+-------------------------------+--------------+-----------+-----------------------------------------------+
| helper_function               |            2 |        25 | helper_module.py                              |
+-------------------------------+--------------+-----------+-----------------------------------------------+
| utility_function              |            2 |        30 | utility_module.py                             |
+-------------------------------+--------------+-----------+-----------------------------------------------+
| another_helper_function       |            1 |        35 | another_helper_module.py                      |
+-------------------------------+--------------+-----------+-----------------------------------------------+
| yet_another_function          |            1 |        40 | yet_another_module.py                         |
+-------------------------------+--------------+-----------+-----------------------------------------------+

Maximum complexity: 6

FAILED - Maximum complexity 4 exceeded by 2

Functions with complexity greater than the maximum allowed:
example_function: 6
another_function: 5

Options

Flag Description
--max-complexity, -m Set the maximum allowed complexity per function
--exclude-dirs, -e Comma-separated list of directories to exclude
--help Show CLI help

🔧 Configuration

You can use a .cyclo configuration file to set default options for cyclo. This file should be placed in the root directory of your project. Here is an example configuration:

[cyclo]
max_complexity = 10
exclude_dirs = .venv,tests,node_modules

You can then run cyclo without any options, and it will use the settings from the configuration file:

Example Command Using Configuration

# Run py-cyclo using the defaults from the .cyclo file
cyclo .

If both the .cyclo file and command-line arguments are provided, the command-line arguments take precedence.

This update ensures that users are aware of the new exclude_dirs argument and the .cyclo configuration file, and it provides clear examples of how to use them.


🧪 Testing

To run the test suite:

pip install --upgrade pip
pip install invoke
pip install ".[dev]"
invoke test

🤝 Contributing

Contributions are welcome! To get started:

  1. Fork this repo
  2. Create a new branch (git checkout -b feature/my-feature)
  3. Make your changes
  4. Write tests and ensure everything passes
  5. Submit a pull request

Please follow the Contributor Covenant code of conduct.


📄 License

This project is licensed under the MIT License. See the LICENSE file for details.


🙌 Acknowledgments

  • Inspired by tools like radon
  • Built with ❤️ using Click and ast


References

📬 Contact

Feel free to reach out via GitHub Issues or submit feature requests and bugs.

Metadata

Release files for py-cyclo 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-cyclo 1.2.0
File Size Uploaded Provenance Actions
py_cyclo-1.2.0.tar.gz 8.2 kB Without provenance Details for py_cyclo-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-cyclo 1.2.0
File Interpreter ABI Platform Actions
py_cyclo-1.2.0-py2.py3-none-any.whl Python 2, Python 3 none any Details for py_cyclo-1.2.0-py2.py3-none-any.whl

Total release size: 17.1 kB

Release files / py_cyclo-1.2.0.tar.gz

Download URL py_cyclo-1.2.0.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0b5d599d1aa532249e33f9a543f5e61e984b0979f9438869d6be91bc5d36b45e
BLAKE2b-256 checksum
How to use checksums
958bc8626b9cd39947ec163d90bcbc81bc4bde33c1ccaf0b56fdd7050f24f8c9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / py_cyclo-1.2.0-py2.py3-none-any.whl

Download URL py_cyclo-1.2.0-py2.py3-none-any.whl
Size 8.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
20500d66b0379a18b28ddccccd9a04e1dbe7d76e23ae1ea9ba014fe5ceac7406
BLAKE2b-256 checksum
How to use checksums
df255524e286820e5de8f57f8c9487488fe81d605324101507e4d40a86170bdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Security for py-cyclo 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page