valvepython/steam

repository·master·Indexed 23 days ago

https://github.com/valvepython/steam

A Python module for interacting with the Steam network, including the Steam Client, Web API, and Content Delivery Networks. It provides tools such as SteamClient for network interaction, WebAPI for Steam's web services, CDNClient for content depots, and utilities for managing SteamID formats and Steam Guard authentication.

Tokens
5.3K
Snippets
15
Records
34
Agent score
79%

What's inside valvepython-steam

  1. Overview of steam features

    master

    The steam module provides several specialized clients and utilities for interacting with Steam:

    • SteamClient: Communication with the Steam network (requires gevent).
    • CDNClient: Access to Steam content depots.
    • WebAuth: Authentication for store.steampowered.com and steamcommunity.com.
    • WebAPI: A simple API for Steam's Web API with automatic interface population.
    • SteamAuthenticator: Manage two-factor authentication (Steam Guard) for accounts.
    • SteamID: Utilities to convert between various Steam ID representations.
    • Master Server Query Protocol: Query master servers directly or via SteamClient.
  2. Overview of steam library features

    master

    The steam Python module provides tools for interacting with various Steam services. Key components include:

    • SteamClient: Communication with the Steam network using gevent.
    • CDNClient: Access to Steam content depots.
    • WebAuth: Authentication for store.steampowered.com and steamcommunity.com.
    • WebAPI: A simple interface for Steam's Web API with automatic population of interfaces.
    • SteamAuthenticator: Management of two-factor authentication for Steam accounts.
    • SteamID: Utilities to convert between different Steam ID representations.
    • Master Server Query Protocol: Direct or SteamClient-mediated querying of master servers.

    Supports Python 2.7+ and 3.4+.

  3. Access Steam built-in service modules

    master
    The steam.client.builtins module provides access to various Steam services through specialized submodules. These modules allow you to interact with different aspects of the Steam ecosystem, such as user data, app information, web services, and social features. Depending on your needs, you can import specific service modules directly from steam.client.builtins.
  4. Install steam on Linux

    master

    To install the steam package on Linux, ensure python and pip are already installed on your system. It is recommended to use virtualenv to avoid modifying system packages.

    1. Install necessary dependencies.
    2. Run the installation command via pip.
    pip install steam
  5. Install the steam library via pip

    master

    You can install the library from PyPI. Choose between the full installation (including SteamClient dependencies like gevent and protobufs) or a lightweight version.

    With SteamClient dependencies (recommended for full functionality):

    pip install -U "steam[client]"

    Without SteamClient dependencies (lightweight, for non-gevent/protobuf parts):

    pip install -U steam
    # with SteamClient dependecies
    pip install -U "steam[client]"
    
    # without (only when using parts that do no rely on gevent, and protobufs)
    pip install -U steam
  6. Install steam from GitHub

    master

    If you need the cutting-edge development version or a specific version tag from GitHub, use the following commands.

    • Cutting edge: Installs from the master branch.
    • Specific version tag: Installs a specific tag (e.g., v1.0.0). You can also specify the [client] extra for specific tags.
    # cutting edge from master
    pip install git+https://github.com/ValvePython/steam#egg=steam
    
    # specific version tag (e.g. v1.0.0) with SteamClient extras
    pip install git+https://github.com/ValvePython/steam@v1.0.0#egg=steam[client]
    
    # specific version tag (e.g. v1.0.0) without SteamClient extras
    pip install git+https://github.com/ValvePython/steam@v1.0.0#egg=steam
  7. Use the Steam WebAPI

    master

    The WebAPI class in steam.webapi is a wrapper around the Steam Web API. It automatically fetches available interfaces and populates the namespace upon initialization.

    Setup

    1. Obtain an API Key from http://steamcommunity.com/dev/apikey (requires a verified email).
    2. Initialize the WebAPI instance with your key.

    Calling Endpoints

    Endpoints are accessed via the pattern api.<interface>.<method>() or api.call('<interface>.<method>', **params).

    • Versioned methods: You can call specific versions of a method using the suffix _v1, _v2, etc. (e.g., api.ISteamUser.ResolveVanityURL_v1(...)).
    • Parameters: You can pass parameters directly to the method or via api.call(). Some methods require parameters to be passed as a list.
    • Global configuration: You can set key, format, raw, and http_timeout on the WebAPI instance to affect all calls.
    • Formats: Supported formats are json (default), vdf, and xml. If raw=True, the response is not deserialized.

    Documentation

    You can inspect available interfaces and methods using the .doc() method:

    • api.ISteamUser.ResolveVanityURL.__doc__: Method documentation.
    • api.ISteamUser.ResolveVanityURL.doc(): Prints method documentation.
    • api.ISteamUser.doc(): Prints interface and all its methods.
    • api.doc(): Prints all available interfaces.
    from steam.webapi import WebAPI
    
    api = WebAPI(key="<your api key>")
    
    # Call via namespace
    api.ISteamWebAPIUtil.GetServerInfo()
    
    # Call via .call()
    api.call('ISteamWebAPIUtil.GetServerInfo')
    
    # Call with parameters
    api.ISteamUser.ResolveVanityURL(vanityurl="valve", url_type=2)
    api.call('ISteamUser.ResolveVanityURL', vanityurl="valve", url_type=2)
    
    # Call a specific version
    api.ISteamUser.ResolveVanityURL_v1(vanityurl="valve", url_type=2)
    
    # Inspect documentation
    api.ISteamUser.ResolveVanityURL.doc()
    api.ISteamUser.doc()
    api.doc()
  8. Install the steam package

    master

    To avoid conflicts with system packages, it is recommended to use virtualenv to create an isolated environment before installing the steam package.

    1. Create a virtual environment: virtualenv env
    2. Activate the environment: source env/bin/activate
    3. Install the package via pip: pip install steam

    To exit the virtual environment, use the deactivate command.

    $ virtualenv env
    $ source env/bin/activate
    (env)$ pip install steam
    
    To deactivate
    
    (env)$ deactivate
  9. Install steam on Windows via Cygwin

    master

    If you are using Cygwin on Windows, follow these steps to install steam. Note that installation may take some time as several dependencies will be compiled.

    1. Download the Cygwin installer from https://cygwin.com/install.html.
    2. During setup, ensure you select the following packages:
      • python3
      • python3-setuptools
    3. Install pip by opening a Cygwin terminal and running: easy_install-3.4 pip.
    4. Install the package using pip.

    It is recommended to use virtualenv to keep system packages untouched.

    easy_install-3.4 pip
    pip install steam
  10. Set up a development environment with Vagrant

    master

    The repository includes a Vagrantfile for experimentation and development. This sets up an Ubuntu 16.04 VM with python2 and python3 virtual environments pre-configured.

    1. Spin up the VM:
      vagrant up
    2. Access the VM:
      vagrant ssh
    3. Activate the desired environment:
      • For Python 2: source venv2/bin/activate
      • For Python 3: source venv3/bin/activate
    vagrant up    # spin the VM and let it setup
    vagrant ssh
    # for python2
    $ source venv2/bin/activate
    # for python3
    $ source venv3/bin/activate
  11. Access Steam Web Sessions

    master

    There are two ways to gain access to Steam websites:

    1. Using the WebAuth class in steam.webauth.
    2. Using SteamClient.get_web_session(), which returns a requests.Session object that can be used to make authenticated requests to Steam sites like the Store.
    # Using SteamClient to get a web session
    session = client.get_web_session()  # returns requests.Session
    session.get('https://store.steampowered.com')