Finding Licensed Users
Problem
You need to find licensed users.
Solution
Filter users to those with a licensed account status.
from posit import connect
= connect.Client()
client = client.users.find(account_status="licensed") users
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:
= parser.isoparse(user.active_time)
date except (ValueError, TypeError):
# If the date parsing fails, consider the user inactive
return False
= datetime.now(UTC) - timedelta(days=365)
one_year_ago return date > one_year_ago
= [user for user in users if is_active(user)] users
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)
<- connect()
client
<- 0
page <- list()
all_results
while (TRUE) {
<- page + 1
page
<- client$GET(
res "/v1/users",
query = list(
page_number = page,
page_size = 100,
account_status = "licensed"
)
)
if (length(res$results) == 0) {
break
}<- append(users, res$results)
all_results
}
<- purrr::map_dfr(all_results, ~.x) users
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)
<- now() - ddays(365)
one_year_ago
<- users |>
active_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.