Skip to content

Client

airt.client.Client

A class for authenticating and accessing the airt service.

Before you can use the service, you must acquire a username and password for your developer account. Please contact us by email info@airt.ai to get one.

The username, password, and server address can either be passed explicitly while calling the get_token method or stored in environment variables AIRT_SERVICE_USERNAME, AIRT_SERVICE_PASSWORD, and AIRT_SERVER_URL.

Upon successful authentication, the airt services will be available.

delete_data(relative_url) classmethod

Make a DELETE request.

This method will implicitly add the server base URL and the token for every request.

Parameters:

Name Type Description Default
relative_url str

The relative URL of the API endpoint.

required

Returns:

Type Description
Dict[str, Any]

A dictionary that encapsulates the response body.

Exceptions:

Type Description
ConnectionError

If the server is not reachable.

ValueError

If the response code is not in range of 200 - 399.

Source code in airt/client.py
@classmethod
def delete_data(cls, relative_url: str) -> Dict[str, Any]:
    """Make a DELETE request.

    This method will implicitly add the server base URL and the token for every request.

    Args:
        relative_url: The relative URL of the API endpoint.

    Returns:
        A dictionary that encapsulates the response body.

    Raises:
        ConnectionError: If the server is not reachable.
        ValueError: If the response code is not in range of 200 - 399.
    """

    server, auth_token = Client._get_server_url_and_token()

    return delete_data(url=f"{server}{relative_url}", token=auth_token)

get_data(relative_url) classmethod

Make a GET request.

This method will implicitly add the server base URL and the token for every request.

Parameters:

Name Type Description Default
relative_url str

The relative URL of the API endpoint.

required

Returns:

Type Description
Any

A dictionary that encapsulates the response body.

Exceptions:

Type Description
ConnectionError

If the server is not reachable.

ValueError

If the response code is not in range of 200 - 399.

Source code in airt/client.py
@classmethod
def get_data(cls, relative_url: str) -> Any:
    """Make a GET request.

    This method will implicitly add the server base URL and the token for every request.

    Args:
        relative_url: The relative URL of the API endpoint.

    Returns:
        A dictionary that encapsulates the response body.

    Raises:
        ConnectionError: If the server is not reachable.
        ValueError: If the response code is not in range of 200 - 399.
    """

    server, auth_token = Client._get_server_url_and_token()

    return get_data(url=f"{server}{relative_url}", token=auth_token)

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

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

This method calls the AIRT services for validating the supplied username and password. Upon successful authentication, an auth token will be returned and will be implicitly used in all the subsequent interactions with the server.

Parameters:

Name Type Description Default
username str

Username for your developer account. If not set (default value None), it will try to use the value from environment variable AIRT_SERVICE_USERNAME.

None
password str

Password for your developer account. If not set (default value None), it will try to use the value from environment variable AIRT_SERVICE_PASSWORD.

None
server str

Server address used to connect to. If not set (default value None), it will try to use the value from environment variable AIRT_SERVER_URL. If the variable is not set as well, then the default public server will be used. You should leave this to default value unless you are running your own server (please contact us for that possibility by email info@airt.ai).

None

Exceptions:

Type Description
ValueException

If the username/password pair does not match the one for sevice hosted at server.

ConnectionError

If the server address is invalid or not reachable.

KeyError

if username or password are None and there are not 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 method calls the AIRT services for validating the supplied username and password. Upon successful
    authentication, an auth token will be returned and will be implicitly used in all the subsequent interactions with the server.

    Args:
        username: Username for your developer account. If not set (default value **None**), it will try to
            use the value from environment variable **AIRT_SERVICE_USERNAME**.
        password: Password for your developer account. If not set (default value **None**), it will try to
            use the value from environment variable **AIRT_SERVICE_PASSWORD**.
        server: Server address used to connect to. If not set (default value **None**), it will try to
            use the value from environment variable **AIRT_SERVER_URL**. If the variable is not set as well,
            then the default public server will be used. You should leave this to default value unless you
            are running your own server (please contact us for that possibility by email info@airt.ai).

    Raises:
        ValueException: If the username/password pair does not match the one for sevice hosted at server.
        ConnectionError: If the server address is invalid or not reachable.
        KeyError: if username or password are None and there are not 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"]

post_data(relative_url, data) classmethod

Make a POST request.

This method will implicitly add the server base URL and the token for every request.

Parameters:

Name Type Description Default
relative_url str

The relative URL of the server's API endpoint.

required
data Optional[Dict[str, Any]]

A Dictionary object to send in the body of the POST request.

required

Returns:

Type Description
Dict[str, Any]

Response body as a dictionary.

Exceptions:

Type Description
ConnectionError

If the server is not reachable.

ValueError

If the response code is not in range of 200 - 399.

Source code in airt/client.py
@classmethod
def post_data(
    cls, relative_url: str, data: Optional[Dict[str, Any]]
) -> Dict[str, Any]:
    """Make a POST request.

    This method will implicitly add the server base URL and the token for every request.

    Args:
        relative_url: The relative URL of the server's API endpoint.
        data: A Dictionary object to send in the body of the POST request.

    Returns:
        Response body as a dictionary.

    Raises:
        ConnectionError: If the server is not reachable.
        ValueError: If the response code is not in range of 200 - 399.
    """

    server, auth_token = Client._get_server_url_and_token()

    return post_data(
        url=f"{server}{relative_url}",
        data=data,
        token=auth_token,
    )

version() staticmethod

Return the version of airt client and airt service

Returns:

Type Description
Series

A pandas series containing the version of both airt client and airt service

Exceptions:

Type Description
ConnectionError

If the server address is invalid or not reachable.

An example to get the version of airt-client and airt-service:

Client.version()
Source code in airt/client.py
@staticmethod
def version() -> pd.Series:
    """Return the version of airt client and airt service

    Returns:
        A pandas series containing the version of both airt client and airt service

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

    An example to get the version of airt-client and airt-service:

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

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

    version = {
        "airt-client": airt.__version__,
        "airt-service": response["airt_service"],
    }

    return pd.Series(version, name="Version")
Back to top