Project

mtg-db

0.01
No commit activity in last 3 years
No release in over 3 years
mtg-db is a Ruby gem containing data for all Magic: The Gathering cards and sets, in JSON format. The linked repository contains rake scripts to scrape new data and update the JSON files.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

mtg-db Gem Version

Ruby gem containing structured data for all Magic: The Gathering cards.

Installation

Include in your Gemfile

source 'https://rubygems.org'
gem 'mtg-db', '>= 2.4.2'

or install from Rubygems

gem install mtg-db

Usage

Ruby

require 'mtg-db'

all_sets = Mtg::Db.sets
all_set_json = Mtg::Db.sets.to_json

all_cards = Mtg::Db.cards
all_card_json = Mtg::Db.cards.to_json

aether_revolt_cards = Mtg::Db.cards(:aer)

JSON Format

Sets

A set1 in Magic: The Gathering is a pool of cards released together and designed for the same play environment.

ATTRIBUTES
  • name Required string. The set's name as listed on Wizards of the Coasts's Gatherer card database.
  • release_date Required string. The calendar date of the set's release. In the case of some older sets, the closest known date is used.
  • code Required string. The unique code used to identify the set. Often a three-character string. Notable exceptions are Masterpiece sets and Duel Decks with codes mps_kld, dd3_dvd, etc.
EXAMPLE JSON
{
  "name": "Aether Revolt",
  "release_date": "January 20, 2017",
  "code": "aer"
}
EXCEPTIONS

mtg-db overrides the attributes of some sets to maintain internal consistency and correct Gatherer errors. See these override files:

Cards

ATTRIBUTES
  • name Required string. The cards's name as listed on Wizards of the Coasts's Gatherer card database.
  • set_name Required string. The Magic set this card is from.
  • collector_num2 Required string. This card's collector number. First used in Exous, collector numbers for earlier sets have been generated using the same ordering system. May contain letters and numbers.
  • illustrator Optional string. The illustrator of this card's art.
  • types3 Required string array of the card's types. Possible values are Artifact, Conspiracy, Creature, Enchantment, Instant, Land, Planeswalker, Sorcery, Tribal, and Vanguard.
  • supertypes4 Optional string array of the card's supertypes. Possible values are Basic, Legendary, World, and Snow.
  • subtypes5 Optional string array of the card's subtypes.
  • rarity6 Required string. Rarity defines the scarcity of cards in boosters and indicates the complexity of the card. Possible values are Common, Uncommon, Rare, Mythic, Special, and Land.
  • mana_cost7 Optional string. The mana payment required to cast a spell. See mana_cost_symbols.yml for the system used to encode mana symbols.
  • converted_mana_cost8 Required integer. The total amount of mana the card's mana cost, regardless of color.
  • oracle_text9 Optional string array of the card's up-to-date rules text. Each element of the array represents one line of rules text. Four times a year the Oracle is updated to incorporate changes to cards that do not work as intended.
  • flavor_text10 Optional string. Italicized text that serves to provide mood or give background information on the game world, but has no effect on gameplay.
  • power11 Optional string. The amount of damage a Creature or Vehicle deals. Usually an integer, but may contain a modifier such as * or X.
  • toughness12 Optional string. The amount of damage needed to kill a Creature or Vehicle. Usually an integer, but may contain a modifier such as * or X.
  • loyalty13 Optional string. The number of loyalty counters a Planeswalker enters the battlefield with. Usually an integer, but may contain a modifier such as X.
  • multiverse_id: Optional integer. An identifier unique to the printing of a card. Cards missing from Gatherer will have an empty multiverse_id.
  • other_part: Optional string. The name of the other half of a double-faced,14 flip,15 meld,16 or split card.17
  • color_indicator18 Optional string. Used when a card's color can't be identified by its mana cost. Possible values are White, Blue, Black, Red, or Green
  • rulings Optional array of objects, each containing the text and date for an Oracle ruling associated with this card.
EXAMPLE JSON
{
  "name": "Aerial Modification",
  "set_name": "Aether Revolt",
  "collector_num": "1",
  "illustrator": "Jung Park",
  "types": [
    "Enchantment"
  ],
  "supertypes": [],
  "subtypes": [
    "Aura"
  ],
  "rarity": "Uncommon",
  "mana_cost": "4W",
  "converted_mana_cost": 5,
  "oracle_text": [
    "Enchant creature or Vehicle",
    "As long as enchanted permanent is a Vehicle, it's a creature in addition to its other types.",
    "Enchanted creature gets +2/+2 and has flying."
  ],
  "flavor_text": null,
  "power": null,
  "toughness": null,
  "loyalty": null,
  "multiverse_id": 423668,
  "other_part": null,
  "color_indicator": null,
  "rulings": [
    {
      "date": "2/9/2017",
      "text": "If Aerial Modification becomes unattached from a Vehicle that’s attacking or blocking, that Vehicle will be removed from combat unless another effect (such as its crew ability) is also making it a creature."
    }
  ]
}
EXCEPTIONS

mtg-db overrides the attributes of some cards to maintain internal consistency and correct Gatherer errors. See these override files: