Skip to content

Rustbeard86/AppIdStream

Repository files navigation

AppIdStream

A simple .NET 10 library for retrieving Steam application data with automatic pagination.

Features

  • Automatic pagination (default 50,000 results per page)
  • Async streaming with IAsyncEnumerable<SteamApp>
  • File and stream output options
  • Progress/error reporting via IMessageSink
  • Minimal memory footprint with streaming mode
  • Standalone CLI tool included

Build

./build.ps1

This produces:

  • publish/ - Library DLL and CLI tool

The CLI source is generated at build time in .cli-build/ (excluded from solution/git) and cleaned up after compilation.

Build Options

./build.ps1 -SkipCli   # Library only, no CLI

CLI Usage

# With API key argument (outputs to app directory)
steamapps your-api-key

# With custom output path
steamapps your-api-key C:\output\steam-apps.json

# Using environment variable
set STEAM_API_KEY=your-api-key
steamapps

Getting an API Key

  1. Go to https://steamcommunity.com/dev/apikey
  2. Log in with your Steam account
  3. Register for a key (free, requires Steam account)

Library Usage

Quick Start

using AppIdStream;

// Create client with your Web API key
using var client = new SteamAppIdClient("your-api-key");

// Stream all apps
await foreach (var app in client.GetAllAppsAsync())
{
    Console.WriteLine($"{app.AppId}: {app.Name}");
}

Basic Streaming

Iterate through all Steam apps with automatic pagination:

using var client = new SteamAppIdClient("your-api-key");

await foreach (var app in client.GetAllAppsAsync())
{
    // Process each app as it arrives
    Console.WriteLine($"{app.AppId}: {app.Name}");
}

Write to File

Save all apps as a JSON file:

using var client = new SteamAppIdClient("your-api-key");

await client.WriteToFileAsync("steam-apps.json");

Stream to File (Low Memory)

For large datasets, stream directly to a file without buffering:

using var client = new SteamAppIdClient("your-api-key");

await using var file = File.Create("steam-apps.json");
await client.StreamToAsync(file);

Progress Reporting

Monitor progress using the built-in console sink:

using var client = new SteamAppIdClient("your-api-key");

await client.WriteToFileAsync(
    "steam-apps.json",
    messageSink: new ConsoleMessageSink()
);

// Output:
// Page 1: Retrieved 50000 apps (Total: 50000)
// Page 2: Retrieved 50000 apps (Total: 100000)
// Complete: 150000 apps retrieved across 3 pages

Custom Message Sink

Implement IMessageSink for custom logging:

public class MyLogger : IMessageSink
{
    public void OnProgress(int pageNumber, int appsRetrieved, int totalApps)
        => Log.Info($"Page {pageNumber}: {totalApps} total");

    public void OnError(string message, Exception? ex)
        => Log.Error(ex, message);

    public void OnComplete(int totalApps, int totalPages)
        => Log.Info($"Done: {totalApps} apps");
}

// Usage
using var client = new SteamAppIdClient("your-api-key");
await client.WriteToFileAsync("apps.json", messageSink: new MyLogger());

Custom Page Size

Adjust the number of results per API call:

using var client = new SteamAppIdClient("your-api-key");

// Smaller pages (useful for testing or rate limiting)
await foreach (var app in client.GetAllAppsAsync(pageSize: 10_000))
{
    Console.WriteLine(app.Name);
}

Cancellation Support

Cancel long-running operations:

using var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5));
using var client = new SteamAppIdClient("your-api-key");

try
{
    await client.WriteToFileAsync(
        "steam-apps.json",
        cancellationToken: cts.Token
    );
}
catch (OperationCanceledException)
{
    Console.WriteLine("Operation timed out");
}

Using Custom HttpClient

Provide your own HttpClient for custom configuration:

var httpClient = new HttpClient
{
    Timeout = TimeSpan.FromMinutes(2)
};

using var client = new SteamAppIdClient("your-api-key", httpClient);
await client.WriteToFileAsync("apps.json");

API Reference

SteamAppIdClient

Method Description
GetAllAppsAsync() Streams all apps as IAsyncEnumerable<SteamApp>
WriteToFileAsync() Writes all apps as JSON to a file
WriteToStreamAsync() Writes all apps as JSON to a stream (buffered)
StreamToAsync() Streams JSON directly to output (low memory)

SteamApp Record

Property Type Description
AppId uint Steam application ID
Name string Application name
LastModified long Last modification timestamp
PriceChangeNumber long Price change tracking number

IMessageSink

Method Description
OnProgress() Called after each page is retrieved
OnError() Called when an error occurs
OnComplete() Called when all pages are retrieved

Requirements

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published