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.2.1
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.2.1.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| circular_imports-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.6 kB
Release files / circular_imports-0.2.1.tar.gz
| Download URL | circular_imports-0.2.1.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a0c9fd6ff13557bc36507c678b3d1d18e2e5ae0a912b3dc500470a45cac3e48
|
|
BLAKE2b-256 checksum How to use checksums |
20861187304b9792cd2b038b50b05fd3812f87c1f2265d0026ca32c6c2e7ee65
|
| 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.2.1-py3-none-any.whl
| Download URL | circular_imports-0.2.1-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
69b4137e84c6f3718699fd6dcc5ea619b97efa068392ecba8bef732af029d836
|
|
BLAKE2b-256 checksum How to use checksums |
ce6f324363e382cc979aa61b9ab8948b7d5c041138feb3ed41db692b72df1d61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|