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

# Create a Namespace and a Tag

> Learn how to create a namespace and a tag with mutations using the Validio SDK.

## Overview

Create a namespace to hold resources, and a tag to label them, by using mutations and variables.

The API key that runs the script needs the global `namespaces:WRITE` permission. It becomes an Admin of the namespace it creates, so the same script can go on to create credentials and sources in it.

Both mutations return an `errors` list. Check it before using the result, because a failed create returns errors instead of raising an exception.

## Steps

**1. Create a namespace**

`NamespaceCreateInput` requires both an `id` and a `name`. The `id` is the namespace identifier that other resources refer to, such as the `namespaceId` of a credential, and it can't be changed later. Use lowercase letters, numbers, hyphens, and underscores, which is the format the Validio UI generates from the namespace name. To give other users, teams, or API keys access, add `members`, `teams`, or `apiKeys` to the input, each with an ID and the role ID to assign. List namespace roles and their IDs with the `roleConfigs` query, filtered to `type: Namespace`. If you list the API key that runs the script, it gets that role instead of Admin. For more information, see [Managing Namespaces](https://docs.validio.io/docs/access-and-settings/settings/managing-namespaces.md).

**2. Create a tag**

`TagCreateInput` uses `key` and `value`. For a key and value tag, set both, as in this example. For a label tag, set `key` to `label` and `value` to the label text. To apply the tag, pass its ID in `tagIds` when you create or update a resource, such as a source. For more information, see [Managing Tags](https://docs.validio.io/docs/access-and-settings/settings/managing-tags.md).

## Full code sample

```python title="Python" theme={null}
from validio_sdk.client import Client


async def example():
    client = Client()
    namespace_id = await create_namespace(client)
    tag_id = await create_tag(client)

    print(f"Created namespace {namespace_id} and tag {tag_id}")


async def create_namespace(client: Client) -> str:
    query = """
    mutation NamespaceCreate($input: NamespaceCreateInput!) {
      namespaceCreate(input: $input) {
        errors {
          code
          message
        }
        namespace {
          id
        }
      }
    }
    """
    variable_values = {
        "input": {
            "id": "data-platform",
            "name": "Data Platform",
            "description": "Sources owned by the data platform team",
        }
    }
    result = await client.execute(query, variable_values=variable_values)

    if result["namespaceCreate"]["errors"]:
        raise RuntimeError(result["namespaceCreate"]["errors"])

    return result["namespaceCreate"]["namespace"]["id"]


async def create_tag(client: Client) -> str:
    query = """
    mutation TagCreate($input: TagCreateInput!) {
      tagCreate(input: $input) {
        errors {
          code
          message
        }
        tag {
          id
        }
      }
    }
    """
    variable_values = {
        "input": {
            "key": "team",
            "value": "data-platform",
        }
    }
    result = await client.execute(query, variable_values=variable_values)

    if result["tagCreate"]["errors"]:
        raise RuntimeError(result["tagCreate"]["errors"])

    return result["tagCreate"]["tag"]["id"]
```
