Advent-of-code-py
Advent of Code helper CLI and library for python projects.
Status & Info:
| License | Project Version |
|---|---|
Installation
Requires Python 3.11 or newer.
Add advent-of-code-py to a project with uv:
uv add advent-of-code-py
OR install only the CLI as a tool:
uv tool install advent-of-code-py
OR use pip:
pip install advent-of-code-py
This installs the aocpy command and the advent_of_code_py library.
Usage
Session configuration
advent-of-code-py needs your session cookie. You can get it from your browser's cookies while logged in to the Advent of Code website. Add it to the config with a name of your choice:
aocpy config add <session-name> <session-value>
You can add multiple sessions. The config file is created only readable by your user as it contains secrets.
Session names starting with _ are reserved.
aocpy config list # list sessions with masked value and saved user, e.g. default = ********de28 (name)
aocpy config check [<name>...] # check session is valid and save user, e.g. "default: valid (logged in as ...)"
aocpy config rename <old> <new> # rename a session and move its cache folder
aocpy config remove <name> # remove a session
Session cookies expire after some time. config check checks all sessions by default, saves the result and exits
with code 1 if any session is invalid, expired or could not be checked. config add checks the new session too (it is
saved with a warning if it is invalid or could not be checked). config list shows the saved result without making any
request and suggests running config check when the result is old.
Requests which only read from Advent of Code (download, puzzle page, status, check) are retried up to 3 times on network errors. Submitting an answer is never retried.
Instead of config you can set AOC_SESSION environment variable (useful for CI or a new machine). It is used as
session _env when config does not have any session, and can always be selected with -s _env:
AOC_SESSION=<session-value> aocpy download
CLI
# download input of latest unlocked puzzle for all sessions
aocpy download
# download specific years, days and sessions (options can be repeated)
aocpy download -y 2024 -d 1 -d 2 -s <session-name>
# print location of cache folder
aocpy cache path
# delete cached input and submission history (defaults to everything in cache folder)
# lists what will be deleted and asks for confirmation, use --yes to skip it
aocpy cache clear -y 2024 -d 1 -s <session-name>
# show stars of every day (defaults to latest year and all sessions)
aocpy status -y 2026 -s <session-name>
status, config list and config check accept --json to print output as JSON, e.g. for scripts:
aocpy status -y 2026 --json # [{"session": ..., "year": 2026, "stars": 4, "max_stars": 24, "days": {"1": 2, "3": null, ...}}]
aocpy config list --json # value is always masked
status output looks like:
default 2026: 3/24 stars
day 1 ★★
day 2 ★☆
day 3 locked
From 2025 onward Advent of Code has 12 puzzles per year instead of 25.
cache clear deletes cached input and submission history. Submission history is used to avoid submitting an
already known wrong answer again, so it asks for confirmation.
Library
Use the solve or submit decorator on a function which takes puzzle input as a string and returns the answer.
import advent_of_code_py
@advent_of_code_py.submit(2018, 3, 1, sessions=["<session-name>"])
def puzzle_2018_3_1(data):
# do some calculation with data and return final output
return final_output
@advent_of_code_py.solve(2018, 3, 2)
def puzzle_2018_3_2(data):
return final_output
Call the decorated function to run it:
puzzle_2018_3_1()
When called without arguments the input of each session is downloaded (and cached) and the function runs once per
session. If sessions is not provided all sessions present in the config are used.
solveprints the answer.submitsubmits the answer to the Advent of Code server and prints whether it was correct. Already submitted answers are not submitted again and a submission within one minute of the previous one is blocked.
You can also pass input directly, e.g. for the puzzle's example input:
puzzle_2018_3_2("example input")
Custom input runs once and its answer is only printed, labelled as _input. It is never submitted, even for a
function decorated with submit.
The call returns a dictionary of session name to PuzzleResult. If the function returns None nothing is printed
or submitted for that session.
results = puzzle_2018_3_1()
result = results["<session-name>"]
result.answer # answer as string, also str(result)
result.duration # seconds taken by the function, excluding input download and submit
result.correct # True / False for submitted answer, None when not submitted
result.message # result message of submission, None when not submitted
result.session, result.year, result.day, result.part
Results are printed by default. Use set_reporter to handle them yourself (or None to print nothing), and
run_options to run without submitting or only for some sessions:
previous = advent_of_code_py.set_reporter(lambda result: my_log.append(result))
with advent_of_code_py.run_options(submit=False, sessions=["<session-name>"]):
puzzle_2018_3_1() # submit function runs like solve, only for <session-name>
advent_of_code_py.set_reporter(previous)
Submission history (every submitted answer with its result and time, and the correct answer of each part) is cached per session and day. A part known to be solved is never submitted again.
Creating a CLI for solutions
Use the Initializer and advent_runner to create a CLI for your solutions, so you can run them without
modifying python files every time.
Initializer.from_package imports a package with all of its sub packages and registers every function decorated with
solve or submit as <year>-<day>-<part>:
@advent_of_code_py.advent_runner
def main_cli():
return advent_of_code_py.Initializer.from_package("my_package")
For example with a package like
my_package/
cli.py
year_2026/
day01.py # part_1 decorated with solve(2026, 1, 1), part_2 with solve(2026, 1, 2)
new solution files are picked up automatically. Two functions for same year, day and part raise an error.
Functions are grouped automatically by year (2026) and day (2026-1). Custom groups (@name) can be added with
groups argument of decorator or add_group, which can contain aliases, years, days and other groups:
@advent_of_code_py.solve(2026, 1, 1, groups=["fast"])
def part_1(data): ...
initializer.add_group("slow", "2025-10-2", "2026-7")
Functions can also be registered manually with an alias. Both ways can be combined:
@advent_of_code_py.advent_runner
def main_cli():
initializer = advent_of_code_py.Initializer()
initializer.add_package("my_package")
initializer.add(p_3_1=puzzle_2018_3_1)
return initializer
Set main_cli as a script entry point in your pyproject.toml:
[project.scripts]
aoc = "my_package.cli:main_cli"
Then:
aoc list # list all functions, alias and solved status (✓) from cache
aoc list 2026 # list functions of 2026
aoc groups # list custom groups and automatic year and day groups
aoc run 2026-1-1 # run 2026 day 1 part 1
aoc run 2026-1 # run every part of 2026 day 1
aoc run 2026 # run every function of 2026
aoc run @fast 2026-1-1 # run custom group and alias, each function runs once
aoc run 2026-1 --no-submit # run submit functions without submitting
aoc run 2026-1 -s <session-name> # run only for a session (repeatable)
aoc run 2026-1-1 --input example.txt # run with custom input, answer is never submitted
aoc run 2026-1-1 --time # also print time taken, e.g. "default:2026-1-1 took 12.4 ms"
aoc all # run all functions
aoc all -t # run all functions and print time taken by each
aoc run 2026-1-1 --json # print results as JSON
aoc list --json # list functions as JSON
With --json stdout only contains JSON, e.g.
[{"alias": "2026-1-1", "session": "default", "year": 2026, "day": 1, "part": 1, "answer": "76923790", ...}].
Answer lines and anything printed by solutions go to stderr.
aoc run and aoc all exit with code 1 when any submitted answer is not correct (after running every function),
so they can be used in scripts and CI.
Development
uv sync
uv run ruff check .
uv run ruff format --check .
uv run pytest
uv run nox # run checks against all supported Python versions
Metadata
Release files for advent-of-code-py 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| advent_of_code_py-0.7.0.tar.gz | 38.3 kB | Without provenance | Details for advent_of_code_py-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| advent_of_code_py-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for advent_of_code_py-0.7.0-py3-none-any.whl |
Total release size: 70.2 kB
Release files / advent_of_code_py-0.7.0.tar.gz
| Download URL | advent_of_code_py-0.7.0.tar.gz |
|---|---|
| Size | 38.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fb414b010f5d4a153b874d13b47db3cb81226f268f12d78c164c7e0cd077e4d1
|
|
BLAKE2b-256 checksum How to use checksums |
b6f7e42afac32d7ff1b9f4707233def4f6956fe893cd21cf93281cdd12255568
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.12 {"installer":{"name":"uv","version":"0.13.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / advent_of_code_py-0.7.0-py3-none-any.whl
| Download URL | advent_of_code_py-0.7.0-py3-none-any.whl |
|---|---|
| Size | 31.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
290b5dba1d45ae29b9cd8a98f2d9dfd6652b8f0aebd712c7a4bd450f9d6dbf01
|
|
BLAKE2b-256 checksum How to use checksums |
d448ca6b5460bb41528ac5da4a9f741abc7e3b97c3150b98927f064c0998d8c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.12 {"installer":{"name":"uv","version":"0.13.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for advent-of-code-py 0.7.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.