Non-intrusive system for logging and debug printing.
Project description
🖋️ Ictr is a system for logging and debug printing in Python applications. It provides a clean, type-safe API for emitting diagnostic messages with minimal boilerplate, featuring standard message flavors, hierarchical trace levels for debugging depth, automatic exception tracebacks, and optional rich rendering with colors and styling.
Designed as an alternative to traditional print debugging and verbose logging setup, ictr can install a global dispatcher into the Python builtins, similar to the well-known icecream package, for effortless access throughout your application — no import statements needed in every module. Perfect for both quick debugging sessions and production logging with per-module configuration.
Key Features ⭐
🎨 Standard Message Flavors: Pre-configured note, monition, error, abort, future, success, and advice flavors with semantic labels and optional emoji/color styling.
🔢 Hierarchical Trace Levels: Ten trace levels (0-9) with automatic indentation for visualizing call depth and execution flow.
💥 Automatic Exception Tracebacks: errorx and abortx flavors capture and format active exceptions with full stack traces.
🌳 Module Hierarchy: Global and per-module configs with inheritance for precise control over active flavors, trace levels, output formatting, etc….
🚀 Zero-Import Access: Global dispatcher available in builtins after initial setup — no import statements needed in every module.
🖨️ Printer Factory: Dynamically associate output functions with reporters based on module name, flavor, etc…. Swap in customized print, logging, or other sinks as desired.
📚 Library-Friendly: Non-intrusive registration for libraries without stepping on application debugger/logging configuration.
Installation 📦
Method: Install Python Package
Install via uv pip command:
uv pip install ictr
Or, install via pip:
pip install ictr
Examples 💡
For more detailed examples, please see the examples documentation.
Basic Usage
Install an ictr dispatcher as a Python builtin (default alias, ictr) and then use it anywhere in your codebase:
import ictr
ictr.install( )
# Emit messages with different flavors
ictr( 'note' )( 'Application started.' ) # NOTE| Application started.
ictr( 'error' )( 'Connection failed.' ) # ERROR| Connection failed.
ictr( 'success' )( 'Task completed.' ) # SUCCESS| Task completed.
Trace Levels
Use numeric trace levels (0-9) for hierarchical debugging output:
import ictr
ictr.install( trace_levels = { None: 3 } ) # Enable levels 0-3 globally
ictr( 0 )( 'Top-level operation' ) # TRACE0| Top-level operation
ictr( 1 )( 'Sub-operation details' ) # TRACE1| Sub-operation details
ictr( 2 )( 'More detail' ) # TRACE2| More detail
ictr( 4 )( 'Too verbose' ) # (suppressed - level > 3)
Exception Handling
Use errorx or abortx flavors to capture active exceptions with tracebacks:
import ictr
ictr.install( )
try:
result = 1 / 0
except ZeroDivisionError:
ictr( 'errorx' )( 'Calculation failed.' )
# ERROR| Calculation failed.
#
# [ZeroDivisionError] division by zero
# File 'example.py', line 8, in <module>
# result = 1 / 0
Library Integration
Libraries can register their own configurations without overriding those of the application:
# mylibrary/__init__.py
import ictr
ictr.register_address( 'mylibrary' )
When install is called by the application, any addresses that were previously registered via register_address are incorporated into the installed dispatcher. This allows applications to setup output after libraries have registered their configurations.
Motivation 🚚
Why ictr?
There is nothing wrong with the icecream or logging packages. However, there are times that the author of ictr (and its predecessor, icecream-truck) has wanted, for various reasons, more than these packages inherently offer:
Coexistence: Application and libraries can coexist without configuration clashes.
Library developers are strongly advised not to create custom levels in logging.
Library developers are advised on how to avoid polluting stderr in logging, when an application has not supplied a configuration.
Loggers propagate upwards by default in logging. This means that libraries must explicitly opt-out of propagation if their authors want to be good citizens and not contribute to noise pollution / signal obfuscation.
Granularity: Control of debug output by depth threshold and subsystem.
Only one default debugging level (DEBUG) with logging. Libraries cannot safely extend this. (See point about coexistence).
No concept of debugging level with ic builtin. Need to orchestrate multiple icecream.IceCreamDebugger instances to support this. (In fact, this is what icecream-truck does.)
While logger hierarchies in logging do support the notion of software subsystems, hierarchies are not always the most convenient or abbreviated way of representing subsystems which span parts or entireties of modules.
Signal: Prevention of undesirable library chatter.
The logging root logger will log all messages, at its current log level or higher, which propagate up to it. Many Python libraries have opt-out rather than opt-in logging, so you see all of their DEBUG and INFO spam unless you surgically manipulate their loggers or squelch the overall log level.
Use of the ic builtin is only recommended for temporary debugging. It cannot be left in production code without spamming. While the enabled flag on the ic builtin can be set to false, it is easy to forget and also applies to every place where ic is used in the code. (See point about granularity.)
Extensibility: More natural integration with packages like rich via robust recipes.
While it is not difficult to change the argToStringFunction on ic to be rich.pretty.pretty_repr, there is some repetitive code involved in each project which wants to do this. And, from a safety perspective, there should be a fallback if rich fails to import.
Similarly, one can add a rich.logging.RichHandler instance to a logger instance with minimal effort. However, depending on the the target output stream, one may also need to build a rich.console.Console first and pass that to the handler. This handler will also compete with whatever handler has been set on the root logger. So, some care must be taken to prevent propagation. Again, this is repetitive code across projects and there are import safety fallbacks to consider.
About the Name 📝
The name ictr has multiple origins and interpretations:
🍦 Shortened from icecream-truck: The package from which ictr is derived and redesigned. The abbreviation maintains the connection to its predecessor while establishing its own identity.
🎯 Short and memorable: Four letters that are easy to type and remember. The Python package distribution name and import name are the same, reducing cognitive overhead.
📊 Backronym interpretations: While ictr works perfectly well as just a name, several backronyms capture different aspects of its purpose:
Inspection-Capable Trace Reporting (emphasizes diagnostic capabilities)
Intelligent Configurable Trace Reporter (emphasizes smart behavior)
I See Textual Reports (playful take on the phonetic sound)
Pronunciation? You can spell it out. But, if that is too many syllables, then maybe “eyes-tra” but probably not “ick-ter”, because it is not that revulsive.
Contribution 🤝
Contribution to this project is welcome! However, it must follow the code of conduct for the project.
Please file bug reports and feature requests in the issue tracker or submit pull requests to improve the source code or documentation.
For development guidance and standards, please see the development guide.
Additional Indicia
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 ictr-1.0a0.tar.gz.
File metadata
- Download URL: ictr-1.0a0.tar.gz
- Upload date:
- Size: 33.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c0de4447126aa237162b42207c159c7eb1d2f4fe3e94517d753adaefa832a03
|
|
| MD5 |
878a9bb0b63bf49036694306774a1a16
|
|
| BLAKE2b-256 |
ea7d5fa80042599f6881c24e72af28ebbaf10cb179b977adcdcc798fff881c5a
|
Provenance
The following attestation bundles were made for ictr-1.0a0.tar.gz:
Publisher:
releaser.yaml on emcd/python-ictr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ictr-1.0a0.tar.gz -
Subject digest:
6c0de4447126aa237162b42207c159c7eb1d2f4fe3e94517d753adaefa832a03 - Sigstore transparency entry: 760661360
- Sigstore integration time:
-
Permalink:
emcd/python-ictr@28b9dd1fc4f9e9e2053b095cbdfb4828df549adf -
Branch / Tag:
refs/tags/v1.0a0 - Owner: https://github.com/emcd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
releaser.yaml@28b9dd1fc4f9e9e2053b095cbdfb4828df549adf -
Trigger Event:
push
-
Statement type:
File details
Details for the file ictr-1.0a0-py3-none-any.whl.
File metadata
- Download URL: ictr-1.0a0-py3-none-any.whl
- Upload date:
- Size: 47.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2857d6b975940d97ce4a50cdafb1a3f2ef4b2c328e57cce146a2f7e397dcda01
|
|
| MD5 |
fb9f8d2b4ad91a4f9f49891571c2a919
|
|
| BLAKE2b-256 |
44c3a2d8e556f0ca0e485718c32ae1c0d6640079768afa26b3d6468526389b51
|
Provenance
The following attestation bundles were made for ictr-1.0a0-py3-none-any.whl:
Publisher:
releaser.yaml on emcd/python-ictr
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ictr-1.0a0-py3-none-any.whl -
Subject digest:
2857d6b975940d97ce4a50cdafb1a3f2ef4b2c328e57cce146a2f7e397dcda01 - Sigstore transparency entry: 760661362
- Sigstore integration time:
-
Permalink:
emcd/python-ictr@28b9dd1fc4f9e9e2053b095cbdfb4828df549adf -
Branch / Tag:
refs/tags/v1.0a0 - Owner: https://github.com/emcd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
releaser.yaml@28b9dd1fc4f9e9e2053b095cbdfb4828df549adf -
Trigger Event:
push
-
Statement type: