Move inline imports (imports inside function bodies) to the top of Python files.
Project description
clawde
Move inline imports — imports buried inside function bodies — back to the top of the file, where they belong.
Imports inside try/except blocks, inside if TYPE_CHECKING: blocks, or marked with # noqa are left in place.
Install / run
Run without installing:
uvx clawde --help
Or install it:
uv tool install clawde
# or
pipx install clawde
Usage
By default, clawde runs in dry-run mode and prints a table of imports it would move. Pass --write to actually apply the changes.
# Show what would change in the current directory
clawde
# Apply changes
clawde --write
# Target specific paths
clawde src/ scripts/foo.py
Example output
❯ clawde myproject/
Scanning Python files... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
Inline Import Analysis
Status File:Line Import Reason
🟢 Skipped manage.py:13 from django.core.management import Inside try/except block
execute_from_command_line
🟢 Skipped apps/team/cache.py:9 from .models import AboutPage # noqa: PLC0415 Marked with # noqa
🟢 Skipped apps/til/apps.py:18 from .signals import post_delete # noqa Marked with # noqa
🟡 Move apps/blog/0024.py:16 from wagtail.images import get_image_model
🟡 Move apps/blog/0024.py:17 from wagtail.models import Page, Site
Total: 5 imports analyzed
To Move: 2
Skipped: 3
Note: This was a dry-run. No files were modified.
Use --write to apply changes.
What it does
For every .py file under the given paths, clawde parses the source with ast and looks for import / from ... import statements inside function bodies. Each finding is reported as:
| Status | Meaning |
|---|---|
| Move | Will be lifted to the top of the file (under any __future__ imports). |
| Skipped | Left in place — inside try, TYPE_CHECKING, or marked # noqa. |
| Error | File could not be parsed. |
Hidden directories (any path segment starting with .) are always skipped — this catches .git, .venv, .tox, .mypy_cache, .ruff_cache, .pytest_cache, and so on.
In addition, the following directory names are skipped by default:
node_modulesvenvbuilddist__pycache__site-packageshtmlcov
Configuration
You can override the named exclude list by adding a [tool.clawde] section to your pyproject.toml:
[tool.clawde]
exclude = ["build", "dist", "node_modules", "vendor", "generated"]
- The list replaces the default — include any defaults you still want.
- Entries are matched against path segments (folder names), not full paths or globs.
- Hidden directories are skipped regardless of this setting.
- Set
exclude = []to scan every non-hidden directory.
clawde looks for a pyproject.toml by walking up from the current working directory.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clawde-0.1.0.tar.gz.
File metadata
- Download URL: clawde-0.1.0.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a24b08bebe5e973195197dd5daed3a651cfa2c08762f8009a6bacbffacc65cb6
|
|
| MD5 |
1c12cae40e1248730087601b331a9a8f
|
|
| BLAKE2b-256 |
6c832fed55130521eb5fb60ce81b21bd5bd0cccbf152adcab4aacebda7c08c89
|
File details
Details for the file clawde-0.1.0-py3-none-any.whl.
File metadata
- Download URL: clawde-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ef359a6112985294ec82f321a356ffbf67f6ad5a534d85f904b0e9a2fab8073
|
|
| MD5 |
92146c55955c3a949ff59befd9cdde4c
|
|
| BLAKE2b-256 |
d0004a21cd0b5a6482b4b91eab5884bea4d30169689fa73694c4dd204574df8f
|