Initialization

API functions

async-with neuro_sdk.get(*, path: Optional[Path] = 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 neuro_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.

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

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

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

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

coroutine neuro_sdk.login_with_token(token: str, *, url: URL = DEFAULT_API_URL, path: Optional[Path] = None, timeout: aiohttp.ClientTimeout = DEFAULT_TIMEOUT) None[source]

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

coroutine neuro_sdk.logout(*, path: Optional[Path] = None, show_browser_cb: Callable[[URL], Awaitable[None]] = None) None[source]

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

Config Factory

class neuro_sdk.Factory(path: Optional[Path])

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

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

path

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

Read-only pathlib.Path property.

New in version 20.2.25.

is_config_present

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

Read-only bool property.

coroutine 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 neuro 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 Neuro Platform.

Raise

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

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

Log into Neuro 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 Neuro Platform operations.

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

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

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

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

Log into Neuro 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 Neuro Platform operations.

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

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

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

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

Log into Neuro 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) – Neuro Platform API URL, URL("https://staging.neu.ro/api/v1") by default.

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

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

Log into Neuro 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 NEURO_PASSED_CONFIG environment variable.

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

Log out from Neuro 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.