Skip to main content

Track and analyze Steam playtime statistics

Project description

Steam Playtime to SQLite

A command-line tool to collect Steam playtime information into a SQLite database for easy analysis with Datasette. Comes with some default report options built-in.

Requirements

Installation

pip install steam-playtime-to-sqlite

# Or with uv like the cool kids
uv tool install steam-playtime-to-sqlite

# Or run with uvx for ad-hoc usage
uvx steam-playtime-to-sqlite

From Source

  1. Clone the repository
  2. pip install .
    
    # Or with uv like the cool kids
    uv install .
    

You can also just copy the steam.py file from this repo and use it directly.

Usage

First Setup

Initialize the database and import initial state of playtime data:

steam-playtime-to-sqlite init --api-key YOUR_API_KEY --username STEAM_USERNAME

Notes:

  • STEAM_USERNAME can be either your Steam vanity username or your 64-bit Steam ID
  • The tool will create a SQLite database in the current directory by default

Perpetual Updates

For accurate tracking, you'll need to run the update command daily:

steam-playtime-to-sqlite update --api-key YOUR_API_KEY --username STEAM_USERNAME

See the How Steam Playtime Tracking Works section below for more details.

Available Reports

Daily Report

View playtime sessions for a specific day:

steam-playtime-to-sqlite report daily --day 2025-04-01

Monthly Report

View playtime summary for a specific month:

steam-playtime-to-sqlite report monthly --month 2025-03

Top 10 by Time

View your top 10 most played games by total playtime:

steam-playtime-to-sqlite report top-time

Top 10 by Days

View your top 10 most played games by number of days played:

steam-playtime-to-sqlite report top-days

Per-Game Report

View detailed playtime history for a specific game:

steam-playtime-to-sqlite report per-game --appid 570  # 570 is the AppID for Dota 2

Other Options

  • Change the database file location:

    steam-playtime-to-sqlite --db /path/to/database.db [command]
    
  • Change the logging level:

    steam-playtime-to-sqlite --log-level DEBUG [command]
    

    Available levels: DEBUG, INFO, WARNING, ERROR

How Steam Playtime Tracking Works

Understanding Steam API Limitations

Steam's API doesn't provide granular session data, it only offers cumulative lifetime playtime per game. To work around this limitation, this tool is intended to be run daily and keep historic data. By taking a daily snapshot of total playtime for all your games, it can calculate daily playtime per game by comparing consecutive snapshots.

Recommended Setup: Daily Cron Job

Ideally, set up a daily cron job to run the update command. By default, the tool saves new data with the date of yesterday. I sometimes play a bit past midnight, but I consider that to still count for the day before midnight. By running my cronjob around 6am, I get the most accurate data for my purposes.

Example crontab entry:

55 05 * * * steam-playtime-to-sqlite --db /path/to/database.db update --api-key YOUR_API_KEY --username STEAM_USERNAME

However, your mileage may vary. If you prefer running a cronjob right at 23:59 each day, you may want to use the --date parameter to specify the date of today for the new entries.

What Happens If You Miss Updates?

While the --date parameter sounds like backfilling might be possible, Steam simply doesn't provide data with the historical accuracy needed for that. However, should better APIs or data sources become available, backfilling directly into the SQLite database will be feasible.

Using with Datasette

This tool was designed to work well with Datasette in case you want to do any more specific analysis.

  1. Install Datasette:

    pip install datasette
    
    # Or run with uvx for ad-hoc usage
    uvx datasette
    
  2. Run Datasette with your Steam playtime database:

    datasette steam_playtime.db
    

Check the queries for existing reports in the source for inspiration.

Data Storage / Model

Data is stored locally in a SQLite database. By default, it is named steam_playtime.db and put in the working directory. The database contains two tables:

  • games: Stores game metadata (app ID and name)
  • sessions: Stores daily playtime snapshots for each game

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

steam_playtime_to_sqlite-0.1.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

steam_playtime_to_sqlite-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file steam_playtime_to_sqlite-0.1.0.tar.gz.

File metadata

File hashes

Hashes for steam_playtime_to_sqlite-0.1.0.tar.gz
Algorithm Hash digest
SHA256 20e42e2c12b3d6a47db041b3a0ecb4b009dcae8785469de6cb53cc0b3f70973b
MD5 9d31168ff7b445154159e9df64e97083
BLAKE2b-256 070bccc5fa71c3b6369b919e4c7828299e01e87a0dfc425c0ec52bceac5c9ba2

See more details on using hashes here.

File details

Details for the file steam_playtime_to_sqlite-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for steam_playtime_to_sqlite-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 69ebb2528efd4a336039ae089783b50886227d9d6deb83b90f471ddb7da35e41
MD5 163c04669a9f7eaa0ca8e71e21057d14
BLAKE2b-256 ba0a0d53cdb62955a2b565f269ffe4950a95a51904c3a4874ee4c2381e203666

See more details on using hashes here.

Supported by

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