Finding Licensed Users

Problem

You need to find licensed users.

Solution

Filter users to those with a licensed account status.

from posit import connect

client = connect.Client()
users = client.users.find(account_status="licensed")

Users which have not been active within the past year are not counted. Let’s remove them to get an accurate count.

from datetime import UTC, datetime, timedelta
from dateutil import parser


def is_active(user) -> bool:
    try:
        date = parser.isoparse(user.active_time)
    except (ValueError, TypeError):
        # If the date parsing fails, consider the user inactive
        return False

    one_year_ago = datetime.now(UTC) - timedelta(days=365)
    return date > one_year_ago


users = [user for user in users if is_active(user)]

Finally, we can count the total number of active licensed users.

>>> len(users)
141

Get data on all users with a licensed account status.

library(connectapi)
library(purrr)

client <- connect()

page <- 0
all_results <- list()

while (TRUE) {
  page <- page + 1

  res <- client$GET(
    "/v1/users",
    query = list(
      page_number = page,
      page_size = 100,
      account_status = "licensed"
    )
  )
  
  if (length(res$results) == 0) {
    break
  }
  all_results <- append(users, res$results)
}

users <- purrr::map_dfr(all_results, ~.x)

Users which have not been active within the past year are not counted. Let’s remove them to get an accurate count.

library(dplyr)
library(lubridate)


one_year_ago <- now() - ddays(365)

active_users <- users |>
  mutate(across(ends_with("time"), ymd_hms)) |>
  filter(active_time > one_year_ago)

Finally, we can count the total number of active users.

> count(active_users)
# A tibble: 1 × 1
      n
  <int>
1   141

Discussion

A licensed user is someone who has signed into the server and has an active account. The number of licensed users is restricted based on the license purchased, affecting who can access the server and specific content like Shiny applications. If the user limit is reached, new users cannot sign in. Users inactive for over 365 days are not counted against this limit. Additional restrictions may apply to accessing interactive content, depending on the license type.

For more details, visit the Licence Management Documentation.