1. [​IMG]

    Important Links
    Hypixel API Methods
    This API method shows all the active network boosters in-game

    Method Url: https://api.hypixel.net/boosters?key=XXXX

    key -> Your Hypixel API Key
    Find Guild
    This API method allows you to get a guild's id to search guild information

    Method Url 1: https://api.hypixel.net/findGuild?key=XXXX&byName=GUILD_NAME
    Method Url 2: https://api.hypixel.net/findGuild?key=XXXX&byUuid=PLAYER_UUID

    key -> Your Hypixel API Key
    byName -> The guild's name or byUuid -> A player's uuid
    This API method allows you to get a player's friend list

    Method Url: https://api.hypixel.net/friends?key=XXXX&uuid=PLAYER_UUID

    key -> Your Hypixel API Key
    uuid -> A player's uuid
    Game Counts
    This API method allows you to get the player counts of all network games

    Method Url: https://api.hypixel.net/gameCounts?key=XXXX

    key -> Your Hypixel API Key
    This API method allows you to get a guild's information

    Method Url 1: https://api.hypixel.net/guild?key=XXXX&id=GUILD_ID

    Method Url 2: https://api.hypixel.net/guild?key=XXXX&player=PLAYER_UUID
    Method Url 3: https://api.hypixel.net/guild?key=XXXX&name=GUILD_NAME

    key -> Your Hypixel API Key
    id -> Guild ID or player -> A player's uuid or name -> A guild's name
    This API method allows you to get an API key's information

    Method Url: https://api.hypixel.net/key?key=XXXX

    key -> Your Hypixel API Key
    This API method allows you to get leaderboard information

    Method Url: https://api.hypixel.net/leaderboards?key=XXXX

    key -> Your Hypixel API Key
    This API method allows you to get player information

    Method Url: https://api.hypixel.net/player?key=XXXX&player=PLAYER


    key -> Your Hypixel API Key
    player -> A player's UUID or username
    This API method allows you to get a player's in-game status

    Note: This method is deprecated and will soon be removed

    Method Url: https://api.hypixel.net/session?key=XXXX&uuid=PLAYER_UUID


    key -> Your Hypixel API Key
    uuid -> A player's UUID
    This API method allows you to get watchdog information

    Method Url: https://api.hypixel.net/watchdogstats?key=XXXX


    key -> Your Hypixel API Key
    Hypixel API Python Wrappers

    Getting Started
    Generating an API Key

    To start off, you need an API key. API keys can be obtained by connecting to mc.hypixel.net and executing the command /api new which will generate a new API key. Keep this key safe and note it down in a secure area. Do not share your API key.
    Installing the 'Requests' Python Package

    Next, I recommend installing the popular "Requests" Python Package which simplifies HTTP requests and makes the data received easier to use. You can install this package by opening a Command Prompt window (Terminal if you're on a Mac) and executing pip install requests. Now we're ready to start making requests to the API. If you don't have pip installed, you can watch this video
    Installing the 'JSON Formatter' Chrome Extension (Not Required)

    For reading JSON from Chrome, I'd highly recommend using the 'JSON Formatter' Chrome Extension. JSON in the Hypixel API is not indented or formatted and makes it challenging to read. Below, you'll find two examples

    Using the API
    The Basics

    First of all, you want to start by importing the package 'Requests' that you installed with pip.
    import requests
    Next, you wanna start by making a simple request to the API using requests.get(). .json() is suffixed to the request as the Hypixel API returns a JSON response. You can find more information about what JSON is here
    import requests
    data = requests.get("https://api.hypixel.net/player?key=YOUR_API_KEY&name=PLAYER_NAME_HERE").json()
    Upon printing your variable 'data', you'll find that you'll receive a long response containing player information. We're ready to progress to the next step.
    Returning Specific Values

    Working with JSON data can be tricky to newcomers. However, working with JSON data is simple. JSON stores data under keys which can be accessed easily. For example, the API which stores player data stores the player's information under the key 'player' and stores a player's Skywars Coins under the key 'player' -> 'stats' -> 'SkyWars' -> 'coins'.

    import requests
    data = requests.get("https://api.hypixel.net/player?key=YOUR_API_KEY&name=PLAYER_NAME_HERE").json()
    skywarsWins = data["player"]["stats"]["SkyWars"]["coins"]
    Example: Returning a Player's Rank

    Sometimes, accessing a player's rank can be tricky if you're inexperienced with Python and APIs. This is the case as Hypixel's API can contain three different JSON keys expressing a player's rank. 'packageRank', 'newPackageRank' and 'rank'. Let me explain the difference,

    'packageRank' → displays a rank which was bought by a player pre-EULA
    'newPackageRank' → displays a rank which was bought by a player post-EULA
    'rank' → displays a non-package rank (Helper, Mod, Admin, YouTuber)

    Note: The key 'rank' will also display for ex-staff or ex-yt but will be set to 'NORMAL'
    However, sometimes all these keys are not present in a player's API. For example, if you lookup a player who only has a 'newPackageRank', 'packageRank' will not exist in their information.

    Let's see how we'd go around this.
    import requests
    data = requests.get("https://api.hypixel.net/player?key=API_KEY&name=PLAYER").json()
    if "rank" in data["player"] and data["player"]["rank"] != "NORMAL":
        rank = data["player"]["rank"]
    elif "newPackageRank" in data["player"]:
        rank = data["player"]["newPackageRank"]
    elif "packageRank" in data["player"]:
        rank = data["player"]["packageRank"]
        rank = "Non-Donor"
    Error Handling: KeyError

    Sometimes, different players may have keys in their API that other players don't have. For example, players who may have only spent seconds or minutes on the server may not have any karma or network xp. If you tried grabbing these keys from their API when they don't exist, a keyerror will occur and your application may stop running. There is a simple work-around for this error. Just check if the key exists.
    import requests
    data = requests.get("https://api.hypixel.net/player?key=YOUR_API_KEY&name=PLAYER_USERNAME").json()
    karma = data["player"]["karma"] if "karma" in data["player"] else 0
    This small chunch of code will set the variable 'karma' to the amount of karma the player has. If they key 'karma' doesn't exist, the value will be set to 0.
    Further Questions

    If you have any further questions regarding Python or the Hypixel API, don't hesitate to ask in the replies.
    Last edited: Feb 10, 2020
    • Like Like x 7
    • Useful Useful x 2
    • Mod Emerald Mod Emerald x 2
    • Helper Lapis Helper Lapis x 1
  2. lol minimod
    • Like Like x 2
  3. Thank you mr CarCrOfT, very useful thread, this'll be helping me in the future :p
  4. Amazing guide. This will be definitely helpful for anyone who want to get started with using the API.

    Wouldn't it be more efficient if you used try except block?
    try: karma = data["player"]["karma"]
    except: karma = 0
  5. 100x better then mine lol idk what i was thinking
  6. > python

    in what case does using python actually make sense in 2020? because i cant think of a single one.
  7. Python is actually quite a popular programming language, even in modern days. There's so much you can do with it.
    • Agree Agree x 1
  8. Very interesting thread Carcroft. Thanks for the effort behind making it :)
  9. this doesn't actually answer the question. python is only popular because old people who make high school curriculums think it is easy and still useful, and most of them still teach python 2 (which has aged worse than php, and is fundamentally useless).
    python is literally the slowest language still in common use today, and has been more or less replaced by other, better languages in every use case. there is no situation i can think of off the top of my head where python makes the most sense, and makes literally 0 sense in the context of the hypixel api. the only advantage of python is that its easy and fast, and even for quick scripts it just makes more sense to write in shell script or an equivalent.
    • Like Like x 1
  10. Yeah but python is simple to learn so it's kinda good for someone starting out once they learn that they can move to other languages
  11. there are easier languages to learn than python that are better. again, the only reason python is popular is because old people who make high school curriculums say its easy.
  12. I've tried other languages and python is the most simple
  13. literally not answering the question.

    also there are objectively easier languages like visual basic and shell script (not encouraging the use of visual basic but just saying).
  14. That is not true.

    Just listing a few companies who heavily rely on Python: Facebook, Instagram, Google/YouTube, Spotify, Netflix and there are tons more.

    Additionally, Python is very simple and effective, and as such a great way to get into programming.

    Using the Hypixel API with Python I cannot see how you would ever encounter a performance issue.
    • Like Like x 1
  15. Cough* cough* blender cough* yeah without python the entire creative section would be dead
  16. which part is not true? just asking because you proceeded to dodge literally every point i made.
    only one of those is from the last 4 years.
    reddit used to be written primarily in python but over the past few years has been transitioning to rust and other, more modern languages.
    there are easier (and faster) languages than python out there.
    unless all youre doing is parsing regex, literally everything is a performance issue.
    only a fraction of blender is written in python.
  17. I think python is good for beginners because it's so easily readable by someone inexperienced in programming that a lot of the time someone with little to no experience can go onto PyPi and find packages that they find interesting that usually have plenty of examples written into the beginning of the documentation and basically guess / copy and paste there way through a simple script. You also don't need to understand any kind of classes or functions before making a first script as opposed to like Java (or another language that makes you use OOP, which one language you mentioned was Rust where I think all scripts start with like fn main() right?) where you have to start with your imports, class, and methods plus there isnt really any type declaration so someone doesn't need to really know any data types besides oh this is a word and this is a number. Obviously someone should learn a language instead of just trying to bs there way through but I think the people a tutorial like this would be intended for would appreciate it being in a language where getting started is extremely easy since all this really is is a simple request. The reason I believe this though is because I have a friend who basically likes to code only discord bots because discord.py has really easy examples and that is the extent of coding he does for fun. Sorry if this is basically unreadable garbage I'm not even completely sure what I wrote anymore, anyways the point is Python is super easy and this is a good tutorial (except maybe should've used slothpixel api because it doesn't require a key, although I've barely used slothpixel myself so I dont know if there are any downsides to it).
    Last edited: Feb 14, 2020
    • Like Like x 1
  18. im not debating this. that being said there are other languages that are more appropriate for this decade that are also extremely easy to learn.
    see, the problem with python is that it is simply too slow to be a practical choice over literally anything in any situation. even in simple utilities like ranger you notice the sluggish-ness of the language after a few seconds of use. because of this issue (among others) i think a tutorial like this would be more suited for a language that is more suited for the current year.
    i wholeheartedly agree.
    • Agree Agree x 1

Share This Page