Skip to content

Client

airt.client.Client

A class for authenticating and accessing the airt service.

To access the airt service, you must create a developer account. Please contact us by email info@airt.ai to get one.

Upon successful verification, you will receive the username/password for the developer account in an email.

Finally, you need an application token to access all the APIs in airt service. Please call the get_token method with the username/password to get one. You can either pass the username, password, and server address as parameters to the get_token method or store the same in the AIRT_SERVICE_USERNAME, AIRT_SERVICE_PASSWORD, and AIRT_SERVER_URL environment variables.

Upon successful authentication, the airt services will be available to access.

get_token(*, username=None, password=None, server=None) classmethod

Get application token for airt service from a username/password pair.

This methods validates the developer credentials and returns an auth token. The returned auth token is implicitly used in all the interactions with the server.

Parameters:

Name Type Description Default
username str

Username for the developer account. If None (default value), then the value from AIRT_SERVICE_USERNAME environment variable is used.

None
password str

Password for the developer account. If None (default value), then the value from AIRT_SERVICE_PASSWORD environment variable is used.

None
server str

The airt server uri. If None (default value), then the value from AIRT_SERVER_URL environment variable is used. If the variable is not set as well, then the default public server will be used. Please leave this setting to default unless you are running the service in your own server (please email us to info@airt.ai for that possibility).

None

Exceptions:

Type Description
ValueException

If the username/password pair does not match.

ConnectionError

If the server address is invalid or not reachable.

KeyError

If username/password is neither passed as parameters nor stored in environment variables.

Source code in airt/client.py
@classmethod
def get_token(
    cls, *, username: str = None, password: str = None, server: str = None
):
    """Get application token for airt service from a username/password pair.

    This methods validates the developer credentials and returns an auth token. The returned auth
    token is implicitly used in all the interactions with the server.



    Args:
        username: Username for the developer account. If None (default value), then the value from
            **AIRT_SERVICE_USERNAME** environment variable is used.
        password: Password for the developer account. If None (default value), then the value from
            **AIRT_SERVICE_PASSWORD** environment variable is used.
        server: The airt server uri. If None (default value), then the value from **AIRT_SERVER_URL** environment variable
            is used. If the variable is not set as well, then the default public server will be used. Please leave this
            setting to default unless you are running the service in your own server (please email us to info@airt.ai
            for that possibility).

    Raises:
        ValueException: If the username/password pair does not match.
        ConnectionError: If the server address is invalid or not reachable.
        KeyError: If username/password is neither passed as parameters nor stored in environment variables.

    """
    cls.server = get_base_url(server)

    username, password = _get_credentials(username, password)

    response = post_data(
        url=f"{cls.server}/token",
        data=dict(username=username, password=password),
        token=None,
    )

    cls.auth_token = response["access_token"]

set_token(token=None, server=None) classmethod

Set application token for airt service.

The token set using this method will be implicitly used in all the interactions with the server.

Please call this method only if you already have a token. Else call the get_token method to generate one.

Parameters:

Name Type Description Default
token str

The application token generated from a username/password pair. If None (default value), then the value from AIRT_SERVICE_TOKEN environment variable is used.

None
server str

The airt server uri. If None (default value), then the value from AIRT_SERVER_URL environment variable is used. If the variable is not set as well, then the default public server will be used. Please leave this setting to default unless you are running the service in your own server (please email us to info@airt.ai for that possibility).

None

An example to set the token:

Client.set_token()
Source code in airt/client.py
@classmethod
def set_token(cls, token: str = None, server: str = None):
    """Set application token for airt service.

    The token set using this method will be implicitly used in all the interactions with the server.

    Please call this method only if you already have a token. Else call the `get_token` method to generate one.

    Args:
        token: The application token generated from a username/password pair. If None (default value), then the value from
            **AIRT_SERVICE_TOKEN** environment variable is used.
        server: The airt server uri. If None (default value), then the value from **AIRT_SERVER_URL** environment variable
            is used. If the variable is not set as well, then the default public server will be used. Please leave this
            setting to default unless you are running the service in your own server (please email us to info@airt.ai
            for that possibility).

    An example to set the token:

    ```python
    Client.set_token()
    ```
    """

    auth_token = token if token is not None else os.environ.get(SERVICE_TOKEN)

    if not auth_token:
        raise KeyError(
            f"The token is neither passed as parameter nor set in the environment variable {SERVICE_TOKEN}."
        )

    cls.auth_token = auth_token
    cls.server = get_base_url(server)

version() staticmethod

Return the client and server versions.

Returns:

Type Description
dict

A dict containing the client and server versions.

Exceptions:

Type Description
ConnectionError

If the server address is invalid or not reachable.

An example to get the client and server versions:

Client.version()
Source code in airt/client.py
@staticmethod
def version() -> dict:
    """Return the client and server versions.

    Returns:
        A dict containing the client and server versions.

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

    An example to get the client and server versions:

    ```python
    Client.version()
    ```
    """

    response = Client._get_data(relative_url=f"/version")

    version = {
        "client": importlib.import_module(CLIENT_NAME).__version__,
        "server": response["airt_service"],
    }

    return version
Back to top