Accounts and users¶
Use client.identity.me() for the signed-in account. Use
client.identity.users to find collaborators or invite a new account.
Set NOMAD_PAT to a NOMAD Central token. Each example sets up its own
client. For an Oasis, set the
endpoint on your credential.
| Action | Required scope |
|---|---|
| Read your own account | users:read |
| Find collaborators by exact lookup, batch lookup, or prefix | users:read |
| Invite a new user | users:invite |
Read your own account¶
This example reads the account ID and available profile fields.
as_user() converts the returned Account to a local User model.
import os
from nomad_python_api import NomadClient
from nomad_python_api.identity import BearerTokenCredential
credential = BearerTokenCredential(os.environ["NOMAD_PAT"])
with NomadClient(credential=credential) as client:
# Load the profile once and read its local fields below.
me = client.identity.me()
print(me.user_id, me.name or me.username)
profile = me.as_user()
print(profile.affiliation)
See the Account return value for fields and methods.
Find collaborators¶
Replace the example email, username, and prefix with values from
your deployment. An exact lookup
accepts one ID, username, or email. Pass a list of dictionaries to get_many() to
resolve a team in input order. Calling search(prefix=...) gives you
candidates to inspect before choosing a user.
import os
from nomad_python_api import NomadClient
from nomad_python_api.identity import BearerTokenCredential
# Replace these example values with your search inputs.
email = "email1@example.org"
username = "user2"
prefix = "user"
credential = BearerTokenCredential(os.environ["NOMAD_PAT"])
with NomadClient(credential=credential) as client:
users = client.identity.users
# An exact lookup returns one user. Keep the ID for later operations.
collaborator = users.get_by_email(email)
same_user = users.get_by_id(collaborator.user_id)
team = users.get_many([
{"email": email},
{"username": username},
])
# Inspect prefix matches before choosing anyone to add to a group.
candidates = users.search(prefix=prefix)
print(same_user.user_id, [user.user_id for user in team])
print([(user.user_id, user.username) for user in candidates])
The result contains user objects you can reuse in group membership.
NOMAD may omit email from a directory profile, including one found by email.
An exact lookup raises UserNotFoundError for a missing match or
AmbiguousUserError when several records match. A search with no candidates
returns an empty list. Each distinct selector in a batch can make one request.
Invite a user¶
Replace the example email with the intended recipient's address. Pass a
UserInviteOptions object or a dictionary with the same fields.
On success, the example prints the user ID returned by NOMAD.
import os
from nomad_python_api import NomadClient
from nomad_python_api.identity import BearerTokenCredential, UserInviteOptions
# Replace this example address with the intended recipient.
email = "email1@example.org"
credential = BearerTokenCredential(os.environ["NOMAD_PAT"])
invitation = UserInviteOptions(email=email)
# This sends an invitation to the configured address.
with NomadClient(credential=credential) as client:
invited = client.identity.users.invite(invitation)
print(invited.user_id)
Deployment and delivery
NOMAD rejects invitations when the server's Oasis mode is enabled. The account result confirms the API outcome. Email delivery depends on the deployment. Check server state if the request outcome is uncertain.
See the Python reference and the Users REST routes.