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 │
│ --- ┆ --- ┆ --- │
│ object ┆ object ┆ str │
╞═════════════════════════════════╪═════════════════════════════════╪═════════════════╡
│ 6d77fcab-92b0-48a2-94fd-f80c6b… ┆ 867f6d6f-53b4-4ee6-8f37-37ce5d… ┆ Data Scientists │
│ 85d1ddff-bb05-4d3b-9f5b-37bb20… ┆ fd7b011b-7d07-4b92-8c7a-69279a… ┆ Data Engineers │
└─────────────────────────────────┴─────────────────────────────────┴─────────────────┘You can also use the groups.find_one() method to find a specific group. 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.
group = client.groups.find_one(prefix="Data Scientists")Use the get_groups() function. This returns a data frame of all groups on the Connect server.
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-a5521fe6dfb0You can also provide a prefix argument to filter the results returned from the API.
ds_groups <- get_groups(client, prefix = "Data Scientists")> ds_groups
# A tibble: 1 × 3
guid name owner_guid
<chr> <chr> <chr>
1 c6beca6e-0898-4c27-b295-8beec58735d7 Data Scientists 4d81b29b-a2b2-41d3-8ef5-32cc5f63e679