
## Creating users and groups

URL: https://docs.atlan.com/product/capabilities/build-apps/sdks/python/users-groups/how-tos/create-users-groups

> Create users and groups in Atlan programmatically using the Python SDK (pyatlan) or Java SDK. Use AtlanUser and AtlanGroup to invite users, create groups, and manage group membership via the SDK.

# AtlanUser: create users and groups

Use `AtlanUser` and `AtlanGroup` in the Atlan Python SDK to programmatically create and invite users and groups in your Atlan environment.

Like other objects in the SDK, you can create users and groups using the builder pattern.

## Create group

For example, to create a group:

### Java

```java showLineNumbers title="Create a group"
AtlanGroup group = AtlanGroup.creator("Example Group") // (1)
 .build(); // (2)
String guid = group.create(client); // (3)
```

1. When creating a group, you must specify at least its name.
2. Like other builder patterns, you build the object to make it ready for creation.
3. To actually create the group in Atlan, call the `create()` method on the built object. Note that it will return the GUID of the group that was created when successful. Because this operation will persist the group in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

### Python

```python showLineNumbers title="Create a group"
from pyatlan.model.group import AtlanGroup
from pyatlan.client.atlan import AtlanClient

client = AtlanClient()
group = AtlanGroup.create(alias="Example Group") # (1)
guid = client.group.create(group).group # (2)
```

1. When creating a group, you must specify at least its name.
2. To actually create the group in Atlan, call the `group.create()` method with the built object. Note that it will return a minimal object that includes the GUID of the group that was created in the `group` property.

### Kotlin

```kotlin showLineNumbers title="Create a group"
val group = AtlanGroup.creator("Example Group") // (1)
 .build() // (2)
val guid = group.create(client) // (3)
```

1. When creating a group, you must specify at least its name.
2. Like other builder patterns, you build the object to make it ready for creation.
3. To actually create the group in Atlan, call the `create()` method on the built object. Note that it will return the GUID of the group that was created when successful. Because this operation will persist the group in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

### Go

```go showLineNumbers title="Create a group"
atlanGroup := assets.AtlanGroup{}
group, _ := atlanGroup.Create("Example Group") // (1)
response, atlanErr := ctx.GroupClient.Create(group, nil) // (2)
```

1. When creating a group, you must specify at least its name.
2. To actually create the group in Atlan, call the `GroupClient.Create()` method with the built object. Note that it will return a minimal object that includes the GUID of the group that was created in the `group` property.

### Raw REST API

```json showLineNumbers title="POST /api/service/groups"
{
 "group": { // (1)
 "attributes": { // (2)
 "alias": [ // (3)
 "Example Group"
 ],
 "isDefault": [ // (4)
 "false"
 ]
 },
 "name": "example_group" // (5)
 }
}
```

1. All the details for the group must be wrapped in a `group` object.
2. The details of the group are further nested within an `attributes` object.
3. Provide an alias for the group, which will be the name that appears in the UI. Note that it must be specified as an array, even though there is only a single value.
4. Specify whether the group should be applied to all new users (true) or not (false). Note that this must be specified as a string within an array.
5. Provide an internal name for the group.

 :::warning[Must follow certain constraints]
The internal name for the group must be unique, all lowercase, and include only alphanumeric characters and the `_` (no spaces or special characters).
 :::

## Create user

To create a user, what you're really doing is inviting them. The users will need to verify their email address to activate their account, and will be able to specify their own password as part of that process.

To invite a user:

### Java

```java showLineNumbers title="Invite a user"
AtlanUser user = AtlanUser.creator(
 "someone@somewhere.org", // (1)
 "$member") // (2)
 .build(); // (3)
user.create(client); // (4)
```

1. When inviting a user, you must specify at least their email address...
2. ...and the workspace role you want to give that user (one of `$guest`, `$member`, or `$admin`).
3. Like other builder patterns, you build the object to make it ready for creation.
4. To actually invite the user to Atlan, call the `create()` method on the built object. Note that this doesn't return any information. Because this operation will persist the user in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

### Python

```python showLineNumbers title="Invite a user"
from pyatlan.model.user import AtlanUser
from pyatlan.client.atlan import AtlanClient

client = AtlanClient()
users = [
 AtlanUser.create(
 email="someone@somewhere.org", # (1)
 role_name="$member" # (2)
 )
]
client.user.create(users, return_info=False) # (3)
```

1. When inviting a user, you must specify at least their email address...
2. ...and the workspace role you want to give that user (one of `$guest`, `$member`, or `$admin`).
3. To invite the user to Atlan, simply call the `user.create()` method with the built object.
Note that if `return_info` is set to `True`, this will return a list
containing details of the created users; otherwise, it will return `None`.

### Kotlin

```kotlin showLineNumbers title="Invite a user"
val user = AtlanUser.creator(
 "someone@somewhere.org", // (1)
 "\$member") // (2)
 .build() // (3)
user.create(client) // (4)
```

1. When inviting a user, you must specify at least their email address...
2. ...and the workspace role you want to give that user (one of `\$guest`, `\$member`, or `\$admin`).
3. Like other builder patterns, you build the object to make it ready for creation.
4. To actually invite the user to Atlan, call the `create()` method on the built object. Note that this doesn't return any information. Because this operation will persist the user in Atlan, you must [provide it an `AtlanClient`](https://docs.atlan.com/llms/platform/python/set-up-sdk/llms.txt) through which to connect to the tenant.

### Go

```go showLineNumbers title="Invite a user"
users := []assets.AtlanUser{
 {
 Email: "someone@somewhere.org", // (1)
 WorkspaceRole: "$member", // (2)
 },
}
ctx.UserClient.CreateUsers(users, false) // (3)
```

1. When inviting a user, you must specify at least their email address...
2. ...and the workspace role you want to give that user (one of `$guest`, `$member`, or `$admin`).
3. To invite the user to Atlan, simply call the `UserClient.CreateUsers()` method with the built object.
Note that if `returnInfo` is set to `True`, this will return a list
containing details of the created users; otherwise, it will return `None`.

### Raw REST API

```json showLineNumbers title="POST /api/service/users"
{
 "users": [ // (1)
 ]
}
```

1. All user details must be wrapped in a `users` array, where each object in the array defines a single user.
2. You must provide a valid email address for each user. Atlan will send an invitation to this email address.
3. You must specify the role for the user, one of: `$admin`, `$member`, or `$guest`.
4. You must also provide the unique ID (GUID) of the role.

 :::warning[You probably need to look this up first]
When using the raw API, you will need to lookup the role GUID yourself. You can `GET /api/service/roles`, and the GUID will be the `id` field in the response for each role.
 :::

---
