Skip to main content

Tools and utilities for TF2 trading

Project description

tf2-utils

License Stars Issues Size Discord Code style

Tools and utilities for TF2 trading. Use 3rd party inventory providers, get SKUs directly from inventories, listen to BackpackTF's websocket and more.

Donate

Features

  • Get SKUs directly from inventories/offers
  • Fetch inventories using 3rd party providers (avoid being rate-limited)
  • Listen for Backpack.TF websocket events
  • Listen for Prices.TF websocket events

Setup

Install

pip install tf2-utils
# or 
python -m pip install tf2-utils

Upgrade

pip install --upgrade tf2-utils
# or 
python -m pip install --upgrade tf2-utils

Usage

See examples or tests for more usage examples.

Inventory fetching

from tf2_utils import Inventory

# using 3rd party provider to avoid being rate-limited
provider = Inventory("steamsupply", "9st947vs0qmgfpeqde1gj92l0oqmhysm")

# using steam as inventory provider
provider = Inventory() # or Inventory("steamcommunity")

# get an inventory
inventory = provider.fetch("76561198253325712")

Gettings SKUs from inventories

NOTE: NOT ALL SKU ATTRIBUTES ARE ADDED YET

Get SKUs implicitly

from tf2_utils import Inventory, map_inventory

provider = Inventory("steamcommunity")

user_inventory = provider.fetch("76561198253325712")
inventory = map_inventory(user_inventory, add_skus=True)

Get a particular item's SKU

from tf2_utils import get_sku

inventory = map_inventory(user_inventory)

for item in inventory:
    sku = get_sku(item)

BackpackTF Websocket

Handle one listing at a time

from tf2_utils import BackpackTFSocket

def my_function(data: dict):
    print("got data!", data)

socket = BackpackTFSocket(my_function)

socket.listen()

Handle list of listings at a time

from tf2_utils import BackpackTFSocket

def my_function(data: list[dict]):
    print("got listings")

    for listing in data:
        print("listing", listing)

socket = BackpackTFSocket(my_function, solo_entries=False)

socket.listen()

PricesTF Websocket

from tf2_utils import PricesTFSocket

def my_function(data: dict):
    print("got data!", data)

socket = PricesTFSocket(my_function)

socket.listen()

Testing

# tf2-utils/
python -m unittest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tf2-utils-2.0.2.tar.gz (142.9 kB view hashes)

Uploaded Source

Built Distribution

tf2_utils-2.0.2-py3-none-any.whl (66.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page