Skip to main content

Advent-of-code-py

Advent of Code helper CLI and library for python projects.

Status & Info:

License Project Version
License: MIT PyPI

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

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:

advent-of-code-py 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.

advent-of-code-py config list            # list all sessions
advent-of-code-py config remove <name>   # remove a session

CLI

# download input of latest unlocked puzzle for all sessions
advent-of-code-py download

# download specific years, days and sessions (options can be repeated)
advent-of-code-py download -y 2024 -d 1 -d 2 -s <session-name>

# delete cached inputs (defaults to every year, day and session)
advent-of-code-py remove -y 2024 -d 1

From 2025 onward Advent of Code has 12 puzzles per year instead of 25.

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, session_list=["<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 session_list is not provided all sessions present in the config are used.

  • solve prints the answer.
  • submit submits 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")

The call returns a dictionary of session name to answer. If the function returns None nothing is printed or submitted for that session.

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.

@advent_of_code_py.advent_runner
def main_cli():
    initializer = advent_of_code_py.Initializer()
    initializer.add(p_3_1=puzzle_2018_3_1, p_3_2=puzzle_2018_3_2)
    # add other functions ...
    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 and their alias
aoc run p_3_1   # run a function by alias
aoc all         # run all functions

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.6.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 advent-of-code-py 0.6.0
File Size Uploaded Provenance Actions
advent_of_code_py-0.6.0.tar.gz 15.6 kB Without provenance Details for advent_of_code_py-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for advent-of-code-py 0.6.0
File Interpreter ABI Platform Actions
advent_of_code_py-0.6.0-py3-none-any.whl Python 3 none any Details for advent_of_code_py-0.6.0-py3-none-any.whl

Total release size: 30.3 kB

Release files / advent_of_code_py-0.6.0.tar.gz

Download URL advent_of_code_py-0.6.0.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2349d0c5d4616a666175b64135ed2e4e80f1be31cabdcf8a146d2bcc999a2578
BLAKE2b-256 checksum
How to use checksums
5838779a2a7e2e12172d3ad9977815970b504972c83d3c88ada762d4cdf40199
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","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.6.0-py3-none-any.whl

Download URL advent_of_code_py-0.6.0-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c7eddcbd9bc976ea50beaf068b2733d3764b1903649bc614da1a99ac68fb7fd
BLAKE2b-256 checksum
How to use checksums
adad0b420bf430ca0af99f5cad5d6c06e71656dd7aa95144e185e3ac28d7d1c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","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.6.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.

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