Metadata-Version: 2.4
Name: advent-of-code-py
Version: 0.5.0
Summary: Advent of Code helper CLI and library
Author-email: Saurav Sharma <appdroiddeveloper@gmail.com>
License-Expression: MIT
Project-URL: homepage, https://github.com/iamsauravsharma/advent-of-code-py
Project-URL: source, https://github.com/iamsauravsharma/advent-of-code-py
Keywords: advent-of-code,aoc,aocpy,advent of code
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Games/Entertainment :: Puzzle Games
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click<9,>=8.5.1
Requires-Dist: platformdirs<5,>=4.14.9
Requires-Dist: requests<3,>=2.34.2
Dynamic: license-file

# Advent-of-code-py

[Advent of Code][advent_of_code_link] helper CLI and library for python projects.

**Status & Info:**

|                    License                     |            Project Version             |
| :--------------------------------------------: | :------------------------------------: |
| [![License: MIT][license_badge]][license_link] | [![PyPI][project_badge]][project_link] |

## Installation

Requires Python 3.11 or newer.

Add advent-of-code-py to a project with [uv][uv_link]:

```bash
uv add advent-of-code-py
```

**OR** install only the CLI as a tool:

```bash
uv tool install advent-of-code-py
```

**OR** use pip:

```bash
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:

```bash
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.

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

### CLI

```bash
# 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.

```python
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:

```python
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:

```python
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.

```python
@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`:

```toml
[project.scripts]
aoc = "my_package.cli:main_cli"
```

Then:

```bash
aoc list        # list all functions and their alias
aoc run p_3_1   # run a function by alias
aoc all         # run all functions
```

## Development

```bash
uv sync
uv run ruff check .
uv run ruff format --check .
uv run pytest
uv run nox   # run checks against all supported Python versions
```

[advent_of_code_link]: https://adventofcode.com
[uv_link]: https://docs.astral.sh/uv/
[license_badge]: https://img.shields.io/github/license/iamsauravsharma/advent-of-code-py.svg?style=for-the-badge
[license_link]: LICENSE
[project_badge]: https://img.shields.io/pypi/v/advent-of-code-py?style=for-the-badge&color=blue&logo=python
[project_link]: https://pypi.org/project/advent-of-code-py
