# Bulk User and User Attribute management

**URL:** <https://community.omni.co/t/bulk-user-and-user-attribute-management/253>\
**Category:** Administration\
**Created:** [March 3, 2025, 11:49pm UTC](https://community.omni.co/t/bulk-user-and-user-attribute-management/253 "2025-03-03T23:49:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![russ](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.omni.co/russ/32/296_2.png) [@russ](https://community.omni.co/u/russ)\
**Post date:** [March 3, 2025, 11:49pm UTC](https://community.omni.co/t/bulk-user-and-user-attribute-management/253/1 "2025-03-03T23:49:45Z")

</div>

The best approach to managing users and their attributes is to derive them from an SSO system, and Omni supports many systems through its SAML and SCIM such as [Okta](https://docs.omni.co/docs/administration/saml/okta), [Active Directory](https://docs.omni.co/docs/administration/saml/active-directory) and more.  
But sometimes you have a need to bulk create users in a pinch, update user attributes, or even occasionally delete if needed.

The [Python SDK](https://github.com/exploreomni/omni-python-sdk) now supports the api endpoints to make bulk admin a piece of cake 🎂 .

You can see the script for performing these updates [here](https://github.com/exploreomni/omni-python-sdk/tree/main/examples/user_management). But we’ll walk through the setup step by step.

First, install the python SDK. You may want to create a virtual environment first.

#### Optional Step 0 - Create a virtual environment

Starting in a folder you’d like the script to live in. [Double check you have at least python 3.9+](https://www.naukri.com/code360/library/how-to-check-python-version-in-cmd)

```bash
python -m venv ./.venv

```

Activate the virtual environment:

```bash
source ./.venv/bin/activate

```

[windows instructions](https://www.geeksforgeeks.org/creating-python-virtual-environment-windows-linux/)

#### Step 1 - Pip install the sdk

```bash
pip install omni_python_sdk

```

#### Step 2 - Create the script and fill out API key and Omni Host

```python
from omni_python_sdk import OmniAPI
import csv, time

api_key = '<<your api key>>'
base_url = 'https://<<your omni host>>'

# Initialize the API with your credentials
api = OmniAPI(api_key, base_url)

with open('users.csv', newline='') as csvfile:
    spamreader = csv.DictReader(csvfile)
    for row in spamreader:
        time.sleep(2)
        email = row.pop('email')
        displayName = row.pop('display_name')
        op = row.pop('op')
        if op == 'upsert':
            r1 = api.upsert_user(
                email=email,
                displayName=displayName,
                attributes=row
            )
        elif op == 'delete':
            api.delete_user(email)

```

#### Step 3 - Set up your CSV

 ![Screenshot 2025-03-03 at 3.38.51 PM](https://canada1.discourse-cdn.com/flex004/uploads/omni/original/1X/cc71dee6543d9e6b98a197d951bdc18ec77924ca.png)

- The `op` column should either be upsert, which will create a user if they do not exist, and will refresh their user attributes if they do. Delete will delete the user. Records are identified by email
- The column names after display\_name should be exactly the user attribute’s reference, which you can find in Omni in settings \> attributes
- multi-value user attributes should be enclosed in `[...]` square brackets, if not they will fail.

#### Step 4 – Run it

```bash
python <<name of your script>>.py

```

It will pause 2 seconds in between each update to ensure it doesn’t hit the API throttle, and will provide little messages after each operation.

 ![image](https://canada1.discourse-cdn.com/flex004/uploads/omni/original/1X/6beb75bc1cf478146a41249e5de6b1090139fe7c.png)

That’s it! You may want to schedule it, or run periodically. The upsert is idempotent.
