LiveF1 API - livef1#

Configuration#

Package-level configuration for LiveF1.

Call configure() before running LiveF1 code to adjust logging and F1 account authentication settings.

Functions

configure(*[, log_level, ...])

Configure LiveF1 package settings.

livef1.config.configure(*, log_level=None, logging_stream_format=None, logging_stream_datefmt=None, logging_file_path=<object object>, logging_file_format=None, logging_file_datefmt=None, auth_save_token=None, auth_token_path=None, auth_env_path=None)[source]#

Configure LiveF1 package settings.

Call this before running LiveF1 code when you need non-default behaviour (for example logging in read-only environments such as AWS Lambda).

Parameters:
log_levelUnion[str, int], optional

Logging level as a string ('DEBUG', 'INFO', …) or an logging module constant.

logging_stream_formatstr, optional

Format string for the console (stream) handler.

logging_stream_datefmtstr, optional

Date/time format for the console handler.

logging_file_pathstr or pathlib.Path or None, optional

Path to the log file. Parent directories are created if needed. Pass None to disable file logging. Omit to leave unchanged. File logging is disabled by default.

logging_file_formatstr, optional

Format string for the file handler.

logging_file_datefmtstr, optional

Date/time format for the file handler.

auth_save_tokenbool, optional

Default for livef1.login(): save the F1 account token to disk. Set to False to keep it in memory only.

auth_token_pathstr or pathlib.Path, optional

Default for livef1.login(): where the token is saved. If not set, LIVEF1_TOKEN_PATH from the environment or the .env file is used, else ~/.livef1/f1tv_auth_token.json.

auth_env_pathstr or pathlib.Path, optional

Default for livef1.login(): the .env file the F1 account credentials are read from and saved to. If not set, the first .env in the working directory or one of its parents is used, else .env in the working directory.

Examples

>>> import livef1
>>> # Console only (default) — safe for Lambda / read-only filesystems
>>> livef1.configure(log_level="DEBUG")
>>> # Enable file logging at a writable path
>>> livef1.configure(logging_file_path="/tmp/livef1.log")
>>> # Custom formats
>>> livef1.configure(
...     logging_stream_format="%(levelname)s | %(message)s",
...     logging_file_path="logs/livef1.log",
...     logging_file_format="%(asctime)s %(levelname)s %(message)s",
... )
>>> # Keep the F1 account token in memory only
>>> livef1.configure(auth_save_token=False)

Session Access#

Functions

get_season(season)

Retrieve data for a specified Formula 1 season.

get_meeting(season[, meeting_identifier, ...])

Retrieve data for a specific meeting in a given season.

get_session(season[, meeting_identifier, ...])

Retrieve data for a specific session within a meeting and season.

livef1.api.get_meeting(season: int, meeting_identifier: str = None, meeting_key: int = None, meeting_offname: str = None) → Meeting[source]#

Retrieve data for a specific meeting in a given season.

Parameters:
seasonint

The year of the season to retrieve the meeting from.

meeting_identifierstr

The identifier (e.g., circuit name, grand prix name) of the meeting. The identifier is going to be searched in the season’s meeting table columns: - “Meeting Official Name” - “Meeting Name” - “Circuit Short Name” Therefore, it is suggested to use keywords that is distinguishable among meetings.

Another suggestion is using circuit names for querying.

meeting_keyint

The key of the meeting to get the desired meeting whose key is matching.

Returns:
Meeting

A Meeting object containing sessions and metadata for the specified meeting.

Raises:
livef1Exception

If the meeting cannot be found based on the provided parameters.

livef1.api.get_season(season: int) → Season[source]#

Retrieve data for a specified Formula 1 season.

Parameters:
seasonint

The year of the season to retrieve.

Returns:
Season

A Season object containing all meetings and sessions for the specified year.

Raises:
livef1Exception

If no data is available for the specified season.

livef1.api.get_session(season: int, meeting_identifier: str = None, session_identifier: str = None, meeting_key: int = None, session_key: int = None) → Session[source]#

Retrieve data for a specific session within a meeting and season.

Parameters:
seasonint

The year of the season.

meeting_identifierstr

The identifier (e.g., circuit name, grand prix name) of the meeting. The identifier is going to be searched in the season’s meeting table columns: - “Meeting Official Name” - “Meeting Name” - “Circuit Short Name” Therefore, it is suggested to use keywords that is distinguishable among meetings. Another suggestion is using circuit names for querying.

meeting_keyint

The key of the meeting to get the desired meeting whose key is matching.

session_identifierstr

The identifier of the session (e.g., “Practice 1”, “Qualifying”). The identifier is going to be searched in the meeting’s sessions table.

session_keyint

The key of the session to get the desired session whose key is matching.

Returns:
Session

A Session object containing data about the specified session.

Raises:
livef1Exception

If the session cannot be found based on the provided parameters.

livef1.api.list_seasons() → list[source]#

Note

The LiveF1 package provides access to Formula 1 timing data, but it is not an official Formula 1 API client. External endpoints, available topics, and data formats may change without notice.