Skip to content

client

Client

Create a client instance.

Usage:

>>> from sfapi_client import Client
>>> with Client(client_id, client_secret) as client:
>>>    # Use client

Parameters:

Name Type Description Default
client_id Optional[str]

The client ID

None
secret Optional[str]

The client secret

None
key Optional[Union[str, Path]]

Full path to the client secret file, or path relative to ~ from the expanduser

None
api_base_url Optional[str]

The API base URL

SFAPI_BASE_URL
token_url Optional[str]

The token URL

SFAPI_TOKEN_URL
access_token Optional[str]

An existing access token

None

Returns:

Type Description
Client

The client instance

Source code in sfapi_client/_sync/client.py
def __init__(
    self,
    client_id: Optional[str] = None,
    secret: Optional[str] = None,
    key: Optional[Union[str, Path]] = None,
    api_base_url: Optional[str] = SFAPI_BASE_URL,
    token_url: Optional[str] = SFAPI_TOKEN_URL,
    access_token: Optional[str] = None,
    wait_interval: int = 10,
):
    """
    Create a client instance.

    Usage:

    ```python
    >>> from sfapi_client import Client
    >>> with Client(client_id, client_secret) as client:
    >>>    # Use client
    ```

    :param client_id: The client ID
    :param secret: The client secret
    :param key: Full path to the client secret file, or path relative to `~` from the expanduser
    :param api_base_url: The API base URL
    :param token_url: The token URL
    :param access_token: An existing access token

    :return: The client instance
    :rtype: Client
    """
    self._client_id = None
    self._secret = None
    if any(arg is None for arg in [client_id, secret]):
        self._read_client_secret_from_file(key)
    else:
        self._client_id = client_id
        self._secret = secret
    self._api_base_url = api_base_url
    self._token_url = token_url
    self._client_user = None
    self.__http_client = None
    self._api = None
    self._resources = None
    self._wait_interval = wait_interval
    self._access_token = access_token

api property

API related information.

resources property

Resource related information.

token property

Bearer token string which can be helpful for debugging through swagger UI.

close()

Release resources associated with the client instance.

Source code in sfapi_client/_sync/client.py
def close(self):
    """
    Release resources associated with the client instance.
    """
    if self.__http_client is not None:
        self.__http_client.close()

compute(machine)

Create a compute site to submit jobs or view jobs in the queue

Parameters:

Name Type Description Default
machine Union[Machine, str]

Name of the compute machine to use

required

Returns:

Type Description
Compute

Compute object that can be used to start jobs, view the queue on the system, or list files and directories.

Source code in sfapi_client/_sync/client.py
def compute(self, machine: Union[Machine, str]) -> Compute:
    """Create a compute site to submit jobs or view jobs in the queue

    :param machine: Name of the compute machine to use
    :return: Compute object that can be used to start jobs,
    view the queue on the system, or list files and directories.
    """
    # Allows for creating a compute from a name string
    machine = Machine(machine)
    response = self.get(f"status/{machine.value}")

    values = response.json()
    values["client"] = self
    compute = Compute.model_validate(values)

    return compute

group(name)

Get a group.

Parameters:

Name Type Description Default
name str

The group name

required

Returns:

Type Description
Group

The group

Source code in sfapi_client/_sync/client.py
def group(self, name: str) -> Group:
    """
    Get a group.

    :param name: The group name
    :return: The group
    :rtype: Group
    """
    return Group._fetch_group(self, name)

user(username=None)

Get a user.

Parameters:

Name Type Description Default
username Optional[str]

The username

None

Returns:

Type Description
UserGroup

The user

Source code in sfapi_client/_sync/client.py
def user(self, username: Optional[str] = None) -> User:
    """
    Get a user.

    :param username: The username
    :return: The user
    :rtype: UserGroup
    """
    return User._fetch_user(self, username)