Viewing Tag Information
Problem
You want to find information on a tag for use in a tag-related workflow.
Solution
Tagging workflows in the Python SDK generally use the tag ID.
from posit import connect
= connect.Client()
client
= client.tags.find() tags
The API results can be transformed into a DataFrame for easy viewing and filtering.
>>> import polars as pl
>>> pl.DataFrame(tags)
309, 5)
shape: (
┌─────┬─────────────────────────────────┬───────────┬──────────────────────┬──────────────────────┐id ┆ name ┆ parent_id ┆ created_time ┆ updated_time │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ str ┆ str ┆ str │
│
╞═════╪═════════════════════════════════╪═══════════╪══════════════════════╪══════════════════════╡1 ┆ Technology ┆ null ┆ 2017-04-18T19:53:45Z ┆ 2017-05-01T11:29:36Z │
│ 2 ┆ Health ┆ null ┆ 2017-04-18T19:54:05Z ┆ 2017-05-02T13:57:31Z │
│ 4 ┆ Software ┆ 1 ┆ 2017-04-18T19:54:24Z ┆ 2017-05-19T18:15:39Z │
│ 5 ┆ Mobile Apps ┆ 4 ┆ 2017-04-18T19:54:32Z ┆ 2017-05-03T20:15:27Z │
│ 6 ┆ Version 1.6.0 ┆ 207 ┆ 2017-05-18T04:53:31Z ┆ 2017-05-18T05:00:20Z │
│
│ … ┆ … ┆ … ┆ … ┆ … │751 ┆ Artificial Intelligence ┆ 736 ┆ 2024-06-03T03:26:58Z ┆ 2024-06-03T04:03:24Z │
│ 752 ┆ Machine Learning ┆ 736 ┆ 2024-06-03T03:27:43Z ┆ 2024-06-03T04:04:04Z │
│ 753 ┆ Deep Learning ┆ 736 ┆ 2024-06-03T03:28:12Z ┆ 2024-06-03T04:04:16Z │
│ └─────┴─────────────────────────────────┴───────────┴──────────────────────┴──────────────────────┘
To view family information about a specific tag, you can inspect it’s child_tags
, descendant_tags
, or parent_tag
attributes.
= "TAG_ID_HERE"
tag_id
= client.tags.get(tag_id)
tag # Parent tag
= tag.parent_tag
parent_tag
# Child tags
= tag.child_tags.find()
child_tags
# Descendant tags
= tag.descendant_tags.find() descendant_tags
Tagging workflows in R generally use the Tag
objects, which are obtained using the get_tags()
function.
Use the get_tags()
function to get a tree of all tags on Connect. You can browse the hierarchy using R’s $
operator. Alternately, use the get_tag_data()
function to get a data frame of tag data.
library(connectapi)
<- connect()
client
<- get_tags(client)
tag_tree <- tag_tree$Departments$Administrative
tag <- get_tag_data(client) tag_data
The tag tree and individual tags returned by get_tags()
print a tree-based view. Meanwhile, get_tag_data()
returns a data frame.
> tag_tree
Tree (target_content)
Posit Connect Tag
└── Departments
└── Administrative> tag
Tree (filtered)
Posit Connect Tag
└── Administrative> tag_data
# A tibble: 2 × 5
id name created_time updated_time parent_id<chr> <chr> <chr> <chr> <chr>
1 757 Departments 2024-06-20T14:25:20Z 2024-06-20T14:25:20Z NA
2 758 Administrative 2024-06-20T14:27:22Z 2024-06-20T14:27:22Z 757