Skip to main content

F1 Fantasy API Client

A mildy janky implementation letting you browser the F1 fantasy data set. Certain values are guaranteed to be wrong and methods missing due to a lack of public methods. This is a best guess implementation, and I'd love any feedback.

Basic Usage

  • Navigate to https://fantasy.formula1.com
  • Open dev tools for your browser (typically F12)
  • Click Network
  • Login
  • Look for a request to /services/session/login
  • Click Response
  • Copy the value of GUID and Token.
  • See below example.
import os
import asyncio

from fantasy import Client, APIClient


async def main():
    """Shows your highest place in all your private leagues."""
    client = Client(
        APIClient(
            user_guid=os.environ["USER_GUID"],
            token=os.environ["TOKEN"],
        )
    )

    user_leagues = await client.get_user_leagues()
    for league in user_leagues.leagues:
        leaderboard = await client.get_private_league_leaderboard(league.league_id)
        ranks = [i.rank_in_league for i in league.teams_in_league]
        print(f"League: {leaderboard.league_name}\n\tBest rank: {max(ranks)}")


if __name__ == "__main__":
    asyncio.run(main())

Further Usage

The class fantasy.Client exposes all the nice data models, however many are missing.

If you want full access, use fantasy.APIClient which implements significantly more but provides the data as the API does which is hard to work with.

Metadata

Release files for skelmis-f1-fantasy 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for skelmis-f1-fantasy 0.2.0
File Size Uploaded
skelmis_f1_fantasy-0.2.0.tar.gz 11.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for skelmis-f1-fantasy 0.2.0
File Interpreter ABI Platform
skelmis_f1_fantasy-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.8 kB

Release files / skelmis_f1_fantasy-0.2.0.tar.gz

Download URL skelmis_f1_fantasy-0.2.0.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
89998d859edd129bb62c0d15194f63b552f632e004fb19a11e872e8a4bf0aa10
BLAKE2b-256 checksum
How to use checksums
c25c7e43c4fed4b32bc0729624ce52a307a082e06ec7cbbc4364a4cd927d92e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.16

Release files / skelmis_f1_fantasy-0.2.0-py3-none-any.whl

Download URL skelmis_f1_fantasy-0.2.0-py3-none-any.whl
Size 19.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f7d8bb312211254babac223910734adf077dca259ac62e8fa9fbc5c71f5bf2b9
BLAKE2b-256 checksum
How to use checksums
9b1dbac55e6d88bb285d58738c4a91f508e3c4b8b133d1e494d0a4c3c29533f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.16

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page