This repository provides a set of Python scripts to create a custom legality checker for Magic: The Gathering formats, using card data from Scryfall and integrating with Moxfield. You can validate any deck against a custom card pool and check for illegal or banned cards.


Features

  • Custom format legality checker: Define your own set of legal cards based on Scryfall queries.
  • Scryfall to Moxfield integration: Import card lists into Moxfield.
  • CSV to JSON conversion: Generate a legal card list JSON from Moxfield CSV exports.
  • Deck validation: Check if a decklist contains illegal or banned cards.

Scripts

1. scryfall_to_moxfield.py

Fetch cards from Scryfall using a custom query and export them as a CSV file for Moxfield import.

Usage:

python scryfall_to_moxfield.py

Key Parameters:

  • QUERY: Scryfall search query (e.g., "f:standard tix<=0.1 usd<=1")
  • OUTPUT_FILE: CSV file to save card data.
  • MAX_PAGES: Limit the number of pages to fetch (0 for no limit).

This script outputs a CSV with card details suitable for importing into Moxfield.


2. moxfield_csv_to_json_cards.py

Convert a Moxfield CSV export into a JSON file containing legal cards and sets.

Usage:

python moxfield_csv_to_json_cards.py

Output:

  • standard_penny.json (or your chosen filename)
  • Structure:
{
  "sets": ["SETCODE1", "SETCODE2", ...],
  "cards": ["Card Name 1", "Card Name 2", ...]
}

3. deck_validator.py

Validate a decklist (decklist.txt) against a legal card pool (legal_cards.json) and report illegal or banned cards.

Usage:

python deck_validator.py

Inputs:

  • legal_cards.json: JSON file generated from moxfield_csv_to_json_cards.py.
  • decklist.txt: Decklist to validate.

Output:

Lists any illegal or banned cards found in the deck.


Workflow

  1. Fetch a custom card pool from Scryfall:
python scryfall_to_moxfield.py
  1. Import the CSV into Moxfield (optional) for deck building.

  2. Export your Moxfield collection CSV and convert it to JSON:

python moxfield_csv_to_json_cards.py
  1. Validate a decklist using the generated JSON:
python deck_validator.py

Decklist Format

  • One card per line.
  • Optional quantity prefix (2 Card Name or 2x Card Name).
  • Comments can start with #.
  • Section headers (Deck or Sideboard) are ignored.
  • Example:
4 Lightning Bolt
2x Opt
# This is a comment
Sideboard:
3 Mystical Dispute

Dependencies

  • Python 3.8+
  • requests library (for Scryfall API requests)

Install dependencies:

pip install requests

Notes

  • Card names are case-insensitive.
  • Cards in the “banned” list in the JSON are automatically flagged as illegal.
  • You can adjust the Scryfall query to any custom format or price constraints.

This setup allows you to create a legality checker for any custom Magic: The Gathering format, validate decks, and integrate seamlessly with Moxfield.