Linting and formatting Python code in Google Colab.
Project description
Overview
colablinter is an IPython magic command extension designed for Jupyter and Google Colab notebooks.
It integrates the high-speed linter ruff to perform code quality checks and formatting directly within Jupyter/Colab cells.
It allows developers to lint code on a cell-by-cell basis with simple commands.
Magic cell Commands
| Command | Description |
|---|---|
%clautoformat |
Activates or deactivates automatic import sorting, formatting, and execution time display before every cell. |
%%clcheck |
Displays a linting report for the current cell. |
After executing a cell magic command, the checked/formatted code is immediately executed (if applicable), maintaining the notebook workflow.
Installation
Just run it in colab:
!uv pip install colablinter
The extension must be explicitly loaded in the notebook session before use.
%load_ext colablinter
Once loaded, %clautoformat is activated by default to keep your code clean from the start.
Usage
-
Activate/Deactivate Auto Fix (
%clautoformat)The
%clautoformatline magic allows you to automatically fix code before every code cell is executed.import math, sys; class Example( object ): def __init__ ( self, bar ): if bar : bar+=1; bar=bar* bar ; return bar else: some_string = "foo" return (sys.path, some_string)
Fixed Cell:
import math import sys class Example(object): def __init__(self, bar): if bar: bar += 1 bar = bar * bar return bar else: some_string = "foo" return (sys.path, some_string)
To deactivate auto fixing:
%clautoformat off # %clautoformat on when you want to activate
-
Check cell quality (
%%clcheck)Use
%%clcheckto see linting reports for the code below the command. After the report is displayed, the code in the cell executes as normal.%%clcheck def invalid_code(x): return x + y
Output:
[ColabLinter:INFO] F821 Undefined name `y` --> tmp.py:2:16 | 1 | def invalid_code(x): 2 | return x + y | ^ | Found 1 error. [ColabLinter:INFO] ✔ Done | 0.015s
Note on F401: The linter is explicitly configured to ignore F401 errors (unused imports). This is to ensure compatibility with the stateful nature of Jupyter/Colab notebooks, where imports in one cell may be necessary for code execution in subsequent cells, preventing unintended breakage of the notebook's execution flow.
Known Caveats & Troubleshooting
Magic Command Execution: When using magic or terminal commands while %clautoformat is active, the auto-format mechanism is temporarily suppressed during the final execution step to prevent infinite loops or dual checks. If you want to disable auto-formatting, use %clautoformat off
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 colablinter-0.3.2.tar.gz.
File metadata
- Download URL: colablinter-0.3.2.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed4c9b43b3ce84b1cafc415ca2aa65e0175cfad4a7dc9115ca919203069728ab
|
|
| MD5 |
9b685958f5654fd54cb2957f09d5e21e
|
|
| BLAKE2b-256 |
7edfbe2e6f42d97a426e84b47569a986cfc40254670ad7f217331dab1973cf68
|
File details
Details for the file colablinter-0.3.2-py3-none-any.whl.
File metadata
- Download URL: colablinter-0.3.2-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3d2416c96f52f09b29e40476fcfdfaaaff4d9de410fac7709892aa075e69a60
|
|
| MD5 |
3cffc6032616c6f7521a7fb4695caf73
|
|
| BLAKE2b-256 |
a83903dfa220c9e6d2ffc906867d91af051bda64024d176671301bb9071dda5d
|