GithubHelp home page GithubHelp logo

3t0n / steamapi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from smiley/steamapi

0.0 1.0 0.0 128 KB

An unofficial object-oriented Python library for accessing the Steam Web API.

License: MIT License

Python 100.00%

steamapi's Introduction

SteamAPI Build Status

An object-oriented Python 2.7+ library for accessing the Steam Web API.

What's this?

It's a Python library for accessing Steam's Web API, which separates the JSON, HTTP requests, authentication and other web junk from your Python code. Your code will still ask the Steam Web API for bits and bobs of user profiles, games, etc., but invisibly, lazily, and in a cached manner.

It's super-easy to use, straightforward and designed for continuous use. Finally, an easy way to interface with Steam!

How?

With some abstraction, Pythonic classes and magic tricks. Essentially, I use requests for the actual communication, a few converter classes for parsing the output and making it a proper object, and some well-timed caching to make sure lazy-initialization doesn't get you down.

How do I use this?

Clone the repository & run python setup.py develop. (Or download it & run python setup.py install, which copies the code to your local Python packages folder)

Then, you can use it like this:

>>> import steamapi
>>> steamapi.core.APIConnection(api_key="ABCDEFGHIJKLMNOPQRSTUVWXYZ", validate_key=True)  # <-- Insert API key here
>>> steamapi.user.SteamUser(userurl="smileybarry")  # For http://steamcommunity.com/id/smileybarry
Or:
>>> steamapi.user.SteamUser(76561197996416028)  # Using the 64-bit Steam user ID
<SteamUser "Smiley" (76561197996416028)>
>>> me = _
>>> me.level
22
>>> me.friends
[<SteamUser "Bill" (9876543210987654321)>, <SteamUser "Ted" (1234876598762345)>, ...]

Or maybe even like this:

...
>>> me.recently_played
[<SteamApp "Dishonored" (205100)>, <SteamApp "Saints Row: The Third" (55230)>, ...]
>>> me.games
[<SteamApp "Counter-Strike: Source" (240)>, <SteamApp "Team Fortress Classic" (20)>, <SteamApp "Half-Life: Opposing Force" (50)>, ...]

More examples

Flask-based web service

How about a Flask web service that tells a user how many games & friends he has?

from flask import Flask, render_template
from steamapi import core, user

app = Flask("Steamer")
core.APIConnection(api_key="YOURKEYHERE")

@app.route('/user/<name>')
def hello(name=None):
  try:
    try:
      steam_user = user.SteamUser(userid=int(name))
    except ValueError: # Not an ID, but a vanity URL.
      steam_user = user.SteamUser(userurl=name)
    name = steam_user.name
    content = "Your real name is {0}. You have {1} friends and {2} games.".format(steam_user.real_name,
                                                                                  len(steam_user.friends),
                                                                                  len(steam_user.games))
    img = steam_user.avatar
    return render_template('hello.html', name=name, content=content, img=img)
  except Exception as ex:
    # We might not have permission to the user's friends list or games, so just carry on with a blank message.
    return render_template('hello.html', name=name)
  
if __name__ == '__main__':
  app.run()

(hello.html can be found here)

You can try it out for yourself by cloning/downloading a ZIP and deploying it to Google App Engine for free.


The library was made for both easy use and easy prototyping. It supports auto-completion in IPython and other standards-abiding interpreters, even with dynamic objects (APIResponse). I mean, what good is an API if you constantly have to have the documentation, a browser and a web debugger open to figure it out?

Note that you need an API key for most commands, but API keys can be obtained immediately, for free, from the Steam Web API developer page.

The API registration page requires a domain, but it's only a formality. It's not enforced by the API server.

FAQ

Don't see your question here? More questions were asked and answered in the "Issues" section.

Does this work?

Yep! You can try the examples above, or you can just jump in and browse the API using an interpreter. I recommend IPython; it has some awesome auto-completion, search & code inspection.

How can I get * using the API? I can't find it here.

You can open a Python interpreter and play around with the library. It's suited for experimentation and prototyping, to help prevent these exact cases. A full documentation will be available soon.

If you still can't find it, I might've not implemented it yet. This is still a work in progress. Don't worry though, I plan to have the entire public API mapped & available soon!

I have a feature/change that I think should go in. How can I participate?

You can do one of two things:

  1. Fork the repository and make your changes. When you're done, send me a pull request and I'll look at it.
  2. Open a ticket and tell me about it. My aim is to create the best API library in terms of comfort, flexibility and capabilities, and I can't do that alone. I'd love to hear about your ideas.

Is this official?

No, and it's also not endorsed in any way by Valve Corporation. (obligatory legal notice) I couldn't find a fitting name at this point for it, so I just skipped it for now.

Can I use this library in my busy web app?

No, but feel free to experiment with it. It's roughly stable right now, with many of the quirks fixed and most classes having a steady API. Small refactorings are rare, and I do plan to overhaul the object system to allow async/batching behaviour, but that's still a way off.

Is this still actively-developed? The last commit is quite a while ago!

Yes, but less than before. This is a side-project, and sadly work has become hectic enough that I have less time and energy to work on this & other side-projects.

That doesn't mean I'm not working on it at all, but it does mean development's gotten slower.

steamapi's People

Contributors

3t0n avatar francislab avatar kidjourney avatar phantium avatar rdkr avatar scottrice avatar smiley avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.