Circular Imports
If you see an error like this:
ImportError: cannot import name 'some_module'
or
ImportError: cannot import name 'some_module' from partially initialized module 'path.to.module' (most likely due to a circular import)
then you have a circular import in your code.
This library helps you to detect circular imports in Python code to fix them.
Installation
pip install circular-imports
Usage
CLI
Example:
circular-imports path/to/python/project/dir --output output_file.dot --exclude .venv,build
Parameters:
path: path to the Python project directory--output: output file, this can be a.dot,.mermaid. When empty, the output will be printed to the console.--exclude: comma-separated list of directories to exclude from the search
Exits with code 0 if no circular imports are found, 1 otherwise.
Python
from unittest import TestCase
from circular_imports import cycles_in_path
class TestCircularDeps(TestCase):
def test_no_cycles(self):
cycles = cycles_in_path(".", exclude=".venv,build")
self.assertEqual(cycles, set())
License
MIT
Metadata
Release files for circular-imports 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| circular_imports-0.1.5.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| circular_imports-0.1.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.6 kB
Release files / circular_imports-0.1.5.tar.gz
| Download URL | circular_imports-0.1.5.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2eda5dd4388203ed64bde5eae50f26a13854d35e573080e38c46dde404ce8081
|
|
BLAKE2b-256 checksum How to use checksums |
6f3773432890bd3ee4b33fb85b99b42aff159ce8712117c105924ebe00da4df6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / circular_imports-0.1.5-py3-none-any.whl
| Download URL | circular_imports-0.1.5-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3bfba22b5131731e0e7f6cf5c3f9506124d600218ee8c99900ba9b3649202454
|
|
BLAKE2b-256 checksum How to use checksums |
b9bc9a0befc0f009050ec4fd1852a6d8bea5aeff9f22f1ffc7a9fb2afa411647
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|