| Crates.io | advent-of-code-data |
| lib.rs | advent-of-code-data |
| version | 0.0.2 |
| created_at | 2024-11-29 21:46:30.049916+00 |
| updated_at | 2025-12-02 03:51:57.99417+00 |
| description | Advent of Code API for submitting answers and getting inputs |
| homepage | https://github.com/smacdo/advent-of-code-rust |
| repository | https://github.com/smacdo/advent-of-code-rust |
| max_upload_size | |
| id | 1466075 |
| size | 159,608 |
A Rust library for fetching puzzle inputs and submitting answers to Advent of Code.
Install the crate:
$ cargo add advent-of-code-data
Fetch a puzzle input and submit an answer:
use advent_of_code_data::{get_input, submit_answer, Day, Part, Year};
fn main() -> anyhow::Result<()> {
let input = get_input(Day(1), Year(2025))?;
println!("{}", input);
submit_answer(42.into(), Part::One, Day(1), Year(2025))?;
Ok(())
}
Before running, you'll need to set your Advent of Code session cookie. See the Setup section below.
Your puzzle inputs are personalized. To fetch them, you need your Advent of Code session cookie.
The fastest way to get started is to set the AOC_SESSION environment variable:
export AOC_SESSION=your_session_cookie_here
Alternatively, you can create a configuration file. See the Configuration section for details.
By default, puzzle data is cached locally and encrypted. You only need to specify your session cookie.
Set your session with the AOC_SESSION environment variable:
export AOC_SESSION=your_session_cookie_here
Other environment variables are available for advanced use:
AOC_PASSPHRASE: Custom passphrase for encryption (uses hostname by default)AOC_PUZZLE_DIR: Custom directory for caching puzzlesAOC_SESSIONS_DIR: Custom directory for session dataAOC_CONFIG_PATH: Path to a specific config file (disables all other config locations)Create a aoc_settings.toml file in one of these locations:
Linux:
$XDG_CONFIG_HOME/advent_of_code_data/aoc_settings.toml$HOME/.aoc_settings.toml.aoc_settings.toml (current directory)macOS:
$HOME/Library/Application Support/com.smacdo.advent_of_code_data/aoc_settings.toml$HOME/.aoc_settings.toml.aoc_settings.toml (current directory)Windows:
%APPDATA%/com.smacdo.advent_of_code_data/config/aoc_settings.toml%USERPROFILE%/.aoc_settings.toml.aoc_settings.toml (current directory)Example configuration file:
[client]
session_id = "your_session_cookie_here"
Configuration is loaded in this order, with later sources overriding earlier ones:
.aoc_settings.toml)This lets you keep global settings in your user directory, override them with project-specific settings, and override those with environment variables.
If you want to cache puzzles directly in your project (instead of the system cache), set both puzzle_dir and a custom passphrase:
[client]
session_id = "your_session_cookie_here"
puzzle_dir = "./puzzles"
passphrase = "your_custom_passphrase"
Important: Do not commit your passphrase or session cookie to version control. Add your config file to .gitignore if it contains secrets.
If you get a BadSessionId error, your session cookie has expired or is incorrect.
Solution:
AOC_SESSION environment variable or config fileAoC puzzles unlock at midnight EST each day. If you try to fetch a puzzle before it's released, you'll get a PuzzleNotFound error.
Solution:
If you submit too many incorrect answers, AoC temporarily blocks further submissions and returns a SubmitTimeOut error.
Solution: