# Namespaces

> For the complete documentation index, see [llms.txt](https://docs.temporal.io/llms.txt).
> Any documentation page is available as raw Markdown by appending `.md` to its URL.
> For related questions, query https://docs.temporal.io/api/retrieve?q=<question>&jtb=<job-to-be-done>&src=md-page&agent=<your-name> (no auth; returns JSON `{content, source_url, page_url}`, with `source_url` pointing to Markdown for docs pages). Don't include personal data or credentials.

> Register and manage Namespaces in Temporal using CLI or SDK APIs. Isolate Workflow Executions, match development lifecycles, and secure Namespace workflows.

This page shows how to do the following:

- [Register a Namespace](#register-namespace)
- [Manage Namespaces](#manage-namespaces)

You can create, update, deprecate, or delete your [Namespaces](/namespaces) using either the Temporal CLI or SDK APIs.

Use Namespaces to isolate your Workflow Executions according to your needs.
For example, you can use Namespaces to match the development lifecycle by having separate `dev` and `prod` Namespaces.
You could also use them to ensure Workflow Executions between different teams never communicate - such as ensuring that the `teamA` Namespace never impacts the `teamB` Namespace.

On Temporal Cloud, use the [Temporal Cloud UI](/cloud/namespaces#create-a-namespace) to create and manage a Namespace from the UI, or [`temporal cloud namespace` commands](/cli/command-reference/cloud/namespace/) to manage Namespaces from the command line.

On self-hosted Temporal Service, you can register and manage your Namespaces using the Temporal CLI (recommended) or programmatically using APIs.
Note that these APIs and `temporal operator namespace` commands will not work with Temporal Cloud. To manage Namespaces from the command line on Temporal Cloud, use the [Temporal Cloud extension](/cli/cloud).

Use a custom [Authorizer](/self-hosted-guide/security#authorizer-plugin) on your Frontend Service in the Temporal Service to set restrictions on who can create, update, or deprecate Namespaces.

You must register a Namespace with the Temporal Service before setting it in the Temporal Client.

## Register a Namespace 

Registering a Namespace creates a Namespace on the Temporal Service or Temporal Cloud.

On Temporal Cloud, use the [Temporal Cloud UI](/cloud/namespaces#create-a-namespace) or [`temporal cloud namespace` commands](/cli/command-reference/cloud/namespace/) to create Namespaces.

On self-hosted Temporal Service, you can register your Namespaces using the Temporal CLI (recommended) or programmatically using APIs.
Note that these APIs and `temporal operator namespace` commands will not work with Temporal Cloud. To manage Namespaces from the command line on Temporal Cloud, use the [Temporal Cloud extension](/cli/cloud).

Use a custom [Authorizer](/self-hosted-guide/security#authorizer-plugin) on your Frontend Service in the Temporal Service to set restrictions on who can create, update, or deprecate Namespaces.

Use [`Register` API](https://pkg.go.dev/go.temporal.io/sdk/client#NamespaceClient) with the `NamespaceClient` interface to register a [Namespace](/namespaces) and set the [Retention Period](/temporal-service/temporal-server#retention-period) for the Workflow Execution Event History for the Namespace.

You can also [register Namespaces using the Temporal CLI command-line tool](/cli/command-reference/operator#create).

<!--SNIPSTART go-namespace-register-->
[go-sandbox/client/namespaces/namespaces.go](https://github.com/temporalio/documentation-sdk-code-examples/blob/main/go-sandbox/client/namespaces/namespaces.go)
```go
namespaceClient, err := client.NewNamespaceClient(client.Options{HostPort: client.DefaultHostPort})
if err != nil {
	return err
}
defer namespaceClient.Close()

retention := 3 * 24 * time.Hour
err = namespaceClient.Register(ctx, &workflowservice.RegisterNamespaceRequest{
	Namespace:                        namespaceName,
	WorkflowExecutionRetentionPeriod: durationpb.New(retention),
})
```
<!--SNIPEND-->

The Retention Period setting using `WorkflowExecutionRetentionPeriod` is mandatory.
The minimum value you can set for this period is 1 day.

Once registered, set Namespace using `Dial` in a Workflow Client to run your Workflow Executions within that Namespace.
See [how to set Namespace in a Client in Go](/develop/go/client/temporal-client#connect-to-temporal-cloud) for details.

Note that Namespace registration using this API takes up to 10 seconds to complete.
Ensure that you wait for this registration to complete before starting the Workflow Execution against the Namespace.

To update your Namespace, use the [`Update` API](https://pkg.go.dev/go.temporal.io/sdk/client#NamespaceClient) with the `NamespaceClient`.

To update your Namespace using the Temporal CLI, use the [temporal operator namespace update](/cli/command-reference/operator#update) command.

## Manage Namespaces 

You can get details for your Namespaces, update Namespace configuration, and deprecate or delete your Namespaces.

On Temporal Cloud, use the [Temporal Cloud UI](/cloud/namespaces#create-a-namespace) or [`temporal cloud namespace` commands](/cli/command-reference/cloud/namespace/) to manage Namespaces.

On self-hosted Temporal Service, you can manage your registered Namespaces using the Temporal CLI (recommended) or programmatically using APIs.
Note that these APIs and `temporal operator namespace` commands will not work with Temporal Cloud. To manage Namespaces from the command line on Temporal Cloud, use the [Temporal Cloud extension](/cli/cloud).

Use a custom [Authorizer](/self-hosted-guide/security#authorizer-plugin) on your Frontend Service in the Temporal Service to set restrictions on who can create, update, or deprecate Namespaces.

You must register a Namespace with the Temporal Service before setting it in the Temporal Client.

On Temporal Cloud, use the [Temporal Cloud UI](/cloud/namespaces) or [`temporal cloud namespace` commands](/cli/command-reference/cloud/namespace/) to manage Namespaces.

On self-hosted Temporal Service, you can manage your registered Namespaces using the Temporal CLI (recommended) or programmatically using APIs.
Note that these APIs and `temporal operator namespace` commands will not work with Temporal Cloud. To manage Namespaces from the command line on Temporal Cloud, use the [Temporal Cloud extension](/cli/cloud).

- Update information and configuration for a registered Namespace on your Temporal Service:

  - With the Temporal CLI: [`temporal operator namespace update`](/cli/command-reference/operator#update)
    Example
  - Use the [`UpdateNamespace` API](https://pkg.go.dev/go.temporal.io/sdk/client#NamespaceClient) to update configuration on a Namespace.
    Example

    <!--SNIPSTART go-namespace-update-->
    [go-sandbox/client/namespaces/namespaces.go](https://github.com/temporalio/documentation-sdk-code-examples/blob/main/go-sandbox/client/namespaces/namespaces.go)
    ```go
    err := namespaceClient.Update(ctx, &workflowservice.UpdateNamespaceRequest{
    	Namespace: "your-namespace-name",
    	UpdateInfo: &namespacepb.UpdateNamespaceInfo{ // updates info for the namespace "your-namespace-name"
    		Description: "updated namespace description",
    		OwnerEmail:  "newowner@mail.com",
    		// Data:  nil,
    		// State: 0,
    	},
    	/* other details that you can update:
    	Config: &namespacepb.NamespaceConfig{ // updates the configuration of the namespace with the following options
    		// WorkflowExecutionRetentionTtl: nil,
    		// BadBinaries:                   nil,
    		// HistoryArchivalState:          0,
    		// HistoryArchivalUri:            "",
    		// VisibilityArchivalState:       0,
    		// VisibilityArchivalUri:         "",
    	},
    	ReplicationConfig: &replication.NamespaceReplicationConfig{ // updates the replication configuration for the namespace
    		// ActiveClusterName: "",
    		// Clusters:          nil,
    		// State:             0,
    	},
    	SecurityToken:    "",
    	DeleteBadBinary:  "",
    	PromoteNamespace: false,
    	*/
    })
    ```
    <!--SNIPEND-->

- Get details for a registered Namespace on your Temporal Service:

  - With the Temporal CLI: [`temporal operator namespace describe`](/cli/command-reference/operator#describe)
  - Use the [`DescribeNamespace` API](https://pkg.go.dev/go.temporal.io/sdk/client#NamespaceClient) to return information and configuration details for a registered Namespace.
    Example

    <!--SNIPSTART go-namespace-describe-->
    [go-sandbox/client/namespaces/namespaces.go](https://github.com/temporalio/documentation-sdk-code-examples/blob/main/go-sandbox/client/namespaces/namespaces.go)
    ```go
    namespaceClient, err := client.NewNamespaceClient(client.Options{})
    if err != nil {
    	return nil, err
    }
    defer namespaceClient.Close()

    description, err := namespaceClient.Describe(ctx, "default")
    ```
    <!--SNIPEND-->

- Get details for all registered Namespaces on your Temporal Service:

  - With the Temporal CLI: [`temporal operator namespace list`](/cli/command-reference/operator#list)
  - Use the [`ListNamespaces` API](https://github.com/temporalio/api/blob/main/temporal/api/workflowservice/v1/service.proto) on the Workflow Service to return information and configuration details for all registered Namespaces on your Temporal Service.
    Example

  <!--SNIPSTART go-namespace-list-->
  [go-sandbox/client/namespaces/namespaces.go](https://github.com/temporalio/documentation-sdk-code-examples/blob/main/go-sandbox/client/namespaces/namespaces.go)
  ```go
  var names []string
  var nextPageToken []byte
  for {
  	// Each call returns one page of Namespaces. Loop until NextPageToken is empty.
  	resp, err := temporalClient.WorkflowService().ListNamespaces(ctx, &workflowservice.ListNamespacesRequest{
  		PageSize:      100,
  		NextPageToken: nextPageToken,
  	})
  	if err != nil {
  		return nil, err
  	}
  	for _, ns := range resp.GetNamespaces() {
  		names = append(names, ns.GetNamespaceInfo().GetName())
  	}
  	nextPageToken = resp.GetNextPageToken()
  	if len(nextPageToken) == 0 {
  		break
  	}
  }
  ```
  <!--SNIPEND-->

- Delete a Namespace: The [`DeleteNamespace` API](https://github.com/temporalio/api/blob/main/temporal/api/operatorservice/v1/service.proto) deletes a Namespace. Deleting a Namespace deletes all running and completed Workflow Executions on the Namespace, and removes them from the persistence store and the visibility store.
  Example:

  <!--SNIPSTART go-namespace-delete-->
  [go-sandbox/client/namespaces/namespaces.go](https://github.com/temporalio/documentation-sdk-code-examples/blob/main/go-sandbox/client/namespaces/namespaces.go)
  ```go
  _, err := temporalClient.OperatorService().DeleteNamespace(ctx, &operatorservice.DeleteNamespaceRequest{
  	Namespace: namespaceName,
  })
  ```
  <!--SNIPEND-->
