Skip to main content

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. Try it here: Open In Colab

Magic cell Commands

Command Description
%clautofix Activates or deactivates automatic fix including import sorting, formatting, and execution time display before every cell.
%%clcheck Displays a linting report for the current cell.
%%clunsafefix Performs a linting check and applies "unsafe" fixes that might change code logic (e.g., changing mutable default arguments).

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, %clautofix is activated by default to keep your code clean from the start.

Usage

  1. Activate/Deactivate Auto Fix (%clautofix)

    The %clautofix line 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:
        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:

    %clautofix off # %clautofix on when you want to activate
    
  2. Check cell quality (%%clcheck)

    Use %%clcheck to 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.
    
  3. Unsafe Fix (%%clunsafefix)

    Use %%clunsafefix when you want ruff to aggressively clean up your code, including rules that are typically considered risky (like fixing mutable default arguments or complex refactoring).

    %%clunsafefix
    
    def process_data(new_item, current_list=[]):
        old_item = "redundant"
        if new_item:
            if isinstance(new_item, str):
                current_list.append(new_item)
    
        if len(current_list) > 0:
            return True
        else:
            return False
    

    Fixed Cell:

    def process_data(new_item, current_list=None):
        if current_list is None:
            current_list = []
        if new_item and isinstance(new_item, str):
            current_list.append(new_item)
    
        return len(current_list) > 0
    

Known Caveats & Troubleshooting

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.

Magic Command Execution: When using magic or terminal commands while %clautofix 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 %clautofix off

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

colablinter-0.4.4.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

colablinter-0.4.4-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file colablinter-0.4.4.tar.gz.

File metadata

  • Download URL: colablinter-0.4.4.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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

Hashes for colablinter-0.4.4.tar.gz
Algorithm Hash digest
SHA256 6a09abb58b623638d39a6b5c80275efc80e927583a5fdc3acb2bed02b7cd7545
MD5 07dcdb377154e7ec7f8a838ce9120005
BLAKE2b-256 3e85c74c3675831d2992ecc96f3120a991ae7cdee0061ee043b9b90139a6ae8f

See more details on using hashes here.

File details

Details for the file colablinter-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: colablinter-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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

Hashes for colablinter-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f7c7116ead036b73e6807548ee94e4161623e4b6c39ded58c7756d8b766e9cc1
MD5 44d4b65ece37426220ea2f37d5f47136
BLAKE2b-256 32c18fd58d4142d06c6256201b0c4c1fe67fe0ad67e284eed883235701055595

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.4.4 This release

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.14

2 files

0.0.13

2 files

0.0.12

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page