proknow.Users
Users
- class proknow.Users.Users(proknow, requestor)
This class should be used to interact with the users in a ProKnow organization. It is instantiated for you as an attribute of the
proknow.ProKnow.ProKnow
class.- create(email, name, password=None)
Creates a new user.
- Parameters:
email (str) – The email of the user.
name (str) – The name of the user.
password (str, optional) – The password of the user.
- Returns:
A representation of the created item.
- Return type:
- Raises:
AssertionError – If the input parameters are invalid.
proknow.Exceptions.HttpError – If the HTTP request generated an error.
Example
This example creates a new user:
from proknow import ProKnow pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json") pk.users.create("jsmith@example.com", "John Smith")
- delete(user_id)
Deletes a user.
- Parameters:
user_id (str) – The id of the user to delete.
- Raises:
AssertionError – If the input parameters are invalid.
proknow.Exceptions.HttpError – If the HTTP request generated an error.
Example
If you know the user id, you can delete the user directly using this method:
from proknow import ProKnow pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json") pk.users.delete('5c463a6c04005a992cc16b29f9a7637b')
- find(predicate=None, **props)
Finds a user by id, email, or name.
Note
For more information on how to use this method, see Using Find Methods.
- Parameters:
predicate (func) – A function that is passed a user as input and which should return a bool indicating whether the user is a match.
**props – A dictionary of keyword arguments that may include any user attribute. These arguments are considered in turn to find matching users.
- Returns:
A representation of the matching user.
- Return type:
- Raises:
proknow.Exceptions.HttpError – If the HTTP request generated an error.
- get(user_id)
Gets a user.
- Parameters:
user_id (str) – The id of the user to get.
- Returns:
An object representing a user in the organization
- Return type:
- Raises:
proknow.Exceptions.HttpError – If the HTTP request generated an error.
Example
If you know the user id, you can get the user directly using this method:
from proknow import ProKnow pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json") admin = pk.users.get('5c463a6c04005a992cc16b29f9a7637b')
- query()
Queries for users.
- Returns:
A list of
proknow.Users.UserSummary
objects, each representing a summarized user in the organization.- Return type:
list
- Raises:
proknow.Exceptions.HttpError – If the HTTP request generated an error.
Example
This example queries the users and prints the name of each user:
from proknow import ProKnow pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json") for user in pk.users.query(): print(user.name)
UserSummary
- class proknow.Users.UserSummary(users, user)
This class represents a summary view of a user. It’s instantiated by the
proknow.Users.Users.query()
method to represent each of the users returned in a query result.- id
The id of the user (readonly).
- Type:
str
- email
The email of the user (readonly).
- Type:
str
- name
The name of the user (readonly).
- Type:
str
- data
The summary representation of the user as returned from the API (readonly).
- Type:
dict
- get()
Gets the complete representation of the user.
- Returns:
An object representing a user in the organization
- Return type:
- Raises:
proknow.Exceptions.HttpError – If the HTTP request generated an error.
Example
The following example shows how to turn a list of UserSummary objects into a list of UserItem objects:
from proknow import ProKnow pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json") users = [user.get() for user in pk.users.query()]
UserItem
- class proknow.Users.UserItem(users, user)
This class represents a user. It’s instantiated by the
proknow.Users.Users
class as a complete representation of a user.- id
The id of the user (readonly).
- Type:
str
- data
The complete representation of the user as returned from the API (readonly).
- Type:
dict
- name
The name of the user.
- Type:
str
- email
The email of the user.
- Type:
str
- active
Indicates whether the user is active.
- Type:
bool
- delete()
Deletes the user.
- Raises:
proknow.Exceptions.HttpError – If the HTTP request generated an error.
Example
The following example shows how to find a user by its email and delete it:
from proknow import ProKnow pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json") jsmith = pk.users.find(email='jsmith@example.com') jsmith.delete()
- save()
Saves the changes made to a user.
- Raises:
proknow.Exceptions.HttpError – If the HTTP request generated an error.
Example
The following example shows how to find a user by its email, set it to inactive, and save it:
from proknow import ProKnow pk = ProKnow('https://example.proknow.com', credentials_file="./credentials.json") jsmith = pk.users.find(email='jsmith@example.com') jsmith.active = False jsmith.save()