Skip to content

Client

Bases: BaseModel

SkahaClient is the base class for all other API clients.

Parameters:

Name Type Description Default
server str

Server URL.

required
version str

Skaha API version.

required
certificate str

Certificate file.

required
timeout int

Timeout for requests.

required

Raises:

Type Description
InvalidServerURL

If the server URL is invalid.

InvalidCertificateError

If the client is given an invalid certificate.

Examples:

Python Console Session
>>> from skaha.client import SkahaClient
    class MyClient(SkahaClient):
        pass

assign_cert_values

Python
assign_cert_values(values: Dict[str, Any])

Check the certificate.

Source code in /home/runner/.cache/pypoetry/virtualenvs/handbook-G9X_rrhO-py3.10/lib/python3.10/site-packages/skaha/client.py
Python
@root_validator(skip_on_failure=True)
def assign_cert_values(cls, values: Dict[str, Any]):
    """Check the certificate."""
    values["session"].headers.update({"X-Skaha-Authentication-Type": "certificate"})
    values["cert"] = str(values["certificate"])
    values["verify"] = True
    values["session"].cert = values["cert"]
    values["session"].verify = values["verify"]
    return values

certificate_exists_and_is_readable

Python
certificate_exists_and_is_readable(value: str)

Check the certificate.

Source code in /home/runner/.cache/pypoetry/virtualenvs/handbook-G9X_rrhO-py3.10/lib/python3.10/site-packages/skaha/client.py
Python
@validator("certificate", pre=True, always=True)
def certificate_exists_and_is_readable(cls, value: str):
    """Check the certificate."""
    try:
        value = parse_obj_as(FilePath, value)  # type: ignore
    except ValidationError as error:
        log.error(error)
        raise InvalidCertificateError(
            "certificate needs to be absolute path and readable"
        )
    return value

server_has_valid_url

Python
server_has_valid_url(value: str)

Check if server is a valid url.

Source code in /home/runner/.cache/pypoetry/virtualenvs/handbook-G9X_rrhO-py3.10/lib/python3.10/site-packages/skaha/client.py
Python
@validator("server", pre=True, always=True)
def server_has_valid_url(cls, value: str):
    """Check if server is a valid url."""
    try:
        value = parse_obj_as(AnyHttpUrl, value)
    except ValidationError as error:
        log.error(error)
        raise InvalidServerURL("invalid server url")
    return value

session_set_headers

Python
session_set_headers(values: Dict[str, Any])

Set headers to session object after all values has been obtained.

Source code in /home/runner/.cache/pypoetry/virtualenvs/handbook-G9X_rrhO-py3.10/lib/python3.10/site-packages/skaha/client.py
Python
@root_validator(skip_on_failure=True)
def session_set_headers(cls, values: Dict[str, Any]):
    """Set headers to session object after all values has been obtained."""
    values["session"].headers.update({"X-Skaha-Server": str(values["server"])})
    values["session"].headers.update(
        {"Content-Type": "application/x-www-form-urlencoded"}
    )
    values["session"].headers.update({"Accept": "*/*"})
    values["session"].headers.update({"User-Agent": "skaha-client"})
    values["session"].headers.update({"Date": asctime(gmtime())})
    values["session"].headers.update({"X-Skaha-Version": __version__})
    values["session"].headers.update(
        {"X-Skaha-Client-Python-Version": python_version()}
    )
    values["session"].headers.update({"X-Skaha-Client-Arch": machine()})
    values["session"].headers.update({"X-Skaha-Client-OS": system()})
    values["session"].headers.update({"X-Skaha-Client-OS-Version": release()})
    values["session"].headers.update({"X-Skaha-Client-Platform": platform()})
    return values