Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tags - Create, delete, info, find content with tag, and view content item tags #345

Closed
schloerke opened this issue Nov 25, 2024 · 3 comments · Fixed by #346
Closed

Tags - Create, delete, info, find content with tag, and view content item tags #345

schloerke opened this issue Nov 25, 2024 · 3 comments · Fixed by #346
Assignees
Labels
enhancement New feature or request sdk Used for automation

Comments

@schloerke
Copy link
Collaborator

schloerke commented Nov 25, 2024

Currently, all recipes are done using the API. This is green field territory!

View information

from posit import connect
client = connect.Client()

res = client.get("/v1/tags")
>>> import polars as pl
>>> pl.DataFrame(res.json())
shape: (309, 5)
┌─────┬─────────────────────────────────┬───────────┬──────────────────────┬──────────────────────┐
│ 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 │
└─────┴─────────────────────────────────┴───────────┴──────────────────────┴──────────────────────┘

Create

from posit import connect

TAG_CATEGORY_NAME = "Departments"

client = connect.Client()
response = client.post("/v1/tags", json={
    "name": "Departments",
})

departments = response.json()

# ----------------------------------
# Create w/ parent tag

PARENT_TAG_ID = departments['id']
TAG_NAME = "Administrative"

res = client.post("/v1/tags", json={
    "name": TAG_NAME,
    "parent_id": PARENT_TAG_ID
})

administrative = response.json()

Delete

from posit import connect

TAG_ID = "your-tag-id"

client = connect.Client()

client.delete(f"/v1/tags/{TAG_ID}")

Find content using tag

from posit import connect
client = connect.Client()

TAG_ID = "42"

res = client.get(f"/v1/tags/{TAG_ID}/content")
>>> import polars as pl
>>> pl.DataFrame(res.json())
shape: (24, 45)
┌─────────────────────────────────┬──────────────────────────────┬──────────────────────────────┬──────────────────────────────────────────────────────────────────────────────┐
│ guid                            ┆ name                         ┆ title                        ┆ description                                                                  │
│ ---                             ┆ ---                          ┆ ---                          ┆ ---                                                                          │
│ str                             ┆ str                          ┆ str                          ┆ str                                                                          │
╞═════════════════════════════════╪══════════════════════════════╪══════════════════════════════╪══════════════════════════════════════════════════════════════════════════════╡
│ 5b6f05d1-1fea-480b-b8fa-51aec6… ┆ AI-Overview                  ┆ Introduction to AI           ┆ An introductory overview of Artificial Intelligence and its core concepts.   │
│ 7ec59570-b199-4f16-8fff-86e3c6… ┆ ML-Models                    ┆ Machine Learning Models      ┆ Detailed explanation of various machine learning models and their applicatio │
│ 3f4140dd-5924-4b31-bb2e-2031b2… ┆ DeepLearning-Techniques      ┆ Advanced Deep Learning       ┆ Exploration of advanced techniques in deep learning, including neural network│
│ 62ebbc03-818b-41f2-91fe-4718bb… ┆ Tech-Trends2024              ┆ Technology Trends in 2024    ┆ A look into the upcoming technology trends expected to dominate in 2024.     │
│ 2bd2a699-b46e-4e6a-8eb6-caca49… ┆ Health-Innovations           ┆ Innovations in Healthcare    ┆ Innovations and breakthroughs in the healthcare industry for better outcomes.│
│ …                               ┆ …                            ┆ …                            ┆ …                                                                            │
│ d235306c-7155-4aa3-aac0-a6b587… ┆ Software-Development         ┆ Software Development Basics  ┆ Basics of software development, including best practices and methodologies.  │
│ 3bed9e07-b793-43ea-839a-37e41b… ┆ Mobile-Apps-Trends           ┆ Trends in Mobile Apps        ┆ Current trends in mobile app development and popular frameworks.             │
│ 1d79c2c7-c649-40be-a0b5-3be159… ┆ Stats-Overview               ┆ Overview of Statistics       ┆ Comprehensive overview of statistics and its importance in data analysis.    │
│ 2c67c0c5-3d8b-44c7-a4b3-a80787… ┆ AI-Applications              ┆ Applications of AI           ┆ Various applications of artificial intelligence across different industries. │
│ 2bee37f3-1f44-4ba5-bbdc-092dd0… ┆ Data-Visualization           ┆ Data Visualization Techniques┆ Techniques and tools for effective data visualization and presentation.      │
└─────────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────────────────────────────────────────────────────┘

View content item's tags

from posit import connect

CONTENT_GUID = "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"

client = connect.Client()

res = client.get(f"/v1/content/{CONTENT_GUID}/tags")
>>> import polars as pl
>>> pl.DataFrame(res.json())
shape: (2, 5)
┌─────┬───────────────────────────┬───────────┬──────────────────────┬──────────────────────┐
│ id  ┆ name                      ┆ parent_id ┆ created_time         ┆ updated_time         │
│ --- ┆ ---                       ┆ ---       ┆ ---                  ┆ ---                  │
│ str ┆ str                       ┆ str       ┆ str                  ┆ str                  │
╞═════╪═══════════════════════════╪═══════════╪══════════════════════╪══════════════════════╡
│ 4   ┆ Software                  ┆ 1         ┆ 2017-04-18T19:54:24Z ┆ 2017-05-19T18:15:39Z │
│ 751 ┆ Artificial Intelligence   ┆ 736       ┆ 2017-04-18T19:54:32Z ┆ 2017-05-03T20:15:27Z │
└─────┴───────────────────────────┴───────────┴──────────────────────┴──────────────────────┘
@schloerke schloerke added the enhancement New feature or request label Nov 25, 2024
@schloerke schloerke self-assigned this Nov 25, 2024
@github-actions github-actions bot added the sdk Used for automation label Nov 25, 2024
@schloerke
Copy link
Collaborator Author

Proposals

# Get all tags

## Return all tags
client.tags.find() -> list[Tag]

## Return all tags with name and parent
client.tags.find(name="tag_name", parent="parent_tag_guid" | parent_tag | None)

# Create Tag
mytag = client.tags.create(
    name="tag_name",
    parent="parent_tag_guid" | parent_tag | None
) -> Tag

# Delete Tag

mytag = client.tags.get("tag_guid")
mytag.destroy() -> None


# Find content using tags
mycontentitems = mytag.content.find() -> list[Content]

# Get content item's tags
mycontentitem: Content = mycontentitems[0]
mycontentitem.tags.find() -> list[Tag]

@schloerke
Copy link
Collaborator Author

Update proposals:

from posit.connect import Client
from posit.connect.tags import Tag
from posit.connect.content import ContentItem

client = Client()

# Get all tags

## Return all tags
tags: list[Tag] = client.tags.find()
some_tag: Tag = tags[0]

## Return all tags with name and parent
commonnametags: list[Tag] = client.tags.find(name="tag_name")
sibling_tags: list[Tag] = client.tags.find(parent="parent_tag_guid")
sibling_tags: list[Tag] = client.tags.find(parent=some_tag)
unique_tag: Tag = client.tags.find(name="tag_name", parent=some_tag)[0]


# Create Tag
mytag: Tag = client.tags.create(name="tag_name")
mytag: Tag = client.tags.create(name="tag_name", parent="parent_tag_guid")
mytag: Tag = client.tags.create(name="tag_name", parent=some_tag)

# Remove Tag
mytag.destroy()


# Content Item

## Find content using tags
mycontentitems: list[ContentItem] = mytag.content_items.find()
some_contentitem: ContentItem = mycontentitems[0]

## Get content item's tags
tags: list[Tag] = some_contentitem.tags.find()

## Add tag to content item
some_contentitem.tags.add(mytag)
## Remove tag from content item
some_contentitem.tags.delete(mytag)



# Family Tree

## Get parent tag
parent_tag: Tag | None = mytag.parent_tag

## Find all children tags
children_tags: list[Tag] = mytag.children_tags.find()

## Find all descendant tags
descendant_tags: list[Tag] = mytag.descendant_tags.find()

## Find all unique content items for a tag and its descendant tags
content_items_list: list[ContentItem] = []
for tag in [mytag, *mytag.descendant_tags.find()]:
    content_items_list.extend(tag.content_items.find())
content_items_list = list(set(content_items_list))

@schloerke
Copy link
Collaborator Author

Final proposal in #346

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sdk Used for automation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant