Skip to content

core

core

Matchweek dataclass

Matchweek(
    gameweek: int,
    date: datetime,
    fixtures: list[dict],
    team_difficulty: dict[str, float],
)

Represents a matchweek with global context.

ATTRIBUTE DESCRIPTION
gameweek

Gameweek number

TYPE: int

date

Date of the gameweek

TYPE: datetime

fixtures

List of fixtures

TYPE: list[dict]

team_difficulty

Team-level difficulty ratings

TYPE: dict[str, float]

Player dataclass

Player(
    id: int,
    name: str,
    team: str,
    position: str,
    price: float,
    timeseries: DataFrame,
    news: Optional[dict] = None,
)

Represents a Fantasy Premier League player.

ATTRIBUTE DESCRIPTION
id

Unique player identifier

TYPE: int

name

Player full name

TYPE: str

team

Current team

TYPE: str

position

Position (GK, DEF, MID, FWD)

TYPE: str

price

Current price in FPL

TYPE: float

timeseries

Historical stats (points, xG, minutes, etc.)

TYPE: DataFrame

news

Latest news/injury information

TYPE: Optional[dict]

last_5_points property

last_5_points: float

Average points over last 5 gameweeks.

availability property

availability: float

Availability score (0-1) based on news.

FullSquad dataclass

FullSquad(
    squad_players: list[Player],
    lineup: Squad,
    bench: list[Player] = list(),
    squad_cost: float = 0.0,
    expected_points: float = 0.0,
)

Represents a 15-player FPL squad with a selected 11-player lineup.

The two-level FPL structure: Level 1: 15-player squad (2 GK, 5 DEF, 5 MID, 3 FWD) under budget. Level 2: 11-player starting lineup chosen from the squad each gameweek.

ATTRIBUTE DESCRIPTION
squad_players

All 15 squad members.

TYPE: list[Player]

lineup

The 11-player starting lineup (subset of squad_players).

TYPE: Squad

bench

The 4 bench players.

TYPE: list[Player]

squad_cost

Total cost of all 15 players.

TYPE: float

expected_points

Expected points for the starting 11.

TYPE: float

summary

summary() -> str

Returns a formatted string summary of the full squad.

Source code in fplx/core/squad.py
def summary(self) -> str:
    """Returns a formatted string summary of the full squad."""
    lines = [
        f"Squad Cost: £{self.squad_cost:.1f}m / £100.0m",
        f"Remaining Budget: £{100.0 - self.squad_cost:.1f}m",
        "",
        self.lineup.summary(),
        "",
        "--- Bench ---",
    ]
    for p in self.bench:
        lines.append(f"  {p.name} ({p.position}, {p.team}, £{p.price}m)")
    return "\n".join(lines)

Squad dataclass

Squad(
    players: list[Player],
    formation: str,
    total_cost: float,
    expected_points: float,
    captain: Optional[Player] = None,
)

Represents an 11-player starting lineup.

ATTRIBUTE DESCRIPTION
players

Selected starters (exactly 11).

TYPE: list[Player]

formation

Formation string (e.g., "3-4-3").

TYPE: str

total_cost

Total cost of the starting 11.

TYPE: float

expected_points

Expected total points for the starting 11.

TYPE: float

captain

Captain selection (earns double points).

TYPE: Optional[Player]

summary

summary() -> str

Returns a formatted string summary of the lineup.

Source code in fplx/core/squad.py
def summary(self) -> str:
    """Returns a formatted string summary of the lineup."""
    pos_order = {"GK": 0, "DEF": 1, "MID": 2, "FWD": 3}
    lines = [
        f"Formation: {self.formation}",
        f"Total Cost: £{self.total_cost:.1f}m",
        f"Expected Points: {self.expected_points:.2f}",
        f"Captain: {self.captain.name if self.captain else 'None'}",
        "",
        "--- Starting XI ---",
    ]
    for p in sorted(self.players, key=lambda x: pos_order.get(x.position, 9)):
        lines.append(f"  {p.name} ({p.position}, {p.team}, £{p.price}m)")
    return "\n".join(lines)