IceCream

2.2.0 · active · verified Fri Apr 10

Never use print() to debug again: inspect variables, expressions, and program execution with a single, simple function call. IceCream is a Python library that makes debugging effortless and more readable. It's currently at version 2.2.0 and has an active release cadence with frequent minor updates.

Warnings

Install

Imports

Quickstart

Import `ic` and use it to wrap variables or expressions for detailed output, including variable names, values, and context. Call `ic()` without arguments to log filename, line number, and function name. `ic.disable()` and `ic.enable()` can control output globally.

from icecream import ic

def calculate_sum(a, b):
    result = a + b
    ic(a, b, result) # Inspect multiple variables
    return result

my_num1 = 5
my_num2 = 10
ic(my_num1, my_num2) # Inspect individual variables
final_sum = calculate_sum(my_num1, my_num2)
ic(f"The final sum is: {final_sum}") # Inspect expressions and strings

class MyClass:
    def __init__(self, name):
        self.name = name
        ic(self.name)

obj = MyClass("IceCreamExample")

ic.disable() # Disable all ic() output
ic("This line will not be printed.")
ic.enable() # Re-enable ic() output
ic("This line will be printed again.")

view raw JSON →