Skip to main content
tif1 can be configured via a .tif1rc file, environment variables, or programmatically using the Config object. Configuration is loaded in this order (later sources override earlier ones):
  1. Default values
  2. .tif1rc file in home directory (~/.tif1rc)
  3. Environment variables (prefixed with TIF1_)
  4. Programmatic config.set() calls

get_config

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

config = tif1.get_config()
print(f"Lib: {config.get('lib')}")
print(f"Cache enabled: {config.get('enable_cache')}")

Config Methods

get(key, default=None)

Get the value for a configuration key.
def get(key: str, default: Any = None) -> Any
Parameters:
  • key: Configuration key name
  • default: Default value if key doesn’t exist
Returns:
  • Configuration value or default
Example:
config = tif1.get_config()

lib = config.get("lib")  # "pandas"
timeout = config.get("timeout", 30)  # 30 if not set
custom = config.get("custom_key", "default")  # "default"

set(key, value)

Update a configuration value in memory for the current session.
def set(key: str, value: Any) -> None
Parameters:
  • key: Configuration key name
  • value: New value to set
Example:
config = tif1.get_config()

# Change lib
config.set("lib", "polars")

# Disable cache
config.set("enable_cache", False)

# Increase timeout
config.set("timeout", 60)
Changes made with set() only affect the current Python session. Use save() to persist changes to disk.

save(path=None)

Save the current configuration to a JSON file.
def save(path: Path | None = None) -> None
Parameters:
  • path: Path to save config file. If None, saves to ~/.tif1rc
Example:
config = tif1.get_config()

# Modify settings
config.set("lib", "polars")
config.set("enable_cache", True)

# Save to default location (~/.tif1rc)
config.save()

# Save to custom location
config.save(Path("./my-config.json"))

Configuration Keys

Core Settings

lib
str
default:"pandas"
Default DataFrame lib ("pandas" or "polars").
config.set("lib", "polars")
enable_cache
bool
default:"True"
Enable or disable the multi-layer caching system (memory + SQLite).
config.set("enable_cache", False)  # Disable caching
cache_dir
str
default:"~/.tif1/cache"
Path where the SQLite cache database is stored.
config.set("cache_dir", "/tmp/tif1-cache")
validate_data
bool
default:"False"
Enable Pydantic validation of incoming JSON data.
Validation adds overhead. Disabled by default for performance.
config.set("validate_data", True)  # Enable validation
ultra_cold_start
bool
default:"True"
Enable ultra-low latency mode for first-time loads. Skips loading full session data when only specific data is needed.
config.set("ultra_cold_start", False)  # Disable for full data loading

Network Settings

timeout
int
default:"30"
Network request timeout in seconds.
config.set("timeout", 60)  # 60 second timeout
max_retries
int
default:"3"
Number of times to retry a failed CDN request.
config.set("max_retries", 5)
max_workers
int
default:"20"
Maximum number of concurrent workers for parallel requests.
config.set("max_workers", 50)
max_concurrent_requests
int
default:"20"
Maximum number of concurrent HTTP requests.
config.set("max_concurrent_requests", 50)

HTTP Session Settings

http_multiplexed
bool
default:"True"
Enable HTTP/2 multiplexing for multiple requests over a single connection.
config.set("http_multiplexed", False)  # Disable multiplexing
http_disable_http3
bool
default:"False"
Disable HTTP/3 support.
config.set("http_disable_http3", True)
pool_connections
int
default:"dynamic"
Number of connection pools to maintain. If not set, automatically calculated as max(256, max_workers, max_concurrent_requests, telemetry_prefetch_max_concurrent_requests).
Most users should rely on automatic sizing. Only set explicitly for specific performance tuning.
config.set("pool_connections", 512)  # Override automatic sizing
pool_maxsize
int
default:"dynamic"
Maximum connections per pool. If not set, automatically calculated as max(512, pool_connections * 4) to handle burst traffic.
Automatically sized to 4x pool_connections with a minimum of 512. Only override for specific use cases.
config.set("pool_maxsize", 2048)  # Override automatic sizing
keepalive_timeout
int
default:"120"
Keep-alive timeout in seconds.
config.set("keepalive_timeout", 300)
keepalive_max_requests
int
default:"1000"
Maximum requests per keep-alive connection.
config.set("keepalive_max_requests", 5000)
user_agent
str
default:"tif1/0.1.0"
User-Agent header for HTTP requests.
config.set("user_agent", "my-app/1.0.0")
http_resolvers
list[str]
DNS resolvers with DoH fallback.
config.set("http_resolvers", ["doh://cloudflare"])

Telemetry Settings

telemetry_prefetch_max_concurrent_requests
int
default:"32"
Maximum concurrent requests for telemetry prefetching.
config.set("telemetry_prefetch_max_concurrent_requests", 128)

Logging Settings

connection_stats_log_interval
float
default:"60.0"
Interval in seconds for logging connection pool statistics.
config.set("connection_stats_log_interval", 120.0)

Advanced Configuration

These settings are for advanced users and performance tuning. Most users should use the defaults.
cache_commit_interval
int
default:"25"
Number of cache operations before committing to SQLite.
config.set("cache_commit_interval", 50)
memory_cache_max_items
int
default:"1024"
Maximum items in the in-memory cache layer.
config.set("memory_cache_max_items", 2048)
memory_telemetry_cache_max_items
int
default:"2048"
Maximum telemetry items in the in-memory cache.
config.set("memory_telemetry_cache_max_items", 4096)
sqlite_timeout
float
default:"30.0"
SQLite connection timeout in seconds.
config.set("sqlite_timeout", 60.0)
cdns
list[str]
List of CDN URLs to use for data fetching. Must be HTTPS URLs.
config.set("cdns", ["https://cdn.jsdelivr.net/gh/TracingInsights"])
cdn_use_minification
bool
default:"False"
Use minified CDN resources (reserved for future use).
config.set("cdn_use_minification", False)
retry_backoff_factor
float
default:"2.0"
Exponential backoff multiplier for retries. Must be >= 1.0.
config.set("retry_backoff_factor", 3.0)
retry_jitter
bool
default:"True"
Add random jitter to retry delays to prevent thundering herd.
config.set("retry_jitter", True)
retry_jitter_max
float
default:"0.0"
Maximum jitter amount in seconds. Must be > 0 to have effect.
config.set("retry_jitter_max", 1.0)
max_retry_delay
float
default:"60.0"
Maximum delay between retries in seconds.
config.set("max_retry_delay", 120.0)
circuit_breaker_threshold
int
default:"5"
Number of consecutive failures before circuit breaker opens.
config.set("circuit_breaker_threshold", 10)
circuit_breaker_timeout
int
default:"60"
Seconds to wait before attempting to close circuit breaker.
config.set("circuit_breaker_timeout", 120)
http2_max_connections
int
default:"10"
Maximum HTTP/2 connections per host.
config.set("http2_max_connections", 20)
http2_max_pool_size
int
default:"20"
HTTP/2 connection pool size.
config.set("http2_max_pool_size", 40)
pool_exhaustion_backoff_base
float
default:"0.01"
Base backoff delay when connection pool is exhausted (seconds).
config.set("pool_exhaustion_backoff_base", 0.02)
pool_exhaustion_backoff_max
float
default:"0.5"
Maximum backoff delay for pool exhaustion (seconds).
config.set("pool_exhaustion_backoff_max", 1.0)
pool_exhaustion_backoff_jitter
float
default:"0.01"
Jitter amount for pool exhaustion backoff (seconds).
config.set("pool_exhaustion_backoff_jitter", 0.02)
validate_lap_times
bool
default:"False"
Enable validation of lap time data using Pydantic schemas.
config.set("validate_lap_times", True)
validate_telemetry
bool
default:"False"
Enable validation of telemetry data using Pydantic schemas.
config.set("validate_telemetry", True)
Enabling validation adds overhead. Only enable for debugging or data quality checks.
prefetch_driver_laps_on_get_driver
bool
default:"True"
Automatically prefetch lap data when accessing a driver.
config.set("prefetch_driver_laps_on_get_driver", False)
prefetch_all_telemetry_on_first_lap_request
bool
default:"False"
Prefetch all telemetry data on first lap telemetry request.
config.set("prefetch_all_telemetry_on_first_lap_request", True)
prefetch_all_telemetry_after_laps_load
bool
default:"False"
Prefetch all telemetry data immediately after loading laps.
config.set("prefetch_all_telemetry_after_laps_load", True)
ultra_cold_background_cache_fill
bool
default:"False"
Fill cache in background during ultra cold start mode.
config.set("ultra_cold_background_cache_fill", True)
ultra_cold_skip_retries
bool
default:"True"
Skip retries in ultra cold start mode for faster initial load.
config.set("ultra_cold_skip_retries", False)
log_level
str
default:"WARNING"
Default logging level. Use setup_logging() to change at runtime.
config.set("log_level", "DEBUG")
offline_mode
bool
default:"False"
Enable offline mode (cache-only, no network requests).
config.set("offline_mode", True)
ci_mode
bool
default:"False"
Enable CI mode (optimized for continuous integration environments).
config.set("ci_mode", True)
polars_lap_categorical
bool
default:"False"
Use categorical types for string columns in polars DataFrames.
config.set("polars_lap_categorical", True)
json_parse_workers
int
default:"0"
Number of worker processes for parallel JSON parsing. 0 disables multiprocessing.
Process-pool JSON parsing can hurt performance due to IPC overhead for telemetry-heavy workloads. Keep disabled unless you have specific use cases.
config.set("json_parse_workers", 4)

Configuration file format

The .tif1rc file is a JSON file with key-value pairs:
{
  "lib": "pandas",
  "enable_cache": true,
  "cache_dir": "~/.tif1/cache",
  "timeout": 60,
  "max_retries": 5,
  "validate_data": false,
  "ultra_cold_start": true,
  "max_workers": 50,
  "pool_connections": 512,
  "pool_maxsize": 1024,
  "http_multiplexed": true,
  "http_disable_http3": false,
  "keepalive_timeout": 300,
  "keepalive_max_requests": 5000,
  "user_agent": "my-app/1.0.0",
  "http_resolvers": ["standard", "doh://cloudflare", "doh://google"]
}
Location:
  • Default: ~/.tif1rc
  • Custom: Specify path with TIF1_CONFIG_PATH environment variable

Environment Variables

All configuration keys can be set via environment variables with the TIF1_ prefix:
# Set lib
export TIF1_LIB=polars

# Disable cache
export TIF1_ENABLE_CACHE=false

# Set timeout
export TIF1_TIMEOUT=60

# Set cache directory
export TIF1_CACHE_DIR=/tmp/tif1-cache

# Set max workers
export TIF1_MAX_WORKERS=50

# Enable ultra cold start
export TIF1_ULTRA_COLD_START=true

# Configure HTTP
export TIF1_HTTP_MULTIPLEXED=true
export TIF1_POOL_CONNECTIONS=512
export TIF1_POOL_MAXSIZE=1024

# Configure DNS resolvers (comma-separated)
export TIF1_HTTP_RESOLVERS=standard,doh://cloudflare

Configuration Precedence

Configuration is loaded in this order (later overrides earlier):
  1. Default values (hardcoded in library)
  2. .tif1rc file (~/.tif1rc or TIF1_CONFIG_PATH)
  3. Environment variables (TIF1_*)
  4. Programmatic calls (config.set())
Example:
# Default: lib = "pandas"
# .tif1rc: lib = "polars"
# Environment: TIF1_LIB=pandas
# Programmatic: config.set("lib", "polars")

# Final value: "polars" (programmatic wins)

Common configuration patterns

High-Performance Setup

import tif1

config = tif1.get_config()

# Use polars lib
config.set("lib", "polars")

# Increase concurrency
config.set("max_workers", 100)
config.set("max_concurrent_requests", 100)
config.set("telemetry_prefetch_max_concurrent_requests", 128)

# Optimize connection pooling (override automatic sizing)
config.set("pool_connections", 512)
config.set("pool_maxsize", 2048)

# Longer keep-alive
config.set("keepalive_timeout", 300)
config.set("keepalive_max_requests", 10000)

Low-Latency Setup

import tif1

config = tif1.get_config()

# Enable ultra cold start
config.set("ultra_cold_start", True)

# Use DoH for faster DNS
config.set("http_resolvers", ["doh://cloudflare", "doh://google"])

# Aggressive connection pooling
config.set("pool_connections", 256)
config.set("pool_maxsize", 1024)

# Shorter timeout
config.set("timeout", 15)

Development Setup

import tif1
import logging

config = tif1.get_config()

# Disable cache for fresh data
config.set("enable_cache", False)

# Enable validation
config.set("validate_data", True)

# Verbose logging
tif1.setup_logging(logging.DEBUG)

# Lower concurrency for debugging
config.set("max_workers", 5)

Production Setup

import tif1

config = tif1.get_config()

# Enable cache
config.set("enable_cache", True)
config.set("cache_dir", "/var/cache/tif1")

# Disable validation for performance
config.set("validate_data", False)

# High concurrency
config.set("max_workers", 100)
config.set("max_concurrent_requests", 100)

# Robust retry settings
config.set("max_retries", 5)
config.set("timeout", 60)

# Save configuration
config.save()

Setting Log Level

While not part of the Config object, you can set the log level using setup_logging:
import tif1
import logging

# Set log level
tif1.setup_logging(logging.DEBUG)  # DEBUG, INFO, WARNING, ERROR
Or use the fastf1-compatible function:
import tif1

# Set log level (fastf1 compatibility)
tif1.set_log_level(logging.DEBUG)

Best Practices

  1. Use config files for persistent settings: Store common settings in ~/.tif1rc
  2. Use environment variables for deployment: Configure per-environment settings
  3. Use programmatic API for runtime changes: Adjust settings based on workload
  4. Save after making changes: Call config.save() to persist changes
  5. Test configuration changes: Verify performance impact before deploying
  6. Monitor connection stats: Track connection reuse rate to optimize pooling
  7. Let pool sizing auto-calculate: Only override pool_connections and pool_maxsize for specific tuning needs
  8. Keep validation disabled in production: Enable only for debugging or data quality checks

Summary

The configuration system provides:
  • Multiple configuration sources (file, env, API)
  • Clear precedence rules
  • Runtime configuration changes
  • Persistent configuration storage
  • Comprehensive settings for all aspects of the library
  • Performance tuning capabilities
Use configuration to optimize tif1 for your specific use case and environment.

Environment Variables

Env var reference

Installation

Setup guide

Best Practices

Configuration tips
Last modified on March 5, 2026