Skip to content

Tags

You can start using the Tags entity by running the following import statement:

from everysk.sdk.entities.tags import Tags

Below we have the most common attributes used in the Tags entity:

min_size: The minimum size of each individual tag. Default is 1.

max_size: The maximum size of each individual tag. Default is 252.

Creating a Tag instance

For creating a new Tag instance and starting using, we can use the following piece of code:

tags = Tags()
tags
# []

Min Size

The min_size attribute is used to set the minimum size of each individual tag. By default, the minimum size is 1. If we want to change it, we can do it as follows:

tags.min_size = 2
tags.min_size
# 2

Let's try to add a tag with less than 2 characters:

tags.append('a')
# FieldValueError: Tags: "a" size it's not between 2 and 252

Max Size

The max_size attribute is used to set the maximum size of each individual tag. By default, the maximum size is 252. If we want to change it, we can do it as follows:

tags.max_size = 5
tags.max_size
# 5

Let's try to add a tag with more than 5 characters:

tags.append('abcdef')
# FieldValueError: Tags: "abcdef" size it's not between 2 and 5

Now, let's understand below the append() method along with a few other methods that can be used to manipulate the tags.

Adding new tags

The append() method is used in order to add new tags to our tag instance:

tags = Tags()
tags.append('tag1')
tags
# ['tag1']

tags.append('tag2')
tags
# ['tag1', 'tag2']

Keep in mind that the append() method only accepts a single tag as an argument, which can be a string, integer, or float. If you want to add multiple tags at once, you can use the extend() method.

Extending tags

There is also the possibility of adding multiple tags at once on a list format by using the extend method:

tags = Tags()
tags.extend(['tag1', 'tag2', 'tag3'])
tags
# ['tag1', 'tag2', 'tag3']

Inserting a tag at some index

To add a specific tag at a certain index, we can make use of the insert method:

Lets continue with our previous tag instance, now let's say that we want to add a new tag at the beginning of our tags list:

tags.insert(0, 'tag0')
tags
# ['tag0', 'tag1', 'tag2', 'tag3']

Unifying Tags

The unify() static method merges two tag sources — typically an overwrite value and an existing entity's tags — into a single Tags instance. If the overwrite is provided it takes precedence; otherwise the existing tags are kept:

existing_tags = Tags(['equity', 'risk'])
overwrite_tags = Tags(['bond'])

Tags.unify(overwrite_tags, existing_tags)
# Tags(['bond'])

# When overwrite is empty, existing tags are preserved
Tags.unify(Tags(), existing_tags)
# Tags(['equity', 'risk'])

This is the standard pattern used by modifier workers when applying partial updates to an entity's tags.