Skip to main content

A Python CLI and library for interacting with the Advent of Code API to fetch puzzles, download inputs, and submit answers.

Project description

Python Advent of Code 🎄

A Python CLI and library for interacting with the Advent of Code API.

Key Features

  • 🌐 Opens the daily puzzle page in your browser
  • 🚀 Downloads your personalised puzzle inputs
  • 📂 Generates new solution files from a template
  • ✅ Tests and directly submits your solutions

Installation

To use the project, you can simply install it using pip:

pip install python-aoc

It can then be used in the command line and imported as a library with pyaoc.

Configuration

To interact with the Advent of Code API, you must provide your session token. This tool reads the token from an environment variable named AOC_SESSION, which can be set manually or through the following command:

pyaoc session set <your-session-token>

Quick Start

The most common workflow is to create, test, and submit a solution.

  1. Create the files for a new day:

    The following command will create a day-5/ directory, download the input into day-5/input.txt, create a day-5/test.txt file to hold a test input, and create a day-5/main.py script file from the default python-aoc template:

    pyaoc create 5 2025
    
  2. Test your solution against a known answer:

    Once you have completed your solution to the puzzle, written in a solve function which takes in the path to an input file, you can test it against a known answer for an example case in test.txt:

    # Assuming the example answer is 123
    pyaoc test day-5/main.py 123 --test-input-path day-5/test.txt
    
  3. Submit your final solution:

    Then, the final solution for the specified part can be submitted using the submit command:

    pyaoc submit day-5/main.py 1 --day 5 --year 2025 --input-path day-5/input.txt
    

For the complete list of CLI commands and their arguments, run pyaoc --help.

Library usage

You can also import and use the core functions in your own Python scripts:

import pyaoc

# Sets the session token (if it's not already set as an environment variable)
pyaoc.set_session("your-session-token")

try:
    # Get puzzle input for Dec 1, 2023
    puzzle_input = pyaoc.get_day_input(day=1, year=2023)
    print(puzzle_input[:50]) # Print the first 50 characters
except Exception as e:
    print(f"An error occurred: {e}")

License

This project is licensed under the MIT License. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_aoc-0.1.1.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_aoc-0.1.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file python_aoc-0.1.1.tar.gz.

File metadata

  • Download URL: python_aoc-0.1.1.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for python_aoc-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7a97b123f1401276b771fc3f51100b5bc38b4c397451d660b136ea04445ece1d
MD5 d27a778372d24af5386c908298bd97e8
BLAKE2b-256 cea6ffde4ca1cabc20b9e795443d3fc6c582cf08cc26b48ea88d7f5bd0d3789a

See more details on using hashes here.

File details

Details for the file python_aoc-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: python_aoc-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.19

File hashes

Hashes for python_aoc-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c9b41912e5329a30408d3bfc7d069acab3c2b0effa4028672b525673a43a7685
MD5 628266b931b957ed6a2a406e8d4e5529
BLAKE2b-256 6cac24aae0046bf4e7c2ac8ecae2cfabf83ac2fc86ab5e72a3882115525bb5c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page