Welcome to IceCream
IceCream: Never use print() to debug again.
icecream, or ic for short, is a Python library that makes print debugging a little sweeter. It's designed to be a more informative and less intrusive alternative to the standard print() function, providing out-of-the-box context for your debugging output.
If you've ever found yourself writing code like print(f'my_var: {my_var}') just to see a variable's value, ic() is for you.
Key Features
- Prints variable names and values: Automatically prints the variable or expression passed to it, along with its value. No more manual string formatting.
- Minimal typing:
ic(my_var)is much faster to type thanprint("my_var", my_var). - Pretty-printed output: Data structures like lists and dictionaries are beautifully formatted for easy reading.
- Syntax highlighting: Output is colorized to improve readability.
- Context-aware: Can optionally print the filename, line number, and parent function where
ic()was called. - Easy to integrate:
ic()returns its argument, so you can sprinkle it throughout your code without refactoring.
A Quick Taste
Here's a simple comparison to see the magic of icecream.
Before (with print()):
import math
def my_function(n):
result = math.sqrt(n)
print(f'n: {n}')
print(f'result: {result}')
return result
my_function(144)
After (with ic()):
import math
from icecream import ic
def my_function(n):
result = math.sqrt(n)
ic(n)
ic(result)
return result
my_function(144)
Output:
ic| n: 144
ic| result: 12.0
Ready to get started? Check out the Quick Start guide or dive deep into the Usage Guide.