Finding Groups

Problem

You want to find a subset of the groups on the Connect server.

Solution

Use the groups attribute and use the prefix parameter to filter groups by group name. The prefix is case insensitive (.e.g, “PoSiT” is logically equivalent to “pOsIt”).

from posit import connect

client = connect.Client()
groups = client.groups.find(prefix="data")

The groups.find() method returns a list of groups whose name matches the prefix parameter.

>>> import polars as pl
>>> pl.DataFrame(groups)
shape: (2, 3)
┌─────────────────────────────────┬─────────────────────────────────┬─────────────────┐
│ guid                            ┆ owner_guid                      ┆ name            │
---------
objectobjectstr
╞═════════════════════════════════╪═════════════════════════════════╪═════════════════╡
6d77fcab-92b0-48a2-94fd-f80c6b… ┆ 867f6d6f-53b4-4ee6-8f37-37ce5d… ┆ Data Scientists │
85d1ddff-bb05-4d3b-9f5b-37bb20… ┆ fd7b011b-7d07-4b92-8c7a-69279a… ┆ Data Engineers  │
└─────────────────────────────────┴─────────────────────────────────┴─────────────────┘

Use the get_groups() function. This returns a data frame of all groups on the Connect server. You can filter this as you would any other table.

library(connectapi)
library(dplyr)

client <- connect()

all_groups <- get_groups(client)
> all_groups
# A tibble: 2 × 3
   guid                                 name            owner_guid                          
   <chr>                                <chr>           <chr>                               
 1 c6beca6e-0898-4c27-b295-8beec58735d7 Data Scientists 4d81b29b-a2b2-41d3-8ef5-32cc5f63e679
 2 8071ec0e-9be2-4c26-a829-4f60a21ccb94 Data Engineers  4b03b981-0cfc-4d51-8dd4-a5521fe6dfb0

Discussion

You can also use the prefix parameter to find a specific group by name if you do not know the group guid. Beware that multiple groups can exists with the same prefix. If this happens, the SDK will only return one group without warning that multiple possible matches exist. Therefore, verifying that group information is correct is important before performing additional actions.

from posit import connect

client = connect.Client()
group = client.groups.find_one(prefix="Data Scientists")