This was requested to help people integrate Steamworks into their Python projects. It is primarily for Linux users but should also work for Windows users. A few things that are worth mentioning before we continue:

You will need a Steamworks developer account to use this in your games, as you need an AppID. The Steamworks SDK, as far as I know, is only available to Steamworks developers. As the Steam API is natively a C++ system, there are a few things that will not work. Possibly ever. Steam MUST be running while you test or run the program.

That being said, if you do not have a Steamworks developer account you can still test the system with a valid AppID. It can be from any game but for this example we will use the one from Space Wars - 480. So let’s get into it!

Preparing

Create a new folder for this test and download the SteamworkForPython repository into it.

From here you have a few options:

You can use the pre-build .so or .dll files to proceed. These should work fine. If you choose this route skip ahead to “Integrating SteamworksPy” You can compile your own .so or .dll files. If you choose this route, continue below.

Next you need to download the Steamworks SDK from https://partner.steamgames.com/. You will need a Steamworks developer account to get access to it. Once downloaded, unzip it into a different folder called Steamworks SDK.

Go into this folder and copy the public/steam folder into your SteamworksPy folder.

This contains the API files. Now head to the SDK’s redistributable_bin/ folder and copy the steam_api.lib into your SteamworksPy folder.

Your SteamworksPy test folder should look like this now:

Compiling

For this tutorial will we cover the Linux method first. Head into your SteamworksPy folder and open a terminal window.

You will need GCC or G++ installed for this next part. Depending on your Linux distro this might vary. For this tutorial we will be using Ubuntu so you can just type:

sudo apt-get install gcc g++

Once finished, or if you had them installed already, you can now compile the SteamworksPy.so file. You can run the following command:

gcc -o SteamworksPy.so -shared -fPIC steampy.cpp -lsteam_api

This will output the SteamworksPy.so file.

The Windows compiling is a little different as it requires you to install Visual Studio.

I will have to come back and write this later though. For now you can refer to the “How To” in the ReadMe file from the repository.

Integrating SteamworksPy

Create a new folder called Test Game and place the SteamworksPy.so file (either the one you just compiled or the one from the Pre-Build folder) in here along with the steamworks.py file.

Now create a game.py file and open it in your editor of choice. Also create a blank .txt file and put in only the number 480 then save it as steam_appid.txt.

In your game.py put in the following code:

from steamworks import * Steam.Init() NAME = SteamFriends.GetPlayerName()

print(“Your Steam name is: %s”) %(NAME)

Save your game.py file and start up Steam itself if you don’t have it running already. Once Steam is running, in terminal run you game.py file.

python game.py

You should get something like this:

From here we will add a few more functions from SteamworksPy. Add the following code to the bottom of your game.py file:

print(“Friend Count: %s”) % (SteamFriends.GetFriendCount())

Once again, save the file and run it in terminal. You should see something like this:

You probably want to do more interesting things like achievements, statistics, etc. Well, those are fairly easy to implement but require your Steamworks developer account.

Here is an example of how you might set that up. Place the following code at the end of your game.py file:

GOT_STATS = SteamUserStats.RequestCurrentStats()

print(“Got user stats: %s”) % (GOT_STATS) ACHIEVEMENT1 = SteamUserStats.GetAchievement(‘TEST_ACHIEVEMENT1’)

print(“Have achievement 1? %s”) % (ACHIEVEMENT1) SteamUserStats.SetAchievement('TEST_ACHIEVEMENT2’) SteamUserStats.StoreStats()

The first line pulls all your player statistics and achievements for the game in the AppID file. You must do this first to get any of that data.

The second line sets True/False from the GetAchievement function, which we are passing on to this variable for use in your game.

The third line is setting the achievement on Steam’s servers for the player. It only take the achievement’s Steamworks name as a variable.

The last line updates the changes in Steam’s server. The achievement will not fire until this is called.

If you run the game.py code now you should see the following:

It will show you have pulled the player’s statistics and achievement fine. However, as there are no such achievements for that AppID it will show the achievement here as False. If the achievement was valid, it would mean the player does not has this particular achievement yet.

You can put conditions to check the other two lines but I didn’t feel that was necessary for this tutorial.

As for statistics you can do very similar things. Add the following to your game.py but above your SteamUserStats.StoreStats() line:

SteamUserStats.SetStat('game_wins’, 5) WINS = SteamUserStats.GetStatInt('game_wins’)

print(“Current wins: %s”) % (WINS)

Save and run your game.py file, you should see something like this:

Notice your current wins are 0. This is because that game_wins variable doesn’t exist for this AppID. In your Steamworks account, under your game’s statistics, you would just use whatever stat names you had in there. Again, you will have to pass the SteamUserStats.StoreStats() to save these to the server.

In Conclusion



For more functions please check out the steamworks.py file itself. You may also refer to the Steamworks API to see what else might be possible with the library.

Please feel free to fork the SteamworksPy project on GitHub and add to it. You may also send in requests of functions to add and I will try to get to them as I am continuing to expand this project as much as possible.

If you have any comments, questions, or such you can reach me at gp@coaguco.com or through the GitHub repo for SteamworksPy. Also please use that for any issues that arise with the project so we can keep track of them.

Thanks for reading!