Recipes

The recipes package provides convenience modules for various tasks like integration with Python standard library logging or use of the rich package for formatting or printing.

Logging Integration

(Example courtesy of xAI grok-3.)

# ruff: noqa: F821

import logging

import ictruck.recipes.logging as ictruckl


def main( ) -> None:
    logging.basicConfig(
        level = logging.INFO, format = '%(levelname)s: %(message)s' )
    ictruckl.install( )
    monitor_files( [ 'data1.txt', 'data2.txt' ] )


def monitor_files( files: list[ str ] ) -> None:
    import os
    ictr( 'info' )( 'Scanning', files )
    for file in files:
        ictr( 'debug' )( 'Checking', file )
        if not os.path.exists( file ):
            ictr( 'warning' )( 'Missing', file )


if __name__ == '__main__': main( )

Running this will result in the following:

INFO: ic| 'Scanning', files: ['data1.txt', 'data2.txt']
WARNING: ic| 'Missing', file: 'data1.txt'
WARNING: ic| 'Missing', file: 'data2.txt'

rich Integration

(Example courtesy of xAI grok-3.)

# ruff: noqa: F821

from typing_extensions import Any

import ictruck.recipes.rich as ictruckr


def main( ):
    ictruckr.install( trace_levels = 3, stderr = True )
    response: dict[ str, Any ] = {
        'status': 'success',
        'data': [
            { 'id': 1, 'name': 'Item 1', 'price': 9.99 },
            { 'id': 2, 'name': 'Item 2', 'price': 14.50 },
            { 'id': 3, 'name': 'Item 3', 'price': 20.25 },
        ],
        'metadata': { 'timestamp': '2025-03-20T10:00:00Z', 'version': '1.0' },
    }
    ictr( 3 )( response )


if '__main__' == __name__: main( )

Running this will result in the following (or something similar, depending on your terminal colors and width):

Rich Recipe Terminal Screen Capture