User Management
Tutorial
User Management
Create, manage, and deactivate user accounts with role-based access
What You'll Learn
- Create Users - Provision new accounts with role assignment
- List & Filter - Retrieve users and filter by active status
- Update Metadata - Change email, display name, and reactivate accounts
- Role Assignment - Promote and demote between analyst, admin, and ops
- Deactivate Users - Disable departed team members without deletion
1
Setup
Connect to the platform and provision personas
# Cell 1 — ParametersUSERNAME = "_FILL_ME_IN_" # Set your email before running# Cell 2 — Connectfrom graph_olap import GraphOLAPClientclient = GraphOLAPClient(username=USERNAME)
# Cell 3 — Provisionfrom notebook_setup import provisionpersonas, conn = provision(USERNAME)analyst = personas["analyst"]admin = personas["admin"]ops = personas["ops"]
# Carol (admin) manages users in this tutorialcarol = adminprint("Carol (admin) ready for user management")
2
The Role Hierarchy
Three levels of access: analyst, admin, and ops
# The three roles, from least to most privilegedroles = ["analyst", "admin", "ops"]print("Role hierarchy (least \u2192 most privileged):")for i, role in enumerate(roles): print(f" {' ' * i}{role}")print("\nAnalysts: query and analyze graphs")print("Admins: manage users + analyst capabilities")print("Ops: platform configuration + admin capabilities")
3
Creating Users
Provision new accounts with default or explicit roles
from graph_olap.exceptions import ConflictError
# Carol creates Alice (analyst)try: alice = carol.users.create( username="tutorial-alice", display_name="Alice Johnson", role="analyst", ) print("Created Alice:")except ConflictError: alice = carol.users.get("tutorial-alice") print("Alice already exists:")
print(f" username: {alice['username']}")print(f" role: {alice['role']}")print(f" active: {alice['is_active']}")# Carol creates Bob (analyst)try: bob = carol.users.create( username="tutorial-bob", display_name="Bob Smith", role="analyst", ) print("Created Bob:")except ConflictError: bob = carol.users.get("tutorial-bob") print("Bob already exists:")
print(f" username: {bob['username']}")print(f" role: {bob['role']}")
4
Listing and Filtering Users
Retrieve users with optional active-status filtering
# List all usersusers = carol.users.list(limit=10)print(f"Total users: {len(users)}\n")for u in users: status = "active" if u["is_active"] else "inactive" print(f" {u['username']:<35} {u['role']:<10} {status}")# Filter by active statusactive = carol.users.list(is_active=True)print(f"Active users: {len(active)}")
5
Updating User Metadata
Change display name, email, or reactivate accounts
updated = carol.users.update( "tutorial-alice", display_name="Alice J. Johnson",)print(f"Updated Alice:")print(f" display_name: {updated['display_name']}")print(f" email: {updated['email']}")
6
Role Assignment
Promote or demote users between analyst, admin, and ops
# Promote Alice to admintry: promoted = carol.users.assign_role("tutorial-alice", role="admin") print(f"Alice promoted: role={promoted['role']}")except Exception as e: print(f"assign_role: {e}")
# Demote back to analysttry: demoted = carol.users.assign_role("tutorial-alice", role="analyst") print(f"Alice demoted: role={demoted['role']}")except Exception as e: print(f"assign_role: {e}")
7
Deactivating Users
When a team member departs, deactivate rather than delete
try: deactivated = carol.users.deactivate("tutorial-bob") print(f"Deactivated Bob: is_active={deactivated['is_active']}")except Exception as e: print(f"deactivate: {e}")
# Verify Bob appears as inactivebob_check = carol.users.get("tutorial-bob")print(f"Bob status: is_active={bob_check['is_active']}")# Reactivate by updating is_activereactivated = carol.users.update("tutorial-bob", is_active=True)print(f"Reactivated Bob: is_active={reactivated['is_active']}")
8
Bootstrap (First-Time Setup)
One-time provisioning of the first ops user on an empty database
# bootstrap() is a one-time operation for initial platform setup.# It only works when no users exist in the database.## ops.users.bootstrap(# username="platform-admin",# email="[email protected]",# display_name="Platform Admin",# )# Returns: dict with role="ops"print("bootstrap() creates the first ops user during initial setup")print("It only succeeds when the user database is empty")# Clean up tutorial usersfor username in ["tutorial-alice", "tutorial-bob"]: try: carol.users.deactivate(username) except Exception: passprint("Tutorial users cleaned up")Key Takeaways
- Access user management via
client.userswith an admin or ops client create()provisions new accounts with a defaultanalystrolelist()andget()retrieve user data; filter withis_activeassign_role()promotes or demotes betweenanalyst,admin, andopsdeactivate()disables accounts without deleting them -- preferred over deletionbootstrap()is a one-time operation for initial platform provisioning