Quick Start Guide

This guide will get you up and running with icecream in just a few minutes.

1. Import ic

First, install icecream as shown in the Installation guide. Then, import the ic function into your Python script.

from icecream import ic

2. Inspect a Variable

Instead of using print() to check a variable's value, use ic().

from icecream import ic

def square(n):
    return n * n

result = square(8)

ic(result)

This will print the variable name and its value directly to your console:

ic| result: 64

Notice how ic automatically includes the result variable name in the output. It can also handle complex expressions:

data = {'user': {'name': 'Alice', 'id': 101}}
ic(data['user']['name'])

Output:

ic| data['user']['name']: 'Alice'

3. Inspect Program Execution

Sometimes you just want to know if a certain line of code is being executed. Call ic() with no arguments to print the filename, line number, and function name.

from icecream import ic

def process_data(data):
    ic() # Check if this function is called
    if not data:
        ic() # Check if this block is entered
        return None

    # ... processing logic ...
    return True

process_data([])

Output:

ic| your_script.py:4 in process_data()
ic| your_script.py:6 in process_data()

This provides a quick and easy way to trace the execution path of your code without manually writing log messages.

That's the basic usage! For more powerful features, explore the Usage Guide and Configuration pages.