Skip to content

User

airt.client.User

A class to encapsulate all the user management routes

All the user management routes are only accessable to super users. If a non-super user tried to access the user management routes they will get a permission error.

create(*, username, first_name, last_name, email, password, super_user=False, quota=False) staticmethod

A method to create a new user in airt service

Parameters:

Name Type Description Default
username str

The username for the new user. If the passed username is already available in airt service, then an error message will be diplayed indicating the same.

required
first_name str

The first name for the new user.

required
last_name str

The last name for the new user.

required
email str

The email for the new user. If the passed email is already available in airt service, then an error message will be diplayed indicating the same.

required
password str

The password for the new user.

required
super_user bool

If set to True, then the new user will have super user privilages. If None, then the default value False will be used.

False
quota bool

If set to True, then the user will have access to all the routes. If None, then the default value False will be used and the user will have access only to DataSource routes.

False

Returns:

Type Description
DataFrame

A pandas dataframe with the details of the newly created user

Exceptions:

Type Description
ConnectionError

If the server address is invalid or not reachable.

ValueError

If the username or email is already present in the airt service.

An minimal example for calling the create method:

    new_user = User.create(
        username="example_username",
        first_name="example_first_name",
        last_name="example_last_name",
        email="example@example.com",
        password="example_password",
    )
Source code in airt/client.py
@staticmethod
def create(
    *,
    username: str,
    first_name: str,
    last_name: str,
    email: str,
    password: str,
    super_user: bool = False,
    quota: bool = False,
) -> pd.DataFrame:
    """A method to create a new user in airt service

    Args:
        username: The username for the new user. If the passed username is already available in airt service, then an error message
            will be diplayed indicating the same.
        first_name: The first name for the new user.
        last_name: The last name for the new user.
        email: The email for the new user. If the passed email is already available in airt service, then an error message
            will be diplayed indicating the same.
        password: The password for the new user.
        super_user: If set to **True**, then the new user will have super user privilages. If **None**, then the default value **False** will be used.
        quota: If set to True, then the user will have access to all the routes. If **None**, then the default value **False** will be used and the user
            will have access only to `DataSource` routes.

    Returns:
            A pandas dataframe with the details of the newly created user

    Raises:
        ConnectionError: If the server address is invalid or not reachable.
        ValueError: If the username or email is already present in the airt service.

    An minimal example for calling the `create` method:

    ```python
        new_user = User.create(
            username="example_username",
            first_name="example_first_name",
            last_name="example_last_name",
            email="example@example.com",
            password="example_password",
        )
    ```
    """
    req_data = dict(
        username=username,
        first_name=first_name,
        last_name=last_name,
        email=email,
        quota=quota,
        super_user=super_user,
        password=password,
    )

    response = Client.post_data(relative_url=f"/user/", data=req_data)

    columns = User._get_columns()

    return pd.DataFrame(response, index=[0])[columns]

disable(user_id) staticmethod

Disable a user in airt service.

Parameters:

Name Type Description Default
user_id int

The user id to disabled in airt service.

required

Returns:

Type Description
DataFrame

A pandas dataframe with the details of the disabled user.

Exceptions:

Type Description
ConnectionError

If the server address is invalid or not reachable.

An example to disable a user (id=1) in airt service:

User.disable(user_id=1)
Source code in airt/client.py
@staticmethod
def disable(user_id: int) -> pd.DataFrame:
    """Disable a user in airt service.

    Args:
        user_id: The user id to disabled in airt service.

    Returns:
        A pandas dataframe with the details of the disabled user.

    Raises:
        ConnectionError: If the server address is invalid or not reachable.

    An example to disable a user (id=1) in airt service:

    ```python
    User.disable(user_id=1)
    ```
    """

    response = Client.delete_data(relative_url=f"/user/{user_id}")

    columns = User._get_columns()

    return pd.DataFrame(response, index=[0])[columns]

enable(user_id) staticmethod

Enable a disabled user in airt service.

Parameters:

Name Type Description Default
user_id int

The id of the disabled user in airt service.

required

Returns:

Type Description
DataFrame

A pandas dataframe with the details of the enabled user.

Exceptions:

Type Description
ConnectionError

If the server address is invalid or not reachable.

An example to enable a disabled user (id=1) in airt service:

User.enable(user_id=1)
Source code in airt/client.py
@staticmethod
def enable(user_id: int) -> pd.DataFrame:
    """Enable a disabled user in airt service.

    Args:
        user_id: The id of the disabled user in airt service.

    Returns:
        A pandas dataframe with the details of the enabled user.

    Raises:
        ConnectionError: If the server address is invalid or not reachable.

    An example to enable a disabled user (id=1) in airt service:

    ```python
    User.enable(user_id=1)
    ```
    """

    response = Client.get_data(relative_url=f"/user/{user_id}/enable")

    columns = User._get_columns()

    return pd.DataFrame(response, index=[0])[columns]

ls(offset=0, limit=100, disabled=False) staticmethod

Display the list of available users.

Parameters:

Name Type Description Default
offset int

The number of rows to offset at the beginning of the users list from the server.If None, then the default value 0 will be used.

0
limit int

The maximum number of rows to return from the server. If None, then the default value 100 will be used.

100
disabled bool

If set to True, then both active and disabled users will be displayed. If None, then the default value False will be used which will display only the list of active users.

False

Returns:

Type Description
DataFrame

A pandas dataframe with the list of available users.

Exceptions:

Type Description
ConnectionError

If the server address is invalid or not reachable.

An example to list the available users:

User.ls()
Source code in airt/client.py
@staticmethod
def ls(
    offset: int = 0,
    limit: int = 100,
    disabled: bool = False,
) -> pd.DataFrame:
    """Display the list of available users.

    Args:
        offset: The number of rows to offset at the beginning of the users
            list from the server.If **None**, then the default value **0** will be used.
        limit: The maximum number of rows to return from the server. If **None**,
            then the default value **100** will be used.
        disabled: If set to **True**, then both active and disabled users will be displayed. If **None**,
            then the default value **False** will be used which will display only the list of active users.

    Returns:
        A pandas dataframe with the list of available users.

    Raises:
        ConnectionError: If the server address is invalid or not reachable.

    An example to list the available users:

    ```python
    User.ls()
    ```
    """
    users = Client.get_data(
        relative_url=f"/user/?disabled={disabled}&offset={offset}&limit={limit}"
    )

    columns = User._get_columns()

    return generate_df(users, columns)

update(user_id, username=None, first_name=None, last_name=None, email=None, password=None) staticmethod

Update user details in airt service.

Parameters:

Name Type Description Default
user_id int

The id of the user in airt service.

required
username Optional[str]

New username for the user_id in airt service. If None (default value), then the username won't be updated for the user.

None
first_name Optional[str]

New first_name for the user_id in airt service. If None (default value), then the first_name won't be updated for the user.

None
last_name Optional[str]

New last_name for the user_id in airt service. If None (default value), then the last_name won't be updated for the user.

None
email Optional[str]

New email for the user_id in airt service. If None (default value), then the email won't be updated for the user.

None
password Optional[str]

New password for the user_id in airt service. If None (default value), then the password won't be updated for the user.

None

Returns:

Type Description
DataFrame

A pandas dataframe with the updated user details.

Exceptions:

Type Description
ConnectionError

If the server address is invalid or not reachable.

An example to update the username for a user (id=1) in airt service:

User.update(user_id=1, username="new_username")
Source code in airt/client.py
@staticmethod
def update(
    user_id: int,
    username: Optional[str] = None,
    first_name: Optional[str] = None,
    last_name: Optional[str] = None,
    email: Optional[str] = None,
    password: Optional[str] = None,
) -> pd.DataFrame:
    """Update user details in airt service.

    Args:
        user_id: The id of the user in airt service.
        username: New **username** for the user_id in airt service. If **None** (default value), then the username won't be updated for the user.
        first_name: New **first_name** for the user_id in airt service. If **None** (default value), then the first_name won't be updated for the user.
        last_name: New **last_name** for the user_id in airt service. If **None** (default value), then the last_name won't be updated for the user.
        email: New **email** for the user_id in airt service. If **None** (default value), then the email won't be updated for the user.
        password: New **password** for the user_id in airt service. If **None** (default value), then the password won't be updated for the user.

    Returns:
        A pandas dataframe with the updated user details.

    Raises:
        ConnectionError: If the server address is invalid or not reachable.

    An example to update the username for a user (id=1) in airt service:

    ```python
    User.update(user_id=1, username="new_username")
    ```
    """

    body = dict(
        username=username,
        first_name=first_name,
        last_name=last_name,
        email=email,
        password=password,
    )

    response = Client.post_data(relative_url=f"/user/{user_id}/update", data=body)

    columns = User._get_columns()

    return pd.DataFrame(response, index=[0])[columns]
Back to top