Initialization

API functions

async apolo_sdk.get(*, path: Path | None = None, timeout: aiohttp.ClientTimeout = DEFAULT_TIMEOUT) AsyncContextManager[Client][source]

The handy API for getting initialized Client instance.

A shortcut for Factory.get() that acts as asynchronous context manager.

The usage is:

async with apolo_sdk.get() as client:
    async with client.jobs.list() as jobs:
        async for job in jobs:
            print(job.id)

See Factory.get() for optional function arguments meaning.

async apolo_sdk.login(show_browser_cb: Callable[[URL], Awaitable[None]], *, url: URL = DEFAULT_API_URL, path: Path | None = None, timeout: aiohttp.ClientTimeout = DEFAULT_TIMEOUT) None[source]

A shortcut for Factory.login(). See the method for details.

async apolo_sdk.login_with_headless(get_auth_code_cb: Callable[[URL], Awaitable[str]], *, url: URL = DEFAULT_API_URL, path: Path | None = None, timeout: aiohttp.ClientTimeout = DEFAULT_TIMEOUT) None

A shortcut for Factory.login_headless(). See the method for details.

async apolo_sdk.login_with_token(token: str, *, url: URL = DEFAULT_API_URL, path: Path | None = None, timeout: aiohttp.ClientTimeout = DEFAULT_TIMEOUT) None[source]

A shortcut for Factory.login_with_token(). See the method for details.

apolo_sdk.logout(*, path: Path | None = None, show_browser_cb: Callable[[URL], Awaitable[None]] = None) None[source]

A shortcut for Factory.logout(). See the method for details.

Config Factory

class apolo_sdk.Factory(path: Path | None)

A factory that used for making Client instances, logging into Apolo Platform and logging out.

path (pathlib.Path) can be provided for pointing on a custom configuration directory (~/.apolo by default). The default value can be overridden by APOLO_CONFIG environment variable.

path

Revealed path to the configuration directory, expanded as described above.

Read-only pathlib.Path property.

Added in version 20.2.25.

is_config_present

True if config files are present under path, False otherwise.

Read-only bool property.

async get(*, timeout: aiohttp.ClientTimeout = DEFAULT_TIMEOUT) Client[source]

Read configuration previously created by login methods and return a client instance. Update authorization token if needed.

The easiest way to create required configuration file is running apolo login CLI command before the first call of this method from a user code.

Parameters:

timeout (aiohttp.ClientTimeout) – optional timeout for HTTP operations, see also Timeouts.

Returns:

Client that can be used for working with Apolo Platform.

Raise:

ConfigError if configuration file doesn’t exist, malformed or not compatible with SDK version.

async login(show_browser_cb: Callable[[URL], Awaitable[None]], *, url: URL = DEFAULT_API_URL, timeout: aiohttp.ClientTimeout = DEFAULT_TIMEOUT) None[source]

Log into Apolo Platform using in-browser authorization method.

The method is dedicated for login from workstation with GUI system. For logging in from server please use login_headless().

The caller provides show_browser_cb callback which is called with URL argument.

The callback should open a browser with this URL (webbrowser.open() can be used).

After the call the configuration file is created, call get() for making a client and performing Apolo Platform operations.

Parameters:
  • show_browser_cb – a callback that should open a browser with specified URL for handling authorization.

  • url (URL) – Apolo Platform API URL, URL("https://staging.neu.ro/api/v1") by default.

  • timeout (aiohttp.ClientTimeout) – optional timeout for HTTP operations, see also Timeouts.

async login_headless(get_auth_code_cb: Callable[[URL], Awaitable[str]], *, url: URL = DEFAULT_API_URL, timeout: aiohttp.ClientTimeout = DEFAULT_TIMEOUT) None[source]

Log into Apolo Platform using two-step authorization method.

The method is dedicated for login from remote server that has no GUI system. For logging in from GUI equipped workstation please use login().

The caller provides get_auth_code_cb callback which is called with URL argument.

Usually, the callback prints given URL on screen and displays a prompt.

User copies the URL from remote terminal session into local browser, authorizes and enters authorization code shown in the browser back into prompt.

After the call the configuration file is created, call get() for making a client and performing Apolo Platform operations.

Parameters:
  • get_auth_code_cb – a callback that receives an URL and returns authorization code.

  • url (URL) – Apolo Platform API URL, URL("https://staging.neu.ro/api/v1") by default.

  • timeout (aiohttp.ClientTimeout) – optional timeout for HTTP operations, see also Timeouts.

async login_with_token(token: str, *, url: URL = DEFAULT_API_URL, timeout: aiohttp.ClientTimeout = DEFAULT_TIMEOUT) None[source]

Log into Apolo Platform using previously acquired token. The method is deprecated and not recommended to use. Provided tokens will be revoked eventually.

Parameters:
  • token (str) – authorization token.

  • url (URL) – Apolo Platform API URL, URL("https://staging.neu.ro/api/v1") by default.

  • timeout (aiohttp.ClientTimeout) – optional timeout for HTTP operations, see also Timeouts.

async login_with_passed_config(config_data: str | None = None, *, timeout: aiohttp.ClientTimeout = DEFAULT_TIMEOUT) None[source]

Log into Apolo Platform using config data passed by platform. Use this only to login from the job that was started with pass_config=True. Inside such job, config_data is available under APOLO_PASSED_CONFIG environment variable.

param str config_data:

config data passed by platform.

param aiohttp.ClientTimeout timeout:

optional timeout for HTTP operations, see also Timeouts.

async logout(show_browser_cb: Callable[[URL], Awaitable[None]] = None)[source]

Log out from Apolo Platform. In case show_browser_cb callback passed, the browser will be opened to remove session cookie.

Parameters:

show_browser_cb – a callback that should open a browser with specified URL for handling authorization.

Timeouts

By default the SDK raises asyncio.TimeoutError if the server doesn’t respond in a minute. It can be overridden by passing timeout argument to Factory methods.