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 | Provenance | Actions |
|---|---|---|---|---|
| circular_imports-0.2.1.tar.gz | 4.7 kB | Without provenance | Details for circular_imports-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| circular_imports-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for circular_imports-0.2.1-py3-none-any.whl |
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
|
Security for circular-imports 0.2.1
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.