Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

mtg-parser

PyPI PyPI - Python Version Github - Nightly Check GitHub

mtg_parser is a Python library to download and parse Magic: The Gathering decklists. It supports the MTGO/MTGA formats as well as the most popular deck building websites.

Table of contents

Installation

The following section covers the installation of mtg_parser.

Before using mtg_parser, you will need:

  • python >= 3.8.1

To install mtg_parser, simply run one of the following commands in the terminal of your choice:

$ pip install mtg-parser

or

$ poetry add mtg-parser

Supported Formats

[!NOTE] mtg_parser has been developed with a primary focus on Commander. While it may function with other formats, compatibility is not guaranteed.

In addition to MTGO and MTGA formats, mtg_parser supports the following websites:

Known issues

Parsing decklists on some websites require a bit more work:

  • Moxfield.com requires a custom User-Agent (see here)

Usage

QuickStart

Start by importing the mtg_parser module:

import mtg_parser

Now let's parse a decklist (in any of the supported formats) and display the cards:

cards = mtg_parser.parse_deck(url)
for card in cards:
    print(card)

parse_deck() methods return a generator of Card objects matching the following description

class Card:
    name: str
    quantity: int = 1
    extension: Optional[str] = None
    number: Optional[str] = None
    tags: List[str] = []

Advanced - Parsing

mtg_parser.parse_deck() is a shortcut method to the specialized versions. If url is a valid Moxfield url, the following lines are equivalent:

cards = mtg_parser.parse_deck(url)
# is the same as:
cards = mtg_parser.moxfield.parse_deck(url)

In general, it's advised to use mtg_parser.parse_deck() as the overhead is insignificant.

Advanced - Configuration

[!NOTE] As of mtg_parser="=>0.0.1a40" switched to httpx instead of requests.

If for any reason, you need to configure how mtg_parser fetches remote decklists, you can provide an optional httpx.Client object.

import httpx

headers = {'user-agent': 'my-custom-user-agent/0.0.1'}
with httpx.Client(headers=headers) as client:
    cards = mtg_parser.parse_deck(url, http_client=client)
    for card in cards:
        print(card)

If no httpx.Client object is provided, one will be created for you.

Parsing MTGO / MTGA

mtg_parser can parse textual decklists in either MTGO or MTGA format

import mtg_parser

decklist = """
    1 Atraxa, Praetors' Voice
    1 Imperial Seal
    1 Lim-Dûl's Vault
    1 Jeweled Lotus (CMR) 319
    1 Llanowar Elves (M12) 182
    3 Brainstorm #Card Advantage #Draw
"""

cards = mtg_parser.parse_deck(deck_list)
# or the less recommended form:
# cards = mtg_parser.decklist.parse_deck(deck_list)
for card in cards:
    print(card)

Parsing from aetherhub.com

mtg_parser can parse public decks from aetherhub.com

import mtg_parser

url = 'https://aetherhub.com/Deck/<deck_name>'

cards = mtg_parser.parse_deck(url)
# or the less recommended form:
# cards = mtg_parser.aetherhub.parse_deck(url)
for card in cards:
    print(card)

Parsing from archidekt.com

mtg_parser can parse public decks from archidekt.com

import mtg_parser

url = 'https://www.archidekt.com/decks/<deck_id>/'

cards = mtg_parser.parse_deck(url)
# or the less recommended form:
# cards = mtg_parser.archidekt.parse_deck(url)
for card in cards:
    print(card)

Parsing from deckstats.net

mtg_parser can parse public decks from deckstats.net

import mtg_parser

url = 'https://deckstats.net/decks/<user_id>/<deck_id>'

cards = mtg_parser.parse_deck(url)
# or the less recommended form:
# cards = mtg_parser.deckstats.parse_deck(url)
for card in cards:
    print(card)

Parsing from moxfield.com

mtg_parser can parse public decks from moxfield.com

[!IMPORTANT] Moxfield.com prohibits scraping their website, as it violates their Terms of Service.

For authorized access, please contact support@moxfield.com to request a custom User-Agent.

import httpx
import mtg_parser

url = 'https://www.moxfield.com/decks/<deck_id>'

headers = {'user-agent': '<MOXFIELD_USER_AGENT>'}
with httpx.Client(headers=headers) as client:
    cards = mtg_parser.parse_deck(url, http_client=client)
    # or the less recommended form:
    # cards = mtg_parser.moxfield.parse_deck(url, http_client=client)
for card in cards:
    print(card)

Parsing from mtggoldfish.com

mtg_parser can parse public decks from mtggoldfish.com

import mtg_parser

url = 'https://www.mtggoldfish.com/deck/<deck_id>'

cards = mtg_parser.parse_deck(url)
# or the less recommended form:
# cards = mtg_parser.mtggoldfish.parse_deck(url)
for card in cards:
    print(card)

Parsing from mtgjson.com

mtg_parser can parse decks from mtgjson.com

import mtg_parser

url = 'https://mtgjson.com/api/v5/decks/<deck_name>.json'

cards = mtg_parser.parse_deck(url)
# or the less recommended form:
# cards = mtg_parser.mtgjson.parse_deck(url)
for card in cards:
    print(card)

Parsing from scryfall.com

mtg_parser can parse public decks from scryfall.com

import mtg_parser

url = 'https://scryfall.com/<userid>/decks/<deck_id>/'

cards = mtg_parser.parse_deck(url)
# or the less recommended form:
# cards = mtg_parser.scryfall.parse_deck(url)
for card in cards:
    print(card)

Parsing from tappedout.net

mtg_parser can parse public decks from tappedout.net

import mtg_parser

url = 'https://tappedout.net/mtg-decks/<deck_id>/'

cards = mtg_parser.parse_deck(url)
# or the less recommended form:
# cards = mtg_parser.tappedout.parse_deck(url)
for card in cards:
    print(card)

Parsing from infinite.tcgplayer.com

mtg_parser can parse public decks from infinite.tcgplayer.com

import mtg_parser

url = 'https://infinite.tcgplayer.com/magic-the-gathering/deck/<deck_name>/<deck_id>'

cards = mtg_parser.parse_deck(url)
# or the less recommended form:
# cards = mtg_parser.tcgplayer_infinite.parse_deck(url)
for card in cards:
    print(card)

Parsing from decks.tcgplayer.com

mtg_parser can parse public decks from decks.tcgplayer.com

import mtg_parser

url = 'https://decks.tcgplayer.com/magic/commander/<user_name>/<deck_name>/<deck_id>'

cards = mtg_parser.parse_deck(url)
# or the less recommended form:
# cards = mtg_parser.tcgplayer.parse_deck(url)
for card in cards:
    print(card)

Metadata

Release files for mtg_parser 0.0.1a41

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mtg_parser 0.0.1a41
File Size Uploaded Provenance Actions
mtg_parser-0.0.1a41.tar.gz 11.7 kB Without provenance Details for mtg_parser-0.0.1a41.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mtg_parser 0.0.1a41
File Interpreter ABI Platform Actions
mtg_parser-0.0.1a41-py3-none-any.whl Python 3 none any Details for mtg_parser-0.0.1a41-py3-none-any.whl

Total release size: 27.4 kB

Release files / mtg_parser-0.0.1a41.tar.gz

Download URL mtg_parser-0.0.1a41.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b0ed2e3b3e0f312785b83c556c4dd1bfea89fd1f976512a75c617dca2f38ed1b
BLAKE2b-256 checksum
How to use checksums
83acc416144cd9108caaee408a55936855defbfb7510442eaf8857957a6d9cf4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Darwin/23.5.0

Release files / mtg_parser-0.0.1a41-py3-none-any.whl

Download URL mtg_parser-0.0.1a41-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42ec61c9c1993ec0cf41466ddd740ffe0942c7f4b07d7c9ab5b9dbec9ee975a1
BLAKE2b-256 checksum
How to use checksums
330ebc8fb652e0a1ba3e02706382d7baa5d44024e2fdeb91db98e53bbf1c7f8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.3 Darwin/23.5.0

Security for mtg_parser 0.0.1a41

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.

Release history Release notifications | RSS feed

This release
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