Async User

The async User module provides functionality for working with users.

class AsyncUser(api, user_id, data={})[source]

Bases: AsyncBase

Parameters:
BASE_ENDPOINT: str = 'users/'
__init__(api, user_id, data={})[source]

Initialize a User instance.

Parameters:
  • api (AsyncGeoboxClient) – The GeoboxClient instance for making requests.

  • user_id (int) – the id of the user

  • data (Dict) – The data of the user.

Return type:

None

__repr__()[source]

Return a string representation of the User instance.

Returns:

A string representation of the User instance.

Return type:

str

property role: UserRole

User role property

Returns:

the user role

Return type:

UserRole

property status: UserStatus

User status Property

Returns:

the user status

Return type:

UserStatus

property plan: AsyncPlan

User plan Property

Returns:

the plan object

Return type:

Plan

async classmethod get_users(api, **kwargs)[source]

[async] Retrieves a list of users (Permission Required)

Parameters:

api (AsyncGeoboxClient) – The API instance.

Keyword Arguments:
  • status (UserStatus) – the status of the users filter.

  • q (str) – query filter based on OGC CQL standard. e.g. “field1 LIKE ‘%GIS%’ AND created_at > ‘2021-01-01’”

  • search (str) – search term for keyword-based searching among search_fields or all textual fields if search_fields does not have value. NOTE: if q param is defined this param will be ignored.

  • search_fields (str) – comma separated list of fields for searching.

  • order_by (str) – comma separated list of fields for sorting results [field1 A|D, field2 A|D, …]. e.g. name A, type D. NOTE: “A” denotes ascending order and “D” denotes descending order.

  • return_count (bool) – Whether to return total count. default is False.

  • skip (int) – Number of items to skip. default is 0.

  • limit (int) – Number of items to return. default is 10.

  • user_id (int) – Specific user. privileges required.

  • shared (bool) – Whether to return shared maps. default is False.

Returns:

list of users or the count number.

Return type:

List[AsyncUser] | int

Example

>>> from geobox.aio import AsyncGeoboxClient
>>> from geobox.aio.user import AsyncUser
>>> async with AsyncGeoboxClient() as client:
>>>     users = await AsyncUser.get_users(client)
or
>>>     users = await client.get_users()
async classmethod create_user(api, username, email, password, role, first_name, last_name, mobile, status)[source]

[async] Create a User (Permission Required)

Parameters:
  • api (AsyncGeoboxClient) – The GeoboxClient instance for making requests.

  • username (str) – the username of the user.

  • email (str) – the email of the user.

  • password (str) – the password of the user.

  • role (UserRole) – the role of the user.

  • first_name (str) – the firstname of the user.

  • last_name (str) – the lastname of the user.

  • mobile (str) – the mobile number of the user. e.g. “+98 9120123456”.

  • status (UserStatus) – the status of the user.

Returns:

the user object.

Return type:

AsyncUser

Example

>>> from geobox.aio import AsyncGeoboxClient
>>> from geobox.aio.user import AsyncUser
>>> async with AsyncGeoboxClient() as client:
>>>     user = await AsyncUser.create_user(client,
...                                     username="user1",
...                                     email="user1@example.com",
...                                     password="P@ssw0rd",
...                                     role=UserRole.ACCOUNT_ADMIN,
...                                     first_name="user 1",
...                                     last_name="user 1",
...                                     mobile="+98 9120123456",
...                                     status=UserStatus.ACTIVE)
or
>>>     user = await client.create_user(username="user1",
...                                     email="user1@example.com",
...                                     password="P@ssw0rd",
...                                     role=UserRole.ACCOUNT_ADMIN,
...                                     first_name="user 1",
...                                     last_name="user 1",
...                                     mobile="+98 9120123456",
...                                     status=UserStatus.ACTIVE)
async classmethod search_users(api, search=None, skip=0, limit=10)[source]

[async] Get list of users based on the search term.

Parameters:
  • api (AsyncGeoboxClient) – The AsyncGeoboxClient instance for making requests.

  • search (str, optional) – The Search Term.

  • skip (int, optional) – Number of items to skip. default is 0.

  • limit (int, optional) – Number of items to return. default is 10.

Returns:

A list of User instances.

Return type:

List[AsyncUser]

Example

>>> from geobox.aio import AsyncGeoboxClient
>>> from geobox.aio.user import AsyncUser
>>> async with AsyncGeoboxClient() as client:
>>>     users = await AsyncUser.get_users(client, search="John")
or
>>>     users = await client.get_users(search="John")
async classmethod get_user(api, user_id='me')[source]

[async] Get a user by its id (Permission Required)

Parameters:
  • api (AsyncGeoboxClient) – The AsyncGeoboxClient instance for making requests.

  • user_id (int, optional) – Specific user. don’t specify a user_id to get the current user.

Returns:

the user object.

Return type:

AsyncUser

Raises:

NotFoundError – If the user with the specified id is not found.

Example

>>> from geobox.aio import AsyncGeoboxClient
>>> from geobox.aio.user import AsyncUser
>>> async with AsyncGeoboxClient() as client:
>>>     user = await AsyncUser.get_user(client, user_id=1)
or
>>>     user = await client.get_user(user_id=1)

get the current user >>> user = await AsyncUser.get_user(client) or >>> user = await client.get_user()

async update(**kwargs)[source]

[async] Update the user (Permission Required)

Keyword Arguments:
  • username (str)

  • email (str)

  • first_name (str)

  • last_name (str)

  • mobile (str) – e.g. “+98 9120123456”

  • status (UserStatus)

  • role (UserRole)

  • plan (Plan)

  • expiration_date (str)

Returns:

updated data

Return type:

Dict

Example

>>> from geobox.aio import AsyncGeoboxClient
>>> from geobox.aio.user import AsyncUser
>>> async with AsyncGeoboxClient() as client:
>>>     user = await AsyncUser.get_user(client, user_id=1)
>>>     await user.update(status=UserStatus.PENDING)
async delete()[source]

[async] Delete the user (Permission Required)

Returns:

None

Return type:

None

Example

>>> from geobox.aio import AsyncGeoboxClient
>>> from geobox.aio.user import AsyncUser
>>> async with AsyncGeoboxClient() as client:
>>>     user = await AsyncUser.get_user(client, user_id=1)
>>>     await user.delete()
async get_sessions(user_id='me')[source]

[async] Get a list of user available sessions (Permission Required)

Parameters:

user_id (int, optional) – Specific user. don’t specify user_id to get the current user.

Returns:

list of user sessions.

Return type:

List[AsyncSession]

Example

>>> from geobox.aio import AsyncGeoboxClient
>>> from geobox.aio.user import AsyncUser
>>> async with AsyncGeoboxClient() as client:
>>>     user = await AsyncUser.get_user(client, user_id=1)
or
>>>     user = await client.get_user(user_id=1)
>>>     await user.get_sessions()
or
>>>     await client.get_sessions()
async change_password(new_password)[source]

[async] Change the user password (privileges required)

Parameters:

new_password (str) – new password for the user.

Returns:

None

Return type:

None

Example

>>> from geobox.aio import AsyncGeoboxClient
>>> async with AsyncGeoboxClient() as client:
>>>     user = await client.get_user(user_id=1)
>>>     await user.change_password(new_password='user_new_password')
async renew_plan()[source]

[async] Renew the user plan (privileges required)

Returns:

None

Return type:

None

Example

>>> from geobox.aio import AsyncGeoboxClient
>>> async with AsyncGeoboxClient() as client:
>>>     user = await client.get_user(user_id=1)
>>>     await user.renew_plan()
class AsyncSession(uuid, data, user)[source]

Bases: AsyncBase

Parameters:
__init__(uuid, data, user)[source]

Initialize a user session instance.

Parameters:
  • uuid (str) – The unique identifier for the user session.

  • data (Dict) – The data of the session.

  • user (User) – the user instance.

__repr__()[source]

Return a string representation of the resource.

Returns:

A string representation of the Session object.

Return type:

str

async close()[source]

[async] Close the user session

Returns:

None

Return type:

None

Example

>>> from geobox.aio import AsyncGeoboxClient
>>> from geobox.aio.user import AsyncUser
>>> async with AsyncGeoboxClient() as client:
>>>     user = await AsyncUser.get_user(client) # without user_id parameter, it gets the current user
or
>>>     user = await client.get_user() # without user_id parameter, it gets the current user
>>>     sessions = await user.get_sessions()
>>>     session = session[0]
>>>     await session.close()