Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/TracingInsights/tif1/llms.txt

Use this file to discover all available pages before exploring further.

Overview

tif1 uses a singleton configuration system that supports:
  • Default configuration values
  • JSON configuration files (.tif1rc)
  • Environment variable overrides
Configuration is loaded in this priority order:
  1. Default values
  2. Configuration file (.tif1rc)
  3. Environment variables (highest priority)

Functions

get_config()

def get_config() -> Config
Returns the global configuration instance (singleton pattern). Returns:
  • Config: Global configuration manager instance
Example:
import tif1

config = tif1.get_config()
print(config.get('cache_dir'))

Config Class

Constructor

class Config:
    """Configuration manager with file support."""
The Config class is a singleton. Always use get_config() instead of instantiating directly.

Methods

get()

def get(key: str, default: Any = None) -> Any
Get configuration value with validation. Parameters:
  • key (str): Configuration key to retrieve
  • default (Any, optional): Default value if key not found
Returns:
  • Any: Configuration value (validated) or default
Example:
config = tif1.get_config()
timeout = config.get('timeout', 30)
max_retries = config.get('max_retries', 3)

set()

def set(key: str, value: Any) -> None
Set configuration value at runtime. Parameters:
  • key (str): Configuration key to set
  • value (Any): Value to set
Example:
config = tif1.get_config()
config.set('timeout', 60)
config.set('max_retries', 5)

save()

def save(path: Path | None = None) -> None
Save current configuration to a JSON file. Parameters:
  • path (Path, optional): File path to save to. Defaults to ~/.tif1rc
Example:
from pathlib import Path

config = tif1.get_config()
config.set('timeout', 60)
config.save()  # Saves to ~/.tif1rc
# Or save to custom location:
config.save(Path('~/my-project/.tif1rc'))

Configuration Options

Cache Settings

OptionTypeDefaultDescription
cache_dirstr~/.tif1/cacheDirectory for cache storage
enable_cacheboolTrueEnable/disable caching
cache_commit_intervalint25Number of writes before SQLite commit
sqlite_timeoutfloat30.0SQLite connection timeout in seconds
memory_cache_max_itemsint1024Max items in memory cache
memory_telemetry_cache_max_itemsint2048Max telemetry items in memory cache

Logging

OptionTypeDefaultDescription
log_levelstr"WARNING"Logging level (DEBUG, INFO, WARNING, ERROR)

HTTP/Network Settings

OptionTypeDefaultDescription
timeoutint30HTTP request timeout in seconds
max_retriesint3Maximum number of retry attempts
retry_backoff_factorfloat2.0Exponential backoff factor for retries
retry_jitterboolTrueAdd random jitter to retry delays
retry_jitter_maxfloat0.0Maximum jitter value in seconds
max_retry_delayfloat60.0Maximum retry delay in seconds
http2_max_connectionsint10Max HTTP/2 connections
http2_max_pool_sizeint20Max HTTP/2 connection pool size
max_concurrent_requestsint20Max concurrent HTTP requests
keepalive_timeoutint120Keep-alive timeout in seconds
keepalive_max_requestsint1000Max requests per keep-alive connection
http_multiplexedboolTrueEnable HTTP/2 multiplexing
http_disable_http3boolFalseDisable HTTP/3 support
http_resolverslist[str]["standard", "doh://cloudflare", "doh://google"]DNS resolver list

Circuit Breaker

OptionTypeDefaultDescription
circuit_breaker_thresholdint5Failures before opening circuit
circuit_breaker_timeoutint60Circuit breaker timeout in seconds

Performance Settings

OptionTypeDefaultDescription
max_workersint20Max worker threads
json_parse_workersint0Workers for JSON parsing (0=disabled)
pool_exhaustion_backoff_basefloat0.01Base backoff for pool exhaustion
pool_exhaustion_backoff_maxfloat0.5Max backoff for pool exhaustion
pool_exhaustion_backoff_jitterfloat0.01Jitter for pool exhaustion backoff

Data Library Settings

OptionTypeDefaultDescription
libstr"pandas"Data library backend: “pandas” or “polars”
polars_lap_categoricalboolFalseUse categorical types for laps in polars

CDN Settings

OptionTypeDefaultDescription
cdnslist[str]["https://cdn.jsdelivr.net/gh/TracingInsights"]CDN URLs for data
cdn_use_minificationboolFalseUse minified CDN data
user_agentstr"tif1/0.1.0"HTTP User-Agent header

Validation

OptionTypeDefaultDescription
validate_databoolFalseEnable data validation
validate_lap_timesboolFalseValidate lap time data
validate_telemetryboolFalseValidate telemetry data

Special Modes

OptionTypeDefaultDescription
offline_modeboolFalseWork offline using only cached data
ci_modeboolFalseCI/CD mode optimizations
ultra_cold_startboolTrueOptimize for cold start performance
ultra_cold_background_cache_fillboolFalseFill cache in background on cold start
ultra_cold_skip_retriesboolTrueSkip retries during ultra cold start

Prefetching

OptionTypeDefaultDescription
prefetch_driver_laps_on_get_driverboolTruePrefetch laps when getting driver
prefetch_all_telemetry_on_first_lap_requestboolFalsePrefetch all telemetry on first lap
prefetch_all_telemetry_after_laps_loadboolFalsePrefetch all telemetry after loading laps
telemetry_prefetch_max_concurrent_requestsint32Max concurrent telemetry prefetch requests

Configuration File

File Locations

Configuration is loaded from .tif1rc files in this order:
  1. Explicit path: Set via TIF1_CONFIG_FILE environment variable
  2. Current directory: ./tif1rc (requires TIF1_TRUST_CWD_CONFIG=true)
  3. Home directory: ~/.tif1rc (default)

File Format

The .tif1rc file uses JSON format:
{
  "cache_dir": "~/my-project/.cache",
  "timeout": 60,
  "max_retries": 5,
  "log_level": "INFO",
  "lib": "polars",
  "enable_cache": true
}

Environment Variables

All configuration options can be overridden with environment variables using the TIF1_ prefix:
Environment VariableConfig Key
TIF1_CACHE_DIRcache_dir
TIF1_LOG_LEVELlog_level
TIF1_TIMEOUTtimeout
TIF1_MAX_RETRIESmax_retries
TIF1_ENABLE_CACHEenable_cache
TIF1_OFFLINE_MODEoffline_mode
TIF1_CI_MODEci_mode
TIF1_LIBlib
TIF1_HTTP_MULTIPLEXEDhttp_multiplexed
See the full list in the source code (config.py:136-199). Example:
export TIF1_CACHE_DIR="~/my-cache"
export TIF1_TIMEOUT=60
export TIF1_LOG_LEVEL="DEBUG"
python my_script.py

Examples

Basic Configuration

import tif1

# Get configuration
config = tif1.get_config()

# Read values
print(f"Cache dir: {config.get('cache_dir')}")
print(f"Timeout: {config.get('timeout')}")
print(f"Backend: {config.get('lib')}")

Modify Configuration

import tif1

config = tif1.get_config()

# Change settings at runtime
config.set('timeout', 120)
config.set('max_retries', 10)
config.set('lib', 'polars')

# Save to file
config.save()  # Saves to ~/.tif1rc

Use Custom Cache Directory

import tif1

config = tif1.get_config()
config.set('cache_dir', '~/my-project/.tif1-cache')

# Or via environment variable:
# export TIF1_CACHE_DIR="~/my-project/.tif1-cache"

Switch to Polars Backend

import tif1

config = tif1.get_config()
config.set('lib', 'polars')

# Now all data operations will use polars DataFrames
session = tif1.get_session(2024, 'Monaco', 'R')
session.load()
print(type(session.laps))  # polars DataFrame

Disable Caching

import tif1

config = tif1.get_config()
config.set('enable_cache', False)

# All requests will bypass cache

Offline Mode

import tif1

config = tif1.get_config()
config.set('offline_mode', True)

# Only cached data will be used, no network requests

Source Code

For the complete implementation, see config.py:25-312 in the source code.

Build docs developers (and LLMs) love