Skip to content

Configuration

nflreadpy.config.NflreadpyConfig

Bases: BaseSettings

Configuration settings for nflreadpy.

This class manages all configuration options for the nflreadpy package. Settings can be configured via environment variables or programmatically.

Environment Variables
  • NFLREADPY_CACHE: Cache mode ("memory", "filesystem", or "off")
  • NFLREADPY_CACHE_DIR: Directory path for filesystem cache
  • NFLREADPY_CACHE_DURATION: Cache duration in seconds
  • NFLREADPY_PREFER: Preferred data format ("parquet" or "csv")
  • NFLREADPY_VERBOSE: Enable verbose output (true/false)
  • NFLREADPY_TIMEOUT: HTTP request timeout in seconds
  • NFLREADPY_USER_AGENT: Custom user agent string
Example
from nflreadpy.config import update_config, get_config

# Update settings programmatically
update_config(cache_mode="filesystem", verbose=False)

# Get current settings
config = get_config()
print(f"Cache mode: {config.cache_mode}")

nflreadpy.config.update_config

update_config(**kwargs: Any) -> None

Update configuration settings programmatically.

Parameters:

Name Type Description Default
**kwargs Any

Configuration options to update. Valid options include: - cache_mode: "memory", "filesystem", or "off" - cache_dir: Path to cache directory (str or Path) - cache_duration: Cache duration in seconds (int) - prefer_format: "parquet" or "csv" - verbose: Enable verbose output (bool) - timeout: HTTP timeout in seconds (int) - user_agent: Custom user agent string (str)

{}

Raises:

Type Description
ValueError

If an unknown configuration option is provided.

Example
# Enable filesystem caching with custom directory
update_config(
    cache_mode="filesystem",
    cache_dir="/path/to/my/cache",
    verbose=True
)

# Prefer CSV format and increase timeout
update_config(
    prefer_format="csv",
    timeout=60
)
Source code in src/nflreadpy/config.py
def update_config(**kwargs: Any) -> None:
    """Update configuration settings programmatically.

    Args:
        **kwargs: Configuration options to update. Valid options include:
            - cache_mode: "memory", "filesystem", or "off"
            - cache_dir: Path to cache directory (str or Path)
            - cache_duration: Cache duration in seconds (int)
            - prefer_format: "parquet" or "csv"
            - verbose: Enable verbose output (bool)
            - timeout: HTTP timeout in seconds (int)
            - user_agent: Custom user agent string (str)

    Raises:
        ValueError: If an unknown configuration option is provided.

    Example:
        ```python
        # Enable filesystem caching with custom directory
        update_config(
            cache_mode="filesystem",
            cache_dir="/path/to/my/cache",
            verbose=True
        )

        # Prefer CSV format and increase timeout
        update_config(
            prefer_format="csv",
            timeout=60
        )
        ```
    """
    global config
    for key, value in kwargs.items():
        if hasattr(config, key):
            setattr(config, key, value)
        else:
            raise ValueError(f"Unknown configuration option: {key}")

nflreadpy.config.get_config

get_config() -> NflreadpyConfig

Get the current configuration instance.

Returns:

Type Description
NflreadpyConfig

The global configuration object containing all current settings.

Example
config = get_config()
print(f"Cache directory: {config.cache_dir}")
print(f"Verbose mode: {config.verbose}")
Source code in src/nflreadpy/config.py
def get_config() -> NflreadpyConfig:
    """Get the current configuration instance.

    Returns:
        The global configuration object containing all current settings.

    Example:
        ```python
        config = get_config()
        print(f"Cache directory: {config.cache_dir}")
        print(f"Verbose mode: {config.verbose}")
        ```
    """
    return config

nflreadpy.config.reset_config

reset_config() -> None

Reset all configuration settings to their default values.

This will restore all settings to their initial state, clearing any programmatic or environment variable overrides.

Example
# Make some changes
update_config(cache_mode="off", verbose=False)

# Reset everything back to defaults
reset_config()

# Now cache_mode is "memory" and verbose is True again
Source code in src/nflreadpy/config.py
def reset_config() -> None:
    """Reset all configuration settings to their default values.

    This will restore all settings to their initial state, clearing any
    programmatic or environment variable overrides.

    Example:
        ```python
        # Make some changes
        update_config(cache_mode="off", verbose=False)

        # Reset everything back to defaults
        reset_config()

        # Now cache_mode is "memory" and verbose is True again
        ```
    """
    global config
    config = NflreadpyConfig()