> ## Documentation Index
> Fetch the complete documentation index at: https://docs.law4devs.eu/llms.txt
> Use this file to discover all available pages before exploring further.

# Tags

> List and inspect classification tags with the Law4Devs Python SDK.

## Overview

Tags are predefined classification labels applied to articles and requirements. They enable cross-framework filtering by topic — for example, finding all content related to `"data-breach"` across GDPR, NIS2, and the CRA.

***

## Methods

### `list()`

Returns a page of all tags.

```python theme={null}
page = client.tags.list()

print(f"Total tags: {page.meta.total}")
for tag in page.data:
    print(f"  {tag.slug}: {tag.name}")
```

**Parameters**

| Parameter  | Type  | Default | Description            |
| ---------- | ----- | ------- | ---------------------- |
| `page`     | `int` | `1`     | Page number            |
| `per_page` | `int` | `20`    | Items per page (1–100) |

**Returns** `Page[Tag]`

***

### `get()`

Fetch a single tag by its slug.

```python theme={null}
tag = client.tags.get("data-breach")

print(tag.name)         # "Data Breach"
print(tag.description)  # "Articles relating to personal data breach..."
print(tag.keywords)     # ["breach", "notification", "incident", ...]
print(tag.color)        # "#e74c3c"
```

**Parameters**

| Parameter | Type  | Description                    |
| --------- | ----- | ------------------------------ |
| `slug`    | `str` | Tag slug, e.g. `"data-breach"` |

**Returns** `Tag`

***

### `iter()`

Iterate over all tags.

```python theme={null}
for tag in client.tags.iter():
    print(f"{tag.slug}: {tag.name}")
```

**Returns** `Iterator[Tag]`

***

## Model

### `Tag`

| Field         | Type          | Description                               |
| ------------- | ------------- | ----------------------------------------- |
| `id`          | `int`         | Internal numeric ID                       |
| `slug`        | `str`         | URL-safe identifier, e.g. `"data-breach"` |
| `name`        | `str`         | Human-readable label                      |
| `description` | `str \| None` | What this tag covers                      |
| `keywords`    | `list[str]`   | Keywords used to auto-tag content         |
| `color`       | `str \| None` | Hex color code for UI display             |
| `created_at`  | `str`         | ISO 8601 creation timestamp               |

***

## Examples

### Print all tags with descriptions

```python theme={null}
from law4devs import Law4DevsClient

client = Law4DevsClient()

for tag in client.tags.iter():
    desc = tag.description or "(no description)"
    print(f"{tag.name:25} {desc[:60]}")
```

### Look up a tag's keywords

```python theme={null}
tag = client.tags.get("consent")
print(f"Auto-tag keywords for '{tag.name}':")
for keyword in tag.keywords:
    print(f"  - {keyword}")
```

### Find all articles tagged with a given label

```python theme={null}
target_tag = "security"

matches = [
    article
    for article in client.articles.iter("nis2")
    if target_tag in article.tags
]

print(f"{len(matches)} NIS2 articles tagged '{target_tag}':")
for a in matches:
    print(f"  Art. {a.article_number}: {a.title}")
```

### Build a tag index across all frameworks

```python theme={null}
tag_index = {}  # tag_slug -> list of (framework, article_number)

for fw in client.frameworks.iter():
    for article in client.articles.iter(fw.slug):
        for tag_slug in article.tags:
            tag_index.setdefault(tag_slug, []).append(
                (fw.slug, article.article_number)
            )

# Print most used tags
for slug, refs in sorted(tag_index.items(), key=lambda x: -len(x[1])):
    print(f"{slug}: {len(refs)} articles")
```

<Note>
  Tag slugs are stable — safe to hardcode in application logic or store in databases as foreign keys.
</Note>
