Beyond the core timing and telemetry API, tif1 provides several utility functions to manage its internal state, performance, and reliability layers.
Logging
setup_logging
Configure the logging level for tif1.
Parameters:
level: Standard logging level from the logging module
Available Levels:
logging.DEBUG: Detailed diagnostic information
logging.INFO: General informational messages
logging.WARNING: Warning messages (default)
logging.ERROR: Error messages only
logging.CRITICAL: Critical errors only
Example:
Debug Output Example:
Configuration
get_config
Returns the global configuration singleton instance.
The Config object allows you to programmatically get and set settings that are normally loaded from .tif1rc or environment variables.
Returns:
Config singleton instance
Example:
Config Methods
get(key, default=None)
Retrieve a configuration value.
set(key, value)
Update a configuration value in memory.
save(path=None)
Save current configuration to a JSON file.
Available configuration keys
Cache Management
get_cache
Returns the persistent SQLite cache singleton instance.
Returns:
Example:
Cache Methods
clear()
Remove all entries from both memory and SQLite cache.
has_session_data(year, gp, session)
Check if cache contains data for a specific session.
close()
Close the SQLite database connection.
get(key)
Get raw cached data by key.
set(key, data)
Store data in cache.
get_telemetry(year, gp, session, driver, lap)
Get cached telemetry data.
set_telemetry(year, gp, session, driver, lap, data)
Store telemetry data in cache.
Data Utilities
to_timedelta
Convert various formats to pandas timedelta.
Parameters:
x: String, float, int, or timedelta to convert
Example:
to_datetime
Convert string to pandas datetime.
Example:
recursive_dict_get
Safely navigate nested dictionaries.
Parameters:
d: Dictionary to navigate
*keys: Keys to traverse
default_none: Return None instead of on missing keys
Example:
delta_time
Calculate delta time between two laps (compatibility function).
Parameters:
reference_lap: Reference Lap object
compare_lap: Lap object to compare
Returns:
- Tuple of (delta_series, ref_telemetry, comp_telemetry)
Reliability & Networking
get_circuit_breaker
Returns the global circuit breaker instance used for network requests.
The circuit breaker prevents cascading failures by temporarily stopping requests after repeated failures.
States:
closed: Normal operation, requests allowed
open: Too many failures, requests blocked
half_open: Testing if service recovered
Example:
reset_circuit_breaker
Reset the circuit breaker to closed state.
Example:
get_cdn_manager
Returns the CDN manager responsible for fallback and source health.
Example:
Lap Cache Management
clear_lap_cache
Clear the in-memory LRU cache for lap DataFrames.
Example:
Complete Examples
Debug session loading
Cache management workflow
Handle network issues
Custom configuration file
Best Practices
-
Enable debug logging during development: Helps understand data flow and identify issues.
-
Use polars lib for large datasets: Better memory efficiency and performance.
-
Clear cache periodically: Prevents disk space issues.
-
Increase timeout for slow connections: Default 30s may not be enough on slow networks.
-
Disable validation in production: Saves ~10-15% processing time if data quality is trusted.
-
Use ultra-cold start for single lap queries: Significantly faster when you only need one lap’s telemetry.
-
Save configuration after tuning: Persist your optimized settings.
-
Monitor circuit breaker state: Helps diagnose network issues.
-
Close cache on exit: Ensures data is flushed to disk.
Last modified on March 5, 2026