Introduction to the Valorant API

Assuming you’ve read the Installing valorant.py guide, you’re almost ready to start interacting with the Valorant API. But first, you need an API Key.

Getting an API Key

  1. If you haven’t already, head over to the Riot Games Developer Portal and log in or create an account.

  2. Go back to the home page, scroll down a bit and look for the Developement API Key section. It should look like this:

    Riot Games Developer API Portal
  3. Generate a new API key, and copy it into your project enviornment. (Enviornment variable, .env file, etc.)

  4. That’s it! You’re ready to access the API using valorant.py now.

Making Requests

Now let’s get started using the library. Creating a new Python file, val_example.py, let’s put in some sample code:

 1import os
 2import valorant
 3
 4KEY = os.environ["VALPY-KEY"]
 5client = valorant.Client(KEY, locale=None)
 6
 7skins = client.get_skins()
 8name = input("Search a Valorant Skin Collection: ")
 9
10results = skins.find_all(name=lambda x: name.lower() in x.lower())
11
12print("\nResults: ")
13for skin in results:
14    print(f"\t{skin.name.ljust(21)} ({skin.localizedNames['ja-JP']})")

That’s a lot to cover, so let’s run through it step by step.

  1. The import statements let us use the packages we need. os to access or API key from the enviornment, and valorant to interact with the API.

  2. The 5th line creates an instance of the Client, which represents our connection to the Valorant API. By setting locale to None we can get content data in other languages, which will be handy in a second.

  3. Next we make a request to the API for data on Gun and Melee Skins. This is a ContentList of ContentItemDTO objects, each representing a Skin.

  4. Now we want to get a skin collection name from the user, and show them all the gun skins in that collection. So the 8th line will get the user’s input as name.

  5. The 10th line is the most important of all. Here we use the query function ContentList.get_all() in order to serch the list of skins. We want to match every skin that has the given collection in its name, so we use the expression name in x.name. x is the skin object, and by passing that expression as a lambda into the attribute, that expression will be matched against every skin in the list.

  6. Now that we have our list of skins in the results variable, let’s print it out to the user! Lines 13 and 14 loop through the results and print each skin’s name in a nice and neat manner :>

  7. And as an added bonus, because we didn’t give the client a locale, we can also display each skin’s Japanese name as well, using skin.localizedNames['ja-JP'].

Now to run it!

$ python val_example.py

Assuming everything goes well, your program should run smoothly and look like this:

Example Program Result

Congrats, you’ve written your first program with valorant.py! Check out the other guides for more.