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.9

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

$ pip install mtg-parser
# or
$ uv add mtg-parser
# or
$ poetry add mtg-parser

Supported Formats

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

Known issues

Parsing decklists on some websites require specific configuration:

Usage

QuickStart

To parse a decklist with mtg_parser, you need to provide an HTTP client that implements a requests compatible interface (such as requests or httpx).

import requests
import mtg_parser

cards = mtg_parser.parse_deck(url, requests.Session())

For conveniency, mtg_parser provides an optional HttpClientFacade to facilitate handling of different websites with different http clients.

import cloudscraper
import httpx
import mtg_parser

client_facade = mtg_parser.HttpClientFacade(httpx.Client(timeout=10.0))
client_facade.set_override('aetherhub.com', cloudscraper.create_scraper())
client_facade.set_override('moxfield.com', httpx.Client(
    timeout=10.0,
    headers={'User-Agent': os.getenv('MOXFIELD_USER_AGENT')},
))

cards = mtg_parser.parse_deck(url, client_facade)

Return format

parse_deck() returns an Iterable[Card] matching the following description

class Card:
    name: str
    quantity: int
    extension: Optional[str]
    number: Optional[str]
    tags: Iterable[str] = []

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

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)

Parsing from aetherhub.com

mtg_parser can parse public decks from aetherhub.com

import cloudscraper
import mtg_parser

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

cards = mtg_parser.parse_deck(url, cloudscraper.create_scraper())

Parsing from archidekt.com

mtg_parser can parse public decks from archidekt.com

import requests
import mtg_parser

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

cards = mtg_parser.parse_deck(url, requests.Session())

Parsing from deckstats.net

mtg_parser can parse public decks from deckstats.net

import requests
import mtg_parser

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

cards = mtg_parser.parse_deck(url, requests.Session())

Parsing from moxfield.com

mtg_parser can parse public decks from moxfield.com

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 http_client:
    cards = mtg_parser.parse_deck(url, http_client)

Parsing from mtggoldfish.com

mtg_parser can parse public decks from mtggoldfish.com

import requests
import mtg_parser

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

cards = mtg_parser.parse_deck(url, requests.Session())

Parsing from mtgjson.com

mtg_parser can parse decks from mtgjson.com

import requests
import mtg_parser

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

cards = mtg_parser.parse_deck(url, requests.Session())

Parsing from scryfall.com

mtg_parser can parse public decks from scryfall.com

import requests
import mtg_parser

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

cards = mtg_parser.parse_deck(url, requests.Session())

Parsing from tappedout.net

mtg_parser can parse public decks from tappedout.net

import requests
import mtg_parser

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

cards = mtg_parser.parse_deck(url, requests.Session())

Parsing from tcgplayer.com

mtg_parser can parse public decks from either tcgplayer.com or infinite.tcgplayer.com

import requests
import mtg_parser

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

cards = mtg_parser.parse_deck(url, requests.Session())

Metadata

Release files for mtg_parser 0.0.1a50

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.1a50
File Size Uploaded Provenance Actions
mtg_parser-0.0.1a50.tar.gz 16.0 kB Without provenance Details for mtg_parser-0.0.1a50.tar.gz

Built distribution (wheel)

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

Total release size: 36.5 kB

Release files / mtg_parser-0.0.1a50.tar.gz

Download URL mtg_parser-0.0.1a50.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c85d81cace75b6879ab9bc2fe28c403bcc73c5ccacfd40f0be7dc7d0006d87f4
BLAKE2b-256 checksum
How to use checksums
21ab2cad1e0e81d58149f8e9249c6a3583977fd26303a581fd2f2110b79d5fd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.7 Darwin/23.5.0

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

Download URL mtg_parser-0.0.1a50-py3-none-any.whl
Size 20.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6d1960268f060e6c02d0f692ed193c8eea28ba71af9e6d198643700ef25fcf65
BLAKE2b-256 checksum
How to use checksums
b07aeb96b183fab18ee4ee35401b632215eca6038f10b55a497c743fdf4d5ead
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.2.1 CPython/3.13.7 Darwin/23.5.0

Security for mtg_parser 0.0.1a50

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