hdx.data.user
module hdx.data.user
User class containing all logic for creating, checking, and updating users.
Classes
-
User — User class containing all logic for creating, checking, and updating users.
class User(initial_data: dict | None = None, configuration: Configuration | None = None)
Bases : HDXObject
User class containing all logic for creating, checking, and updating users.
Parameters
-
initial_data : dict | None — Initial user metadata dictionary. Defaults to None.
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
Methods
-
actions — Dictionary of actions that can be performed on object
-
update_from_yaml — Update user metadata with static metadata from YAML file
-
update_from_json — Update user metadata with static metadata from JSON file
-
read_from_hdx — Reads the user given by identifier from HDX and returns User object
-
check_required_fields — Check that metadata for user is complete. The parameter ignore_fields should be set if required to any fields that should be ignored for the particular operation.
-
update_in_hdx — Check if user exists in HDX and if so, update user
-
create_in_hdx — Check if user exists in HDX and if so, update it, otherwise create user
-
delete_from_hdx — Deletes a user from HDX.
-
email — Emails a user.
-
get_current_user — Get current user (based on authorisation from API token)
-
get_all_users — Get all users in HDX
-
email_users — Email a list of users
-
get_organization_dicts — Get organization dictionaries (not organization objects) in HDX that this user is a member of.
-
get_organizations — Get organizations in HDX that this user is a member of.
-
check_organization_access — Check user is a member of a given organization.
-
get_current_user_organization_dicts — Get organization dictionaries (not Organization objects) in HDX that the logged in user is a member of.
-
get_current_user_organizations — Get organizations in HDX that the logged in user is a member of.
-
check_current_user_organization_access — Check logged in user is a member of a given organization.
-
check_current_user_write_access — Check logged in user has write access to a given organization. Raises PermissionError if the user does not have access otherwise logs and returns the current username.
-
get_token_list — Get API tokens for user.
-
autocomplete — Autocomplete a user name and return matches
staticmethod User.actions() → dict[str, str]
Dictionary of actions that can be performed on object
Returns
-
dict[str, str] — Dictionary of actions that can be performed on object
method User.update_from_yaml(path: Path | str = Path('config', 'hdx_user_static.yaml')) → None
Update user metadata with static metadata from YAML file
Parameters
-
path : Path | str — Path to YAML dataset metadata. Defaults to config/hdx_user_static.yaml.
Returns
-
None — None
method User.update_from_json(path: Path | str = Path('config', 'hdx_user_static.json')) → None
Update user metadata with static metadata from JSON file
Parameters
-
path : Path | str — Path to JSON dataset metadata. Defaults to config/hdx_user_static.json.
Returns
-
None — None
classmethod User.read_from_hdx(identifier: str, configuration: Configuration | None = None) → Optional['User']
Reads the user given by identifier from HDX and returns User object
Parameters
-
identifier : str — Identifier of user
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
Returns
-
Optional['User'] — User object if successful read, None if not
method User.check_required_fields(ignore_fields: Sequence[str] = ()) → None
Check that metadata for user is complete. The parameter ignore_fields should be set if required to any fields that should be ignored for the particular operation.
Parameters
-
ignore_fields : Sequence[str] — Fields to ignore. Default is ().
Returns
-
None — None
method User.update_in_hdx(**kwargs: Any) → None
Check if user exists in HDX and if so, update user
Returns
-
None — None
method User.create_in_hdx(**kwargs: Any) → None
Check if user exists in HDX and if so, update it, otherwise create user
Returns
-
None — None
method User.delete_from_hdx() → None
Deletes a user from HDX.
Returns
-
None — None
method User.email(subject: str, text_body: str, html_body: str | None = None, sender: str | None = None, **kwargs: Any) → None
Emails a user.
Parameters
-
subject : str — Email subject
-
text_body : str — Plain text email body
-
html_body : str | None — HTML email body
-
sender : str | None — Email sender. Defaults to SMTP username.
-
**kwargs : Any — See below
-
mail_options : List — Mail options (see smtplib documentation)
-
rcpt_options : List — Recipient options (see smtplib documentation)
Returns
-
None — None
staticmethod User.get_current_user(configuration: Configuration | None = None) → User
Get current user (based on authorisation from API token)
Parameters
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
Returns
-
User — Current user
staticmethod User.get_all_users(configuration: Configuration | None = None, **kwargs: Any) → list['User']
Get all users in HDX
Parameters
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
-
**kwargs : Any — See below
-
q : str — Restrict to names containing a string. Defaults to all users.
-
order_by : str — Field by which to sort - any user field or edits (number_of_edits). Defaults to 'name'.
Returns
-
list['User'] — List of all users in HDX
staticmethod User.email_users(users: Sequence['User'], subject: str, text_body: str, html_body: str | None = None, sender: str | None = None, cc: Sequence['User'] | None = None, bcc: Sequence['User'] | None = None, configuration: Configuration | None = None, **kwargs: Any) → None
Email a list of users
Parameters
-
users : Sequence['User'] — List of users in To address
-
subject : str — Email subject
-
text_body : str — Plain text email body
-
html_body : str | None — HTML email body
-
sender : str | None — Email sender. Defaults to SMTP username.
-
cc (Optional[Sequence[User]] — List of users to cc. Defaults to None.
-
bcc (Optional[Sequence[User]] — List of users to bcc. Defaults to None.
-
configuration : Configuration | None — HDX configuration. Defaults to configuration of first user in list.
-
**kwargs : Any — See below
-
mail_options : List — Mail options (see smtplib documentation)
-
rcpt_options : List — Recipient options (see smtplib documentation)
Returns
-
None — None
Raises
-
ValueError
method User.get_organization_dicts(permission: str = 'read') → list[dict]
Get organization dictionaries (not organization objects) in HDX that this user is a member of.
Parameters
-
permission : str — Permission to check for. Defaults to 'read'.
Returns
-
list[dict] — List of organization dicts in HDX that this user is a member of
method User.get_organizations(permission: str = 'read') → list['Organization']
Get organizations in HDX that this user is a member of.
Parameters
-
permission : str — Permission to check for. Defaults to 'read'.
Returns
-
list['Organization'] — List of organizations in HDX that this user is a member of
method User.check_organization_access(organization: str, permission: str = 'read') → bool
Check user is a member of a given organization.
Parameters
-
organization : str — Organization id or name.
-
permission : str — Permission to check for. Defaults to 'read'.
Returns
-
bool — True if the logged in user is a member of the organization.
classmethod User.get_current_user_organization_dicts(permission: str = 'read', configuration: Configuration | None = None) → list['Organization']
Get organization dictionaries (not Organization objects) in HDX that the logged in user is a member of.
Parameters
-
permission : str — Permission to check for. Defaults to 'read'.
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
Returns
-
list['Organization'] — List of organization dicts in HDX that logged in user is a member of
classmethod User.get_current_user_organizations(permission: str = 'read', configuration: Configuration | None = None) → list['Organization']
Get organizations in HDX that the logged in user is a member of.
Parameters
-
permission : str — Permission to check for. Defaults to 'read'.
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
Returns
-
list['Organization'] — List of organizations in HDX that logged in user is a member of
classmethod User.check_current_user_organization_access(organization: str, permission: str = 'read', configuration: Configuration | None = None) → bool
Check logged in user is a member of a given organization.
Parameters
-
organization : str — Organization id or name.
-
permission : str — Permission to check for. Defaults to 'read'.
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
Returns
-
bool — True if the logged in user is a member of the organization.
classmethod User.check_current_user_write_access(organization: str, permission: str = 'create_dataset', configuration: Configuration | None = None) → User
Check logged in user has write access to a given organization. Raises PermissionError if the user does not have access otherwise logs and returns the current username.
Parameters
-
organization : str — Organization id or name.
-
permission : str — Permission to check for. Defaults to 'create_dataset'.
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
Returns
-
User — Username of current user
Raises
-
PermissionError
method User.get_token_list()
Get API tokens for user.
Returns
-
List of API token details
classmethod User.autocomplete(name: str, limit: int = 20, configuration: Configuration | None = None) → list
Autocomplete a user name and return matches
Parameters
-
name : str — Name to autocomplete
-
limit : int — Maximum number of matches to return
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
Returns
-
list — Autocomplete matches