Skip to main content

get_puzzle_input()

Retrieve the raw puzzle input for a specific Advent of Code puzzle.

Usage

Source

get_puzzle_input(
    year,
    day,
    session=None,
)

The input is specific to your Advent of Code account. Line breaks and surrounding whitespace are retained for parsing in your solution.

Parameters

year: int

The Advent of Code event year (e.g., 2024).

day: int

The puzzle day number (1–25 for 2015–2024; 1–12 for reduced-format events).

session: str | None = None
An Advent of Code session token. If omitted, the value of the AOC_SESSION environment variable will be used instead.

Returns

str
The puzzle input as provided by Advent of Code.

Raises

MissingSessionTokenError

If no session token is supplied and AOC_SESSION is not set.

InputFetchError

If fetching or saving the input fails.

PuzzleLockedError

If the puzzle has yet to unlock in America/New_York.

ValueError
If the year or day falls outside the event format.

Notes

Inputs are cached by a fingerprint of the session token. A cache miss makes an authenticated HTTP request.

Examples

Fetch an archived puzzle using the session in your environment.

>>> from elf import get_puzzle_input
>>> lines = get_puzzle_input(2025, 1).splitlines()  # doctest: +SKIP