Linting and formatting Python code in Google Colab.
Project description
colablinter
Overview
colablinter is an IPython magic command extension designed specifically for Jupyter and Google Colab notebooks.
It integrates the high-speed linter ruff to perform code quality checks and enforce standards directly within Jupyter/Colab cells.
It allows developers to lint and format code on a cell-by-cell basis or check the entire notebook with simple commands.
Magic cell Commands
| Command | Type | Description |
|---|---|---|
%%cl_fix |
Cell Magic | Fixes and Formats the current cell's code. |
%%cl_report |
Cell Magic | Displays a linting report for the current cell. |
%cl_autofix |
Line Magic | Activates or deactivates automatic code fixing and formatting before every cell execution. |
%cl_report |
Line Magic | Displays a linting report for the entire saved notebook (requires Google Drive mount). |
After executing a cell magic command, the fixed/reported code is immediately executed (if applicable), maintaining the notebook workflow.
Installation
Requires Python 3.12 or newer.
pip install colablinter
Usage
The extension must be explicitly loaded in the notebook session before use.
%load_ext colablinter
-
Fix and Format cell (
%%cl_fix)%%cl_fixcorrects code and runs the formatter. The cell executes the fixed code.%%cl_fix import sys import os def calculate_long_sum(a,b,c,d,e,f): return {"a":a,"b":b, "sum":(a+b+c)*(d+e+f)}
Fixed Cell:
import os import sys def calculate_long_sum(a, b, c, d, e, f): return {"a": a, "b": b, "sum": (a + b + c) * (d + e + f)}
-
Check cell quality (
%%cl_report)Use
%%cl_reportto see linting reports for the code below the command.%%cl_report def invalid_code(x): return x + y # 'y' is not defined
Output:
[ColabLinter:INFO] F821 Undefined name `y` --> notebook_cell.py:2:16 | 1 | def invalid_code(x): 2 | return x + y # 'y' is not defined | ^ | Found 1 error.
Note: After the report is displayed, the code in the cell executes as normal. If errors exist (like F821), execution will fail.
-
Check entire notebook (
%cl_report)Use line magic
%cl_reportto check across the entire saved notebook file (requires the notebook to be saved to Google Drive and mounted).%cl_report
-
Activate/Deactivate Auto Fix (
%cl_autofix) The%cl_autofixline magic allows you to automatically fix code before every code cell is executed.To Activate Auto Fixing:
%cl_autofix on # %cl_autofix off when you want to deactivate
Known Caveats & Troubleshooting
Magic Command Execution: When using %%cl_report or %%cl_fix with %cl_autofix on active, the autofix mechanism is temporarily suppressed during the final execution step to prevent infinite loops or dual checks. If you want to disable auto-fixing, use %cl_autofix 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.1.1.tar.gz.
File metadata
- Download URL: colablinter-0.1.1.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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 |
cb90f268a1727e8e1e23162f8e1386c1374fff0adf224dbab3dc90aa5b57a98c
|
|
| MD5 |
5633df1c3b499ac4790c1816dd54e4b2
|
|
| BLAKE2b-256 |
ebc3d82c71a866a67668f7ab5563bb2d21c86425d4ffc10a6adad46c0af8f43c
|
File details
Details for the file colablinter-0.1.1-py3-none-any.whl.
File metadata
- Download URL: colablinter-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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 |
7ecb2cfa8693667ff9ce7964bbcb5ebc3543eb80d8a0e4cb22b7dc05804bfdc6
|
|
| MD5 |
a02ed377cb4294675e0e43230ce12aa4
|
|
| BLAKE2b-256 |
095da1737a546a5951e4350ca698543139fd9691538fdebd5ed8ff28aab7bf8f
|