Neuro SDK for Python¶
A Python library for the Neuro Platform API.
Installation¶
The latest stable release is available on PyPI. Either add neuro-sdk
to your
requirements.txt
or install with pip:
$ pip install -U neuro-sdk
Getting Started¶
To start working with the Neuro Platform you need to login first. The easiest way to do it is the using of CLI utility:
$ neuro login
After the login a configuration file is created and it can be read later.
Use neuro_sdk.get()
for initializing client instance from existing
configuration file:
import neuro_sdk
async with neuro_sdk.get() as client:
async with client.jobs.list() as job_iter:
jobs = [job async for job in job_iter]
The example above instantiates a client
object in async context manager and
fetches a list of user’s jobs. On exit from async with
statement the client
object is closed and is not available for future calls.
See Usage section for ideas how typical operations can be done with Neu.ro platform. Reference section contains the full API reference for all API classes, functions etc.
Contents¶
Usage¶
Jobs Usage¶
Use Jobs API (available as Client.jobs
) for starting a job, killing it, getting
list of running jobs etc. This chapter describes several common scenarios.
Here we describe the most common scenarios, see Jobs API Reference for the full list of job namespace methods.
Start a Job¶
To start a job use Jobs.start()
method.
The method accepts image and
required resources preset name as parameters and returns JobDescription
with information about started
job:
from neuro_sdk import get
async with get() as client:
job = await client.jobs.start(
image=client.parse.remote_image("ubuntu:latest"),
preset_name="cpu-small",
command="sleep 30",
)
The example above starts a job using ubuntu:latest
public image, cpu-small
resources preset and executes sleep 30
command inside started container.
Note
After return from the call a new job is scheduled for execution but usually it’s status is pending. The Neuro Platform takes time for preparing resources for a job, pulling image from registry etc. Startup time can vary from seconds for hot start to minutes for cold one.
Check Job Status¶
After spawning a job we have JobDescription
instance that describes job status
(and other things like executed command line).
A job takes time for deployment, it can be terminated by different reasons, e.g. requested image name doesn’t exist.
The following snippet waits for job’s starting execution or failure:
# job is a JobDescription given by former client.job.run() call
while True:
job = await client.jobs.status(job.id)
if job.status in (JobStatus.RUNNING, JobStatus.SUCCEEDED):
break
elif job.status == JobStatus.FAILED:
raise RuntimeError(f"Job {job.id} failed with {job.reason}:"
f"{job.history.description}")
else:
await asyncio.sleep(1)
Mount Neuro Storage folders¶
The Neuro Platform provides access to Neuro storage (storage://
) by
mounted folders inside a container (volumes in Docker
glossary).
If you have a directory storage:folder
and want to mount it inside a container under
/var/data
path please create a Volume
and use it in Container
definition:
from yarl import URL
volume = Volume(
storage_uri=URL("storage:folder"),
container_path="/mnt/data",
)
job = await client.jobs.run(
Container(
image=client.parse.remote_image("ubuntu:latest"),
resources=Resources(memory_mb=100, cpu=0.5),
command="sleep 30",
volumes=[volume],
)
)
There is a parsing helper that can construct a Volume
instance from a string in
format that is used in CLI:
volume = client.parse.volume("storage:folder:/var/data")
To specify read-only mount point please pass read_only=True
to Volume
constructor, e.g. the following code mounts public shared
storage://neuro/public
folder in read-only mode:
public_volume = Volume(
storage_uri=URL("storage:neuro/public"),
container_path="/mnt/public",
read_only=True,
)
The same effect can be achieved by using a parser API:
public_volume = client.parse.volume(
"storage:neuro/public:/mnt/public:ro")
Pass a list of volumes into container to support multiple mount points:
Container(
image=...,
resources=...,
command=...,
volumes=[volume, public_volume],
)
See also
Storage Usage for the storage manipulation API.
Kill a Job¶
Use Jobs.kill()
for enforcing job to stop:
await client.jobs.kill(job.id)
Expose job’s TCP ports locally¶
Sometimes there is a need to access TCP endpoints exposed by a job executed on the Neuro Platform from local workstation.
For example, you’ve started a gRPC server inside a container on TCP port 12345
and
want to access this service from your laptop.
You need to bridge this remote 12345
port into a local TCP namespace
(e.g. 23456
local port by Jobs.port_forward()
method:
from grpclib.client import Channel
# generated by protoc
from .helloworld_pb2 import HelloRequest, HelloReply
from .helloworld_grpc import GreeterStub
async with client.jobs.port_forward(job.id, 23456, 12345):
# open gRPC client and use it
channel = Channel('127.0.0.1', 23456)
greeter = GreeterStub(channel)
reply: HelloReply = await greeter.SayHello(HelloRequest(name='Dr. Strange'))
print(reply.message)
channel.close()
The example uses grpclib library for make client gRPC requests.
Job preemption¶
Job preemption means that unlike normal jobs preemptible ones can be stopped by kernel when the system has lack of resources and restarted later. All memory and local disk changes are lost but data written to the Neuro Storage (see Mount Neuro Storage folders ) is persistent.
To support preemption job’s code should be organized in the following way: it dumps snapshots on disk periodically. On restart the code checks for last saved snapshot and continues the work from this point.
AI frameworks usually supports snapshots out of the box, see saving and loading models in pytorch or Keras ModelCheckpoint.
Preemptible job is not such convenient as regular job but it’s computational time is much cheaper (exact numbers varies on concrete computational cluster provides, e.g. Google Compute, AWS or Azure).
Jobs are non-preeptible by default, you can change this by passing
preemptible_node=True
flag to Jobs.run()
.
Storage Usage¶
Use Storage API (available as Client.storage
) for uploading files to the
Neu.ro Storage and downloading them back. This chapter describes several common
scenarios like uploading / downloading directories recursively.
There are many methods in Storage
namespace, here we describe a few.
Blob Storage API (available as Client.blob_storage
) is another subsystem,
which has a similar Upload/Download interface as methods shown below. Please refer to
BlobStorage
documentation for more details.
Upload a Folder¶
Use Storage.upload_dir()
to upload a local directory on the Neuro Storage:
from neuro_sdk import get
from yarl import URL
async with get() as client:
await client.storage.upload_dir(
URL("file:local_folder"),
URL("storage:remote_folder"),
)
The example above recursively uploads all files and directories ./local_folder
to
storage://<username>/remote_folder
.
Use update=True
flag to upload only files that are newer than are present on the
Storage:
await client.storage.upload_dir(
URL("file:local_folder"),
URL("storage:remote_folder"),
update=True,
)
Download a Folder¶
Use Storage.download_dir()
for downloading data from the Neuro Storage to
local disk.
The method is a counterpart to Storage.upload_dir()
and has the same arguments:
await client.storage.download_dir(
URL("storage:remote_folder"),
URL("file:local_folder"),
)
The example above recursively downloads files and directories from
storage:remote_folder
to ./local_folder
.
Reference¶
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 byNEUROMATION_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 underpath
,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 underNEURO_PASSED_CONFIG
environment variable.- Parameters
config_data (str) – config data passed by platform.
timeout (aiohttp.ClientTimeout) – optional timeout for HTTP operations, see also Timeouts.
- 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.
Client class¶
- class neuro_sdk.Client¶
Neuro Platform client.
For creating a client instance use
Factory
orget()
.The class provides access to Neu.ro subsystems like jobs or storage.
- presets¶
A
typing.Mapping
of preset name (str
) toPreset
dataclass.Presets are loaded from server on login.
Configuration API Reference¶
API functions¶
- neuro_sdk.find_project_root(path: Optional[Path] = None) Path ¶
Look for project root directory.
Folder is considered a project root when it contains
.neuro.toml
. Search begins at path orPath.cwd()
(current working directory) when path is None and checks all parent folders sequentially. Will raise anConfigError
if search reaches root directory.
Config¶
- class neuro_sdk.Config¶
Configuration subsystem, available as
Client.config
.Use it for analyzing fetching information about the system configuration, e.g. a list of available clusters or switching the active cluster.
- presets¶
A
typing.Mapping
of preset name (str
) toPreset
dataclass for the current cluster.
- clusters¶
A
typing.Mapping
of cluster name (str
) toCluster
dataclass for available clusters.
- cluster_name¶
The current cluster name, read-only
str
.To switch on another cluster use
switch_cluster()
.
- org_name¶
The current org name, read-only
str
.To switch on another org use
switch_org()
.
- coroutine fetch() None [source]¶
Fetch available clusters configuration from the Neuro Platform.
Note
The call updates local configuration files.
- coroutine switch_cluster(name: str) None [source]¶
Switch the current cluster to name.
Note
The call updates local configuration files.
- coroutine switch_org(name: str) None [source]¶
Switch the current org to name.
Note
The call updates local configuration files.
Miscellaneous helpers
- registry_url¶
Docker Registry URL for the cluster,
yarl.URL
.Cluster.registry_url
for the current cluster.
- storage_url¶
Storage URL for the cluster,
yarl.URL
.Cluster.storage_url
for the current cluster.
- monitoring_url¶
Monitoring URL for the cluster,
yarl.URL
.Cluster.monitoring_url
for the current cluster.
- coroutine get_user_config() Mapping[str, Any] [source]¶
Return user-provided config dictionary. Config is loaded from config files. There are two configuration files: global and local, both are optional and can be absent.
The global file is named
user.toml
and the API search for it in the path provided toFactory
orget()
($HOME/.neuro/user.toml
by default).The local config file is named
.neuro.toml
, and the API search for this file starting from the current folder up to the root directory.Found local and global configurations are merged. If a parameter is present are both global and local versions the local parameter take a precedence.
Configuration files have a TOML format (a stricter version of well-known INI format). See https://en.wikipedia.org/wiki/TOML and https://github.com/toml-lang/toml#toml for the format specification details.
The API will raise an
ConfigError
if configuration files contains unknown sections or parameters. Note that currently API doesn’t use any parameter from user config.Known sections: alias, job, storage.
Section alias can have any subsections with any keys.
Section job can have following keys: ps-format - string, life-span - string.
Section storage can have following keys: cp-exclude - list of strings, cp-exclude-from-files - list of strings.
There is a plugin system that allows to register additional config parameters. To define a plugin, add a neuro_api entrypoint (check https://packaging.python.org/specifications/entry-points/ for more info about entry points). Entry point should be callable with single argument of type
PluginManager
.New in version 20.01.15.
Cluster¶
- class neuro_sdk.Cluster¶
Read-only
dataclass
for describing a cluster configuration.Clusters are loaded on login to the Neuro platform and updated on
Config.fetch()
call.Config.switch_cluster()
changes the active cluster.- presets¶
A
typing.Mapping
of available job resource presets, keys are preset names (str
), values arePreset
objects.
Preset¶
- class neuro_sdk.Preset¶
Read-only
dataclass
for describing a job configuration provided by Neuro Platform.Presets list is loaded on login to the Neuro platform and depends on used cluster.
- cpu¶
Requested number of CPUs,
float
. Please note, Docker supports fractions here, e.g.0.5
CPU means a half or CPU on the target node.
- is_preemptible¶
A flag that specifies is the job is preemptible or not, see Preemption for details.
- tpu_type¶
Requested TPU type, see also https://en.wikipedia.org/wiki/Tensor_processing_unit
- tpu_software_version¶
Requested TPU software version.
Jobs API Reference¶
Jobs¶
- class neuro_sdk.Jobs¶
Jobs subsystem, available as
Client.jobs
.User can start new job, terminate it, get status, list running jobs etc.
- async-with attach(id: str, *, tty: bool = False, stdin: bool = False, stdout: bool = False, stderr: bool = False, cluster_name: Optional[str] = None) AsyncContextManager[StdStream] [source]¶
Get access to standard input, output, and error streams of a running job.
- Parameters
tty (bool) –
True
if tty mode is requested, default isFalse
.stdin (bool) –
True
to attach stdin, default isFalse
.stdout (bool) –
True
to attach stdout, default isFalse
.stderr (bool) –
True
to attach stderr, default isFalse
.cluster_name (str) –
cluster on which the job is running.
None
means the current cluster (default).
- Returns
Asynchronous context manager which can be used to access stdin/stdout/stderr, see
StdStream
for details.
- async-with exec(id: str, cmd: str, *, tty: bool = False, stdin: bool = False, stdout: bool = False, stderr: bool = False, cluster_name: Optional[str] = None) AsyncContextManager[StdStream] [source]¶
Start an exec session, get access to session’s standard input, output, and error streams.
- Parameters
cmd (str) – the command to execute.
tty (bool) –
True
if tty mode is requested, default isFalse
.stdin (bool) –
True
to attach stdin, default isFalse
.stdout (bool) –
True
to attach stdout, default isFalse
.stderr (bool) –
True
to attach stderr, default isFalse
.cluster_name (str) –
cluster on which the job is running.
None
means the current cluster (default).
- Returns
Asynchronous context manager which can be used to access stdin/stdout/stderr, see
StdStream
for details.
- coroutine get_capacity(*, cluster_name: Optional[str] = None) Mapping[str, int] [source]¶
Get counts of available job for specified cluster for each available preset.
The returned numbers reflect the remaining cluster capacity. In other words, it displays how many concurrent jobs for each preset can be started at the moment of the method call.
The returned capacity is an approximation, the real value can differ if already running jobs are finished or another user starts own jobs at the same time.
- Parameters
cluster_name (str) –
cluster for which the request is performed.
None
means the current cluster (default).- Returns
A mapping of preset_name to count, where count is a number of concurrent jobs that can be executed using preset_name.
- async-with async-for list(*, statuses: Iterable[JobStatus] = (), name: Optional[str] = None, tags: Sequence[str] = (), owners: Iterable[str] = (), since: Optional[datetime] = None, until: Optional[datetime] = None, reverse: bool = False, limit: Optional[int] = None, cluster_name: Optional[str] = None) AsyncContextManager[AsyncIterator[JobDescription]] [source]¶
List user jobs, all scheduled, running and finished jobs by default.
- Parameters
statuses (Iterable[JobStatus]) –
filter jobs by their statuses.
The parameter can be a set or list of requested statuses, e.g.
{JobStatus.PENDIND, JobStatus.RUNNING}
can be used for requesting only scheduled and running job but skip finished and failed ones.Empty sequence means that jobs with all statuses are returned (default behavior). The list can be pretty huge though.
name (str) –
Filter jobs by
name
(exact match).Empty string or
None
means that no filter is applied (default).filter jobs by
tags
.Retrieves only jobs submitted with all tags from the specified list.
Empty list means that no filter is applied (default).
filter jobs by their owners.
The parameter can be a set or list of owner usernames (see
JobDescription.owner
for details).No owners filter is applied if the iterable is empty.
since (datetime) –
filter jobs by their creation date.
Retrieves only jobs submitted after the specified date (including) if it is not
None
. If the parameter is a naive datetime object, it represents local time.None
means that no filter is applied (default).until (datetime) –
filter jobs by their creation date.
Retrieves only jobs submitted before the specified date (including) if it is not
None
. If the parameter is a naive datetime object, it represents local time.None
means that no filter is applied (default).reverse (bool) –
iterate jobs in the reverse order.
If reverse is false (default) the jobs are iterated in the order of their creation date, from earlier to later. If reverse is true, they are iterated in the reverse order, from later to earlier.
limit (int) –
limit the number of jobs.
None
means no limit (default).cluster_name (str) –
list jobs on specified cluster.
None
means the current cluster (default).
- Returns
asynchronous iterator which emits
JobDescription
objects.
- monitor(id: str, *, cluster_name: Optional[str] = None, since: Optional[datetime] = None,
- timestamps: bool = False,
- separator: Optional[str] = None,
- ) -> AsyncContextManager[AsyncIterator[bytes]]
Get job logs as a sequence of data chunks, e.g.:
async with client.jobs.monitor(job_id) as it: async for chunk in it: print(chunk.encode('utf8', errors='replace')
- Parameters
cluster_name (str) –
cluster on which the job is running.
None
means the current cluster (default).since (datetime) –
Retrieves only logs after the specified date (including) if it is not
None
. If the parameter is a naive datetime object, it represents local time.None
means that no filter is applied (default).timestamps (bool) – if true, include timestamps on each line in the log output.
separator (str) –
string which will separate archive and live logs (if both parts are present).
By default a string containing random characters are used. Empty separator suppresses output of separator.
- Returns
AsyncIterator
overbytes
log chunks.
- async-with port_forward(id: str, local_port: int, job_port: int, *, no_key_check: bool = False, cluster_name: Optional[str] = None) None [source]¶
Forward local port to job, e.g.:
async with client.jobs.port_forward(job_id, 8080, 80): # port forwarding is awailable inside with-block
- coroutine run(container: Container, *, name: Optional[str] = None, tags: Sequence[str] = (), description: Optional[str] = None, scheduler_enabled: bool = False, pass_config: bool = False, wait_for_jobs_quota: bool = False, schedule_timeout: Optional[float] = None, life_span: Optional[float] = None, priority: Optional[JobPriority] = None) JobDescription [source]¶
Start a new job.
Deprecated since version 20.11.25: Please use
start()
instead.- Parameters
container (Container) – container description to start.
name (str) – optional container name.
name – optional job tags.
description (str) – optional container description.
scheduler_enabled (bool) – a flag that specifies is the job should participate in round-robin scheduling.
pass_config (bool) – a flag that specifies that platform should pass config data to job. This allows to API and CLI from the inside of the job. See
Factory.login_with_passed_config()
for details.wait_for_jobs_quota (bool) – when this flag is set, job will wait for another job to stop instead of failing immediately because of total running jobs quota.
schedule_timeout (float) – minimal timeout to wait before reporting that job cannot be scheduled because the lack of computation cluster resources (memory, CPU/GPU etc). This option is not allowed when
is_preemptible
is set toTrue
.life_span (float) – job run-time limit in seconds. Pass None to disable.
priority (JobPriority) – priority used to specify job’s start order. Jobs with higher priority will start before ones with lower priority. Priority should be supported by cluster.
- Returns
JobDescription
instance with information about started job.
- coroutine start(*, image: RemoteImage, preset_name: str, cluster_name: Optional[str] = None, org_name: Optional[str] = None, entrypoint: Optional[str] = None, command: Optional[str] = None, working_dir: Optional[str] = None, http: Optional[HTTPPort] = None, env: Optional[Mapping[str, str]] = None, volumes: Sequence[Volume] = (), secret_env: Optional[Mapping[str, URL]] = None, secret_files: Sequence[SecretFile] = (), disk_volumes: Sequence[DiskVolume] = (), tty: bool = False, shm: bool = False, name: Optional[str] = None, tags: Sequence[str] = (), description: Optional[str] = None, pass_config: bool = False, wait_for_jobs_quota: bool = False, schedule_timeout: Optional[float] = None, restart_policy: JobRestartPolicy = JobRestartPolicy.NEVER, life_span: Optional[float] = None, privileged: bool = False, priority: Optional[JobPriority] = None) JobDescription [source]¶
Start a new job.
- Parameters
image (RemoteImage) – image used for starting a container.
preset_name (str) – name of the preset of resources given to a container on a node.
cluster_name (str) – cluster to start a job. Default is current cluster.
org_name (str) – org to start a job on behalf of. Default is current org.
entrypoint (str) – optional Docker ENTRYPOINT used for overriding image entry-point (
str
), defaultNone
is used to pick entry-point from image’s Dockerfile.command (str) – optional command line to execute inside a container (
str
),None
for picking command line from image’s Dockerfile.working_dir (str) – optional working directory inside a container (
str
),None
for picking working directory from image’s Dockerfile.http (HTTPPort) – optional parameters of HTTP server exposed by container,
None
if the container doesn’t provide HTTP access.env (Mapping[str,str]) – optional custom environment variables for pushing into container’s task. A
Mapping
where keys are environments variables names and values are variable values, bothstr
.None
by default.volumes (Sequence[Volume]) – optional Docker volumes to mount into container, a
Sequence
ofVolume
objects. Emptytuple
by default.secret_env (Mapping[str,yarl.URL]) – optional secrets pushed as custom environment variables into container’s task. A
Mapping
where keys are environments variables names (str
) and values are secret URIs (yarl.URL
).None
by default.secret_files (Sequence[SecretFile]) – optional secrets mounted as files in a container, a
Sequence
ofSecretFile
objects. Emptytuple
by default.disk_volumes (Sequence[DiskVolume]) – optional disk volumes used to mount into container, a
Sequence
ofDiskVolume
objects. Emptytuple
by default.tty (bool) – Allocate a TTY or not.
False
by default.shm (bool) – Use Linux shared memory or not.
False
by default.name (str) – optional job name.
description (str) – optional container description.
pass_config (bool) – a flag that specifies that platform should pass config data to job. This allows to API and CLI from the inside of the job. See
Factory.login_with_passed_config()
for details.wait_for_jobs_quota (bool) – when this flag is set, job will wait for another job to stop instead of failing immediately because of total running jobs quota.
schedule_timeout (float) – minimal timeout to wait before reporting that job cannot be scheduled because the lack of computation cluster resources (memory, CPU/GPU etc).
life_span (float) – job run-time limit in seconds. Pass None to disable.
restart_policy (JobRestartPolicy) – job restart behavior.
JobRestartPolicy
.NEVER by default.privileged (bool) – Run job in privileged mode. This mode should be supported by cluster.
priority (JobPriority) – priority used to specify job’s start order. Jobs with higher priority will start before ones with lower priority. Priority should be supported by cluster.
None
by default.
- Returns
JobDescription
instance with information about started job.
- coroutine send_signal(id: str, *, cluster_name: Optional[str] = None) None [source]¶
Send
SIGKILL
signal to a job.
- coroutine status(id: str) JobDescription [source]¶
Get information about a job.
- Parameters
- Returns
JobDescription
instance with job status details.
- async-with async-for top(id: str, *, cluster_name: Optional[str] = None) AsyncContextManager[AsyncIterator[JobTelemetry]] [source]¶
Get job usage statistics, e.g.:
async with client.jobs.top(job_id) as top: async for data in top: print(data.cpu, data.memory)
Container¶
- class neuro_sdk.Container¶
Read-only
dataclass
for describing Docker image and environment to run a job.- image¶
RemoteImage
used for starting a container.
- entrypoint¶
Docker ENTRYPOINT used for overriding image entry-point (
str
), defaultNone
is used to pick entry-point from image’s Dockerfile.
- command¶
Command line to execute inside a container (
str
),None
for picking command line from image’s Dockerfile.
- http¶
HTTPPort
for describing parameters of HTTP server exposed by container,None
if the container doesn’t provide HTTP access.
- env¶
Custom environment variables for pushing into container’s task.
A
Mapping
where keys are environments variables names and values are variable values, bothstr
. Emptydict
by default.
- volumes¶
Docker volumes to mount into container, a
Sequence
ofVolume
objects. Emptylist
by default.
- secret_env¶
Secrets pushed as custom environment variables into container’s task.
A
Mapping
where keys are environments variables names (str
) and values are secret URIs (yarl.URL
). Emptydict
by default.
- secret_files¶
Secrets mounted as files in a container, a
Sequence
ofSecretFile
objects. Emptylist
by default.
- disk_volumes¶
Disk volumes used to mount into container, a
Sequence
ofDiskVolume
objects. Emptylist
by default.
HTTPPort¶
- class neuro_sdk.HTTPPort¶
Read-only
dataclass
for exposing HTTP server started in a job.To access this server from remote machine please use
JobDescription.http_url
.- requires_auth¶
Authentication in Neuro Platform is required for access to exposed HTTP server if
True
, the port is open publicly otherwise.
JobDescription¶
- class neuro_sdk.JobDescription¶
Read-only
dataclass
for describing a job.- history¶
Additional information about job, e.g. creation time and process exit code.
JobStatusHistory
instance.
- scheduler_enabled¶
Is job participate in round-robin scheduling.
- preemptible_node¶
Is this node allows execution on preemptible node. If set to
True
, the job only allows execution on preemptible nodes. If set toFalse
, the job only allows execution on non-preemptible nodes.
- pass_config¶
Is config data is passed by platform, see
Factory.login_with_passed_config()
for details.
- privileged¶
Is the job is running in privileged mode, refer to docker documentation for details.
- tags¶
List of job tags provided by user at creation time,
Sequence[str]
or()
if tags omitted.
- description¶
Job description text provided by user at creation time,
str
orNone
if description is omitted.
- ssh_server¶
yarl.URL
to access running job by SSH. Internal field, don’t access it from custom code. UseJobs.exec()
andJobs.port_forward()
as official API for accessing to running job.
- internal_hostname¶
DNS name to access the running job from other jobs.
- internal_hostname_named¶
DNS name to access the running job from other jobs based on jobs name instead of jobs id. Produces same value for jobs with
name
andowner
in same cluster.
- schedule_timeout¶
Minimal timeout in seconds job will wait before reporting it cannot be scheduled because the lack of computation cluster resources (memory, CPU/GPU etc),
float
- priority¶
Priority used to specify job’s start order. Jobs with higher priority will start before ones with lower priority,
JobPriority
- _internal¶
Some internal info about job used by platform. Should not be used.
JobRestartPolicy¶
JobPriority¶
JobStatus¶
- class neuro_sdk.JobStatus¶
Enumeration that describes job state.
Can be one of the following statues:
- PENDING¶
Job is scheduled for execution but not started yet.
- RUNNING¶
Job is running now.
- SUSPENDED¶
Scheduled job is paused to allow other jobs to run.
- SUCCEEDED¶
Job is finished successfully.
- CANCELLED¶
Job was canceled while it was running.
- FAILED¶
Job execution is failed.
- UNKNOWN¶
Invalid (or unknown) status code, should be never returned from server.
Also some shortcuts are available:
- active_items() Set[JobStatus] [source]¶
Returns all statuses that are not final:
PENDING
,SUSPENDED
andRUNNING
.
- finished_items() Set[JobStatus] [source]¶
Returns all statuses that are final:
SUCCEEDED
,CANCELLED
andFAILED
.
Each enum value has next
bool
fields:
JobStatusItem¶
- class neuro_sdk.JobStatusItem¶
Read-only
dataclass
for describing job status transition details.- reason¶
Additional information for job status,
str
.Examples of reason values:
'ContainerCreating'
forJobStatus.PENDING
job that initiates a pod for container.'ErrImagePull'
forJobStatus.FAILED
job that cannot pull specified image.
JobStatusHistory¶
- class neuro_sdk.JobStatusHistory¶
Read-only
dataclass
for describing job status details, e.g. creation and finishing time, exit code etc.- status¶
Current status of job,
JobStatus
enumeration.The same as
JobDescription.status
.
- reason¶
Additional information for current status,
str
.Examples of reason values:
'ContainerCreating'
forJobStatus.PENDING
job that initiates a pod for container.'ErrImagePull'
forJobStatus.FAILED
job that cannot pull specified image.
- description¶
Extended description for short abbreviation described by
reason
, emptystr
if no additional information is provided.
- exit_code¶
Exit code for container’s process (
int
) orNone
if the job was not started or is still running.
- transitions¶
List of job status transitions,
Sequence
ofJobStatusItem
.
JobTelemetry¶
- class neuro_sdk.JobTelemetry¶
Read-only
dataclass
for job telemetry (statistics), e.g. consumed CPU load, memory footprint etc.See also
- timestamp¶
Date and time of telemetry report (
float
), time in seconds since the epoch, like the value returned fromtime.time()
.See
time
anddatetime
for more information how to handle the timestamp.
Message¶
- class neuro_sdk.Message¶
Read-only
dataclass
for representing job’s stdout/stderr stream chunks, returned fromStdStream.read_out()
.- fileno¶
Stream number, 1 for stdin and 2 for stdout.
Resources¶
- class neuro_sdk.Resources¶
Read-only
dataclass
for describing resources (memory, CPU/GPU etc.) available for container, see alsoContainer.resources
attribute.- cpu¶
Requested number of CPUs,
float
. Please note, Docker supports fractions here, e.g.0.5
CPU means a half or CPU on the target node.
- shm¶
Use Linux shared memory or not,
bool
. ProvideTrue
if you don’t know what/dev/shm
device means.
- tpu_type¶
Requested TPU type, see also https://en.wikipedia.org/wiki/Tensor_processing_unit
- tpu_software_version¶
Requested TPU software version.
StdStream¶
- class neuro_sdk.StdStream¶
A class for communicating with attached job (
Jobs.attach()
) or exec session (Jobs.exec()
). Useread_out()
for reading from stdout/stderr andwrite_in()
for writing into stdin.
Volume¶
SecretFile¶
DiskVolume¶
Storage API Reference¶
Storage¶
- class neuro_sdk.Storage¶
Storage subsystem, available as
Client.storage
.The subsystem can be used for listing remote storage, uploading and downloading files etc.
Remote filesystem operations
- async-with async-for glob(uri: URL, *, dironly: bool = False) AsyncContextManager[AsyncIterator[URL]] [source]¶
Glob the given relative pattern uri in the directory represented by this uri, yielding all matching remote files (of any kind):
folder = yarl.URL("storage:folder/*") async with client.storage.glob(folder) as uris: async for uri in uris: print(uri)
The
“**”
pattern means “this directory and all sub-directories, recursively”. In other words, it enables recursive globbing:folder = yarl.URL("storage:folder/**/*.py") async with client.storage.glob(folder) as uris: async for uri in uris: print(uri)
- async-with async-for list(uri: URL) AsyncContextManager[AsyncIterator[FileStatus]] [source]¶
List a directory uri on the storage, e.g.:
folder = yarl.URL("storage:folder") async with client.storage.list(folder) as statuses: async for status in statuses: print(status.name, status.size)
- Parameters
uri (URL) – directory to list
- Returns
asynchronous iterator which emits
FileStatus
objects for the directory content.
- coroutine mkdir(uri: URL, *, parents: bool = False, exist_ok: bool = False) None [source]¶
Create a directory uri. Also create parent directories if parents is
True
, fail if directory exists and not exist_ok.- Parameters
uri (URL) – a path to directory for creation, e.g.
yarl.URL("storage:folder/subfolder")
.parents (bool) – create parent directories if they are not exists, raise
FileNotFound
otherwise (False
by default).exist_ok (bool) – finish successfully if directory uri already exists, raise
FileExistsError
otherwise (False
by default).
- Raises
FileExistsError
if requested directory already exists and exist_ok flag is not set.- Raises
FileNotFound
if parent directories don’t exist and parents flag is not set.
- coroutine rm(uri: URL, *, recursive: bool = False) None [source]¶
Remove remote file or directory uri.
- Parameters
- Raises
IsADirectoryError
if uri points on a directory and recursive flag is not set.
- coroutine stat(uri: URL) FileStatus [source]¶
Return information about uri.
- Parameters
uri (URL) – storage path for requested info, e.g.
yarl.URL("storage:folder/file.bin")
.- Returns
data structure for given uri,
FileStatus
object.
- coroutine disk_usage(cluster_name: Optional[str] = None, org_name: Optional[str] = None) DiskUsageInfo [source]¶
Return information about disk usage in given cluster and organization.
- Parameters
- Returns
data structure for given cluster and organization,
DiskUsageInfo
object.
File operations
- coroutine create(uri: URL, data: AsyncIterator[bytes]) None [source]¶
Create a file on storage under uri name, file it with a content from data asynchronous iterator, e.g.:
async def gen(): for i in range(10): yield str(i) * 10 file = yarl.URL("storage:folder/file.bin") source = gen() await client.storage.create(file, source) await source.aclose()
- Parameters
uri (URL) – path to created file, e.g.
yarl.URL("storage:folder/file.txt")
.data (AsyncIterator[bytes]) – asynchronous iterator used as data provider for file content.
- coroutine write(uri: URL, data: bytes, offset: int) None [source]¶
Overwrite the part of existing file on storage under uri name.
- async-with async-for open(uri: URL, offset: int = 0, size: Optional[int] = None) AsyncContextManager[AsyncIterator[bytes]] [source]¶
Get the content of remote file uri or its fragment as asynchronous iterator, e.g.:
file = yarl.URL("storage:folder/file.txt") async with client.storage.open(file) as content: async for data in content: print(data)
Copy operations
- coroutine download_dir(src: URL, dst: URL, *, update: bool = False, continue_: bool = False, filter: Optional[Callable[[str], Awaitable[bool]]] = None, progress: Optional[AbstractRecursiveFileProgress] = None) None: [source]¶
Recursively download remote directory src to local path dst.
- Parameters
src (URL) – path on remote storage to download a directory from e.g.
yarl.URL("storage:folder")
.dst (URL) – local path to save downloaded directory, e.g.
yarl.URL("file:///home/andrew/folder")
.update (bool) – if true, download only when the source file is newer than the destination file or when the destination file is missing.
continue (bool) – if true, download only the part of the source file past the end of the destination file and append it to the destination file if the destination file is newer and not longer than the source file. Otherwise download and overwrite the whole file.
filter (Callable[[str], Awaitable[bool]]) – a callback function for determining which files and subdirectories be downloaded. It is called with a relative path of file or directory and if the result is false the file or directory will be skipped.
progress (AbstractRecursiveFileProgress) – a callback interface for reporting downloading progress,
None
for no progress report (default).
- coroutine download_file(src: URL, dst: URL, *, update: bool = False, continue_: bool = False, progress: Optional[AbstractFileProgress] = None) None: [source]¶
Download remote file src to local path dst.
- Parameters
src (URL) – path on remote storage to download a file from e.g.
yarl.URL("storage:folder/file.bin")
.dst (URL) – local path to save downloaded file, e.g.
yarl.URL("file:///home/andrew/folder/file.bin")
.update (bool) – if true, download only when the source file is newer than the destination file or when the destination file is missing.
continue (bool) – if true, download only the part of the source file past the end of the destination file and append it to the destination file if the destination file is newer and not longer than the source file. Otherwise download and overwrite the whole file.
progress (AbstractFileProgress) – a callback interface for reporting downloading progress,
None
for no progress report (default).
- coroutine upload_dir(src: URL, dst: URL, *, update: bool = False, continue_: bool = False, filter: Optional[Callable[[str], Awaitable[bool]]] = None, ignore_file_names: AbstractSet[str] = frozenset(), progress: Optional[AbstractRecursiveFileProgress] = None) None: [source]¶
Recursively upload local directory src to storage URL dst.
- Parameters
src (URL) – path to uploaded directory on local disk, e.g.
yarl.URL("file:///home/andrew/folder")
.dst (URL) – path on remote storage for saving uploading directory e.g.
yarl.URL("storage:folder")
.update (bool) – if true, download only when the source file is newer than the destination file or when the destination file is missing.
continue (bool) – if true, upload only the part of the source file past the end of the destination file and append it to the destination file if the destination file is newer and not longer than the source file. Otherwise upload and overwrite the whole file.
filter (Callable[[str], Awaitable[bool]]) – a callback function for determining which files and subdirectories be uploaded. It is called with a relative path of file or directory and if the result is false the file or directory will be skipped.
ignore_file_names (AbstractSet[str]) – a set of names of files which specify filters for skipping files and subdirectories. The format of ignore files is the same as
.gitignore
.progress (AbstractRecursiveFileProgress) – a callback interface for reporting uploading progress,
None
for no progress report (default).
- coroutine upload_file(src: URL, dst: URL, *, update: bool = False, continue_: bool = False, progress: Optional[AbstractFileProgress] = None) None: [source]¶
Upload local file src to storage URL dst.
- Parameters
src (URL) – path to uploaded file on local disk, e.g.
yarl.URL("file:///home/andrew/folder/file.txt")
.dst (URL) – path on remote storage for saving uploading file e.g.
yarl.URL("storage:folder/file.txt")
.update (bool) – if true, download only when the source file is newer than the destination file or when the destination file is missing.
continue (bool) – if true, upload only the part of the source file past the end of the destination file and append it to the destination file if the destination file is newer and not longer than the source file. Otherwise upload and overwrite the whole file.
progress (AbstractFileProgress) – a callback interface for reporting uploading progress,
None
for no progress report (default).
FileStatus¶
- class neuro_sdk.FileStatus¶
Read-only
dataclass
for describing remote entry (file or directory).- modification_time¶
Modification time in seconds since the epoch, like the value returned from
time.time()
.
- type¶
Entry type,
FileStatusType
instance.
AbstractFileProgress¶
- class neuro_sdk.AbstractFileProgress¶
Base class for file upload/download progress, inherited from
abc.ABC
. User should inherit from this class and override abstract methods to get progress info fromStorage.upload_file()
andStorage.download_file()
calls.- start(data: StorageProgressStart) None [source]¶
Called when transmission of the file starts.
- Parameters
data (StorageProgressStart) – data for this event
- step(data: StorageProgressStep) None [source]¶
Called when transmission of the file progresses (more bytes are transmitted).
- Parameters
data (StorageProgressStep) – data for this event
- complete(data: StorageProgressComplete) None [source]¶
Called when transmission of the file completes.
- Parameters
data (StorageProgressComplete) – data for this event
AbstractRecursiveFileProgress¶
- class neuro_sdk.AbstractRecursiveFileProgress¶
Base class for recursive file upload/download progress, inherited from
AbstractFileProgress
. User should inherit from this class and override abstract methods to get progress info fromStorage.upload_dir()
andStorage.download_dir()
calls.- enter(data: StorageProgressEnterDir) None [source]¶
Called when recursive process enters directory.
- Parameters
data (StorageProgressComplete) – data for this event
- leave(data: StorageProgressLeaveDir) None [source]¶
Called when recursive process leaves directory. All files in that directory are now transmitted.
- Parameters
data (StorageProgressLeaveDir) – data for this event
- fail(data: StorageProgressFail) None [source]¶
Called when recursive process fails. It can happen because of touching special file (like block device file) or some other reason. Check data.message to get error details.
- Parameters
data (StorageProgressFail) – data for this event
AbstractDeleteProgress¶
- class neuro_sdk.AbstractDeleteProgress¶
Base class for file/directory delete progress, inherited from
abc.ABC
. User should inherit from this class and override abstract methods to get progress info fromStorage.rm()
calls.- delete(data: StorageProgressDelete) None [source]¶
Called when single item (either file or directory) was deleted. Directory removal happens after removal of all files and subdirectories is contains.
- Parameters
data (StorageProgressDelete) – data for this event
StorageProgress event classes¶
- class neuro_sdk.StorageProgressStart¶
- class neuro_sdk.StorageProgressStep¶
- class neuro_sdk.StorageProgressComplete¶
- class neuro_sdk.StorageProgressEnterDir¶
- class neuro_sdk.StorageProgressLeaveDir¶
- class neuro_sdk.StorageProgressFail¶
DiskUsageInfo¶
Images API Reference¶
Images¶
- class neuro_sdk.Images¶
Docker image subsystem.
Used for pushing docker images onto Neuro docker registry for later usage by
Jobs.run()
and pulling these images back to local docker.- coroutine push(local: LocalImage, remote: Optional[RemoteImage] = None, *, progress: Optional[AbstractDockerImageProgress] = None) RemoteImage [source]¶
Push local docker image to remote side.
- Parameters
local (LocalImage) – a spec of local docker image (e.g. created by
docker build
) for pushing on Neuro Registry.remote (RemoteImage) – a spec for remote image on Neuro Registry. Calculated from local image automatically if
None
(default).progress (AbstractDockerImageProgress) – a callback interface for reporting pushing progress,
None
for no progress report (default).
- Returns
remote image if explicitly specified, calculated remote image if remote is
None
(RemoteImage
)
- coroutine pull(remote: Optional[RemoteImage] = None, local: LocalImage, *, progress: Optional[AbstractDockerImageProgress] = None) RemoteImage [source]¶
Pull remote image from Neuro registry to local docker side.
- Parameters
remote (RemoteImage) – a spec for remote image on Neuro registry.
local (LocalImage) – a spec of local docker image to pull. Calculated from remote image automatically if
None
(default).progress (AbstractDockerImageProgress) – a callback interface for reporting pulling progress,
None
for no progress report (default).
- Returns
local image if explicitly specified, calculated remote image if local is
None
(LocalImage
)
- coroutine digest(image: RemoteImage) str [source]¶
Get digest of an image in Neuro registry.
- Parameters
image (RemoteImage) – a spec for remote image on Neuro registry.
- Returns
string representing image digest
- coroutine rm(image: RemoteImage, digest: str) str [source]¶
Delete remote image specified by given reference and digest from Neuro registry.
- Parameters
image (RemoteImage) – a spec for remote image on Neuro registry.
digest (str) – remote image digest, which can be obtained via digest method.
- coroutine list(cluster_name: Optional[str] = None) List[RemoteImage] [source]¶
List images on Neuro registry available to the user.
- Parameters
cluster_name (str) –
name of the cluster.
None
means the current cluster (default).- Returns
list of remote images not including tags (
List[RemoteImage]
)
- coroutine tags(image: RemoteImage) List[RemoteImage] [source]¶
List image references with tags for the specified remote image.
- Parameters
image (RemoteImage) – a spec for remote image without tag on Neuro registry.
- Returns
list of remote images with tags (
List[RemoteImage]
)
- coroutine size(image: RemoteImage) int [source]¶
Return image size.
- Parameters
image (RemoteImage) – a spec for remote image with tag on Neuro registry.
- Returns
remote image size in bytes
- coroutine tag_info(image: RemoteImage) Tag [source]¶
Return info about specified tag.
- Parameters
image (RemoteImage) – a spec for remote image with tag on Neuro registry.
- Returns
tag information (name and size) (
Tag
)
AbstractDockerImageProgress¶
- class neuro_sdk.AbstractDockerImageProgress¶
Base class for image operations progress, e.g.
Images.pull()
andImages.push()
. Inherited fromabc.ABC
.- pull(data: ImageProgressPull) None [source]¶
Pulling image from remote Neuro registry to local Docker is started.
- Parameters
data (ImageProgressPull) – additional data, e.g. local and remote image objects.
- push(data: ImageProgressPush) None [source]¶
Pushing image from local Docker to remote Neuro registry is started.
- Parameters
data (ImageProgressPush) – additional data, e.g. local and remote image objects.
- step(data: ImageProgressStep) None [source]¶
Next step in image transfer is performed.
- Parameters
data (ImageProgressStep) – additional data, e.g. image layer id and progress report.
ImageProgressPull¶
- class neuro_sdk.ImageProgressPull¶
Read-only
dataclass
for pulling operation report.- src¶
Source image,
RemoteImage
instance.
- dst¶
Destination image,
LocalImage
instance.
- class neuro_sdk.ImageProgressPush¶
Read-only
dataclass
for pulling operation report.- src¶
Source image,
LocalImage
instance.
- dst¶
Destination image,
RemoteImage
instance.
LocalImage¶
RemoteImage¶
- class neuro_sdk.RemoteImage¶
Read-only
dataclass
for describing image in remote registry (Neuro Platform hosted or other registries like DockerHub).- owner¶
User name (
str
) of a person who manages this image.Public DockerHub images (e.g.
"ubuntu:latest"
) have no owner, the attribute isNone
.
- org_name¶
Name (
str
) of an organization who manages this image or None if there is no such org.Public DockerHub images (e.g.
"ubuntu:latest"
) have no org, the attribute isNone
.
- registry¶
- as_docker_url(with_scheme: bool = False) str [source]¶
URL that can be used to reference this image with Docker.
- Parameters
with_scheme (bool) – if set to True, returned URL includes scheme (https://), otherwise (default behavior) - scheme is omitted.
- with_tag(tag: bool) RemoteImage ¶
Creates a new reference to remote image with tag.
- Parameters
tag (str) – new tag
- Returns
remote image with tag
- classmethod new_neuro_image(name: str, registry: str, *, owner: str, cluster_name: str, tag: Optional[str] = None) RemoteImage [source]¶
Create a new instance referring to an image hosted on Neuro Platform.
Users API Reference¶
Users¶
- class neuro_sdk.Users¶
User management subsystem, available as
Client.users
.- coroutine get_acl(user: str, scheme: Optional[str] = None, *, uri: Optional[URL] = None) Sequence[Permission] [source]¶
Get a list of permissions for user.
- Parameters
user (str) – user name of person whom permissions are retrieved.
scheme (str) – a filter to fetch permissions for specified URI scheme only, e.g.
"job"
or"storage"
. Passing scheme is equivalent to passinguri=scheme + ":"
.uri (URL) – a filter to fetch permissions for specified URI prefix only, e.g.
URL("job:")
orURL("storage://mycluster/myname/mydir")
. You should specify full URI.
- Returns
a
typing.Sequence
ofPermission
objects. Consider the return type as immutable list.
Get resources shared with user by others.
- Parameters
user (str) – user name of person whom shares are retrieved.
scheme (str) – a filter to fetch shares for specified URI scheme only, e.g.
"job"
or"storage"
. Passing scheme is equivalent to passinguri=scheme + ":"
.uri (URL) – a filter to fetch permissions for specified URI prefix only, e.g.
"job:"
or"storage://mycluster/myname/mydir"
. You should specify full URI.
- Returns
a
typing.Sequence
ofShare
objects. Consider the return type as immutable list.
- coroutine get_subroles(user: str) Sequence[str] [source]¶
Get subroles of given user.
- Parameters
user (str) – user name of person whom subroles are retrieved.
- Returns
a
typing.Sequence
ofstr
objects. Consider the return type as immutable list.
Share a resource specified by permission with user.
- Parameters
user (str) – user name to share a resource with.
permission (Permission) – a new permission to add.
- coroutine revoke(user: str, uri: URL) None [source]¶
Revoke all permissions for a resource specified by uri from user.
- Parameters
user (str) – user name to revoke a resource from.
uri (URL) – a resource to revoke.
Action¶
Permission¶
Secrets API Reference¶
Secrets¶
- class neuro_sdk.Secrets¶
Secured secrets subsystems. Secrets can be passed as mounted files and environment variables into a running job.
- async-with async-for list(cluster_name: Optional[str] = None, org_name: Optional[str] = None) AsyncContextManager[AsyncIterator[Secret]] [source]¶
List user’s secrets, async iterator. Yields
Secret
instances.
- coroutine add(key: str, value: bytes, cluster_name: Optional[str] = None, org_name: Optional[str] = None) None [source]¶
Add a secret with name key and content value.
Secret¶
- class neuro_sdk.Secret¶
Read-only
dataclass
for describing secret instance.
Disks API Reference¶
Disks¶
- class neuro_sdk.Disks¶
Persistent disks subsystems. Disks can be passed as mounted volumes into a running job.
- async-for list(cluster_name: Optional[str] = None) AsyncContextManager[AsyncIterator[Disk]] [source]¶
List user’s disks, async iterator. Yields
Disk
instances.- Parameters
cluster_name (str) – cluster to list disks. Default is current cluster.
- coroutine create(storage: int, life_span: Optional[datetime.timedelta], name: Optional[str], cluster_name: Optional[str] = None, org_name: Optional[str] = None) Disk [source]¶
Create a disk with capacity of storage bytes.
- Parameters
storage (int) – storage capacity in bytes.
life_span (Optional[datetime.timedelta]) – Duration of no usage after which disk will be deleted.
None
means no limit.name (Optional[str]) – Name of the disk. Should be unique among all user’s disk.
cluster_name (str) – cluster to create a disk. Default is current cluster.
org_name (str) – org to create a disk. Default is current org.
- Returns
Newly created disk info (
Disk
)
Disk¶
- class neuro_sdk.Disk¶
Read-only
dataclass
for describing persistent disk instance.- used_bytes¶
The amount of used bytes on disk,
int
orNone
if this information is not available. Note that this field is updated periodically, so it can contain incorrect data.
- status¶
Current disk status,
Disk.Status
.
Disk.Status¶
- class Disk.Status[source]¶
Enumeration that describes disk status.
Can be one of the following values:
- PENDING¶
Disk is still creating. It can be attached to job, but job will not start until disk is created.
- READY¶
Disk is created and ready to use.
- BROKEN¶
Disk is broken and cannot be used anymore. Can happen if underneath storage device was destroyed.
ServiceAccounts API Reference¶
ServiceAccounts¶
- class neuro_sdk.ServiceAccounts¶
Service accounts subsystems. Service accounts can be used to generate tokens that can be used in automated environments by third-party services.
- async-with async-for list() AsyncContextManager[AsyncIterator[ServiceAccount]] [source]¶
List user’s service accounts, async iterator. Yields
ServiceAccount
instances.
- coroutine create(name: Optional[str], default_cluster: Optional[str]) Tuple[ServiceAccount, str] [source]¶
Create a service account.
- Parameters
- Returns
Pair of newly created service account info and token. This is the only way to get token of a service account.
- coroutine get(id_or_name: str) ServiceAccount [source]¶
Get a service account with id or name id_or_name.
- Parameters
id_or_name (str) – service account’s id or name.
- Returns
Service account info (
ServiceAccount
)
ServiceAccount¶
- class neuro_sdk.ServiceAccount¶
Read-only
dataclass
for describing service account instance.- role¶
Authorization role this service account is based on.
- name¶
The service account name set by user, unique among all user’s service accounts,
str
orNone
if no name was set.
- role_deleted¶
True
if corresponding role was deleted, otherwiseFalse
.
Buckets API Reference¶
Buckets¶
- class neuro_sdk.Buckets¶
Blob storage buckets subsystems, available as
Client.buckets
.The subsystem helps take advantage of many basic functionality of Blob Storage solutions different cloud providers support. For AWS it would be S3, for GCP - Cloud Storage, etc.
- async-for list(cluster_name: Optional[str] = None) AsyncContextManager[AsyncIterator[Bucket]] [source]¶
List user’s buckets, async iterator. Yields
Bucket
instances.- Parameters
cluster_name (str) – cluster to list buckets. Default is current cluster.
- coroutine create(name: Optional[str], cluster_name: Optional[str] = None, org_name: Optional[str] = None) Bucket [source]¶
Create a new bucket.
- coroutine import_external(provider: Bucket.Provider, provider_bucket_name: str, credentials: Mapping[str, str], name: Optional[str] = None, cluster_name: Optional[str] = None, org_name: Optional[str] = None) Bucket [source]¶
Import a new bucket.
- Parameters
provider (Bucket.Provider) – Provider type of imported bucket.
provider_bucket_name (str) – Name of external bucket inside the provider.
credentials (Mapping[str, str]) – Raw credentials to access bucket provider.
name (Optional[str]) – Name of the bucket. Should be unique among all user’s bucket.
cluster_name (str) – cluster to import a bucket. Default is current cluster.
org_name (str) – org to import a bucket. Default is current org.
- Returns
Newly imported bucket info (
Bucket
)
- coroutine get(bucket_id_or_name: str, cluster_name: Optional[str] = None, bucket_owner: Optional[str) = None) Bucket [source]¶
Get a bucket with id or name bucket_id_or_name.
- coroutine rm(bucket_id_or_name: str, cluster_name: Optional[str] = None, bucket_owner: Optional[str) = None) None [source]¶
Delete a bucket with id or name bucket_id_or_name.
- coroutine request_tmp_credentials(bucket_id_or_name: str, cluster_name: Optional[str] = None, bucket_owner: Optional[str) = None) BucketCredentials [source]¶
Get a temporary provider credentials to bucket with id or name bucket_id_or_name.
- Parameters
- Returns
Bucket credentials info (
BucketCredentials
)
- coroutine set_public_access(bucket_id_or_name: str, public_access: bool, cluster_name: Optional[str] = None, bucket_owner: Optional[str) = None) Bucket [source]¶
Enable or disable public (anonymous) read access to bucket.
- Parameters
- Returns
Bucket info (
Bucket
)
- coroutine head_blob(bucket_id_or_name: str, key: str, cluster_name: Optional[str] = None, bucket_owner: Optional[str) = None) BucketEntry [source]¶
Look up the blob and return it’s metadata.
- Parameters
- Returns
BucketEntry
object.- Raises
ResourceNotFound
if key does not exist.
- coroutine put_blob(bucket_id_or_name: str, key: str, body: Union[AsyncIterator[bytes], bytes], cluster_name: Optional[str] = None, bucket_owner: Optional[str) = None, ) None [source]¶
Create or replace blob identified by
key
in the bucket, e.g:large_file = Path("large_file.dat") size = large_file.stat().st_size file_md5 = await calc_md5(large_file) async def body_stream(): with large_file.open("r") as f: for line in f: yield f await client.buckets.put_blob( bucket_id_or_name="my_bucket", key="large_file.dat", body=body_stream, )
- Parameters
bucket_id_or_name (str) – bucket’s id or name.
key (str) – Key of the blob.
body (bytes) – Body of the blob. Can be passed as either
bytes
or as anAsyncIterator[bytes]
.cluster_name (str) – cluster to look for a bucket. Default is current cluster.
bucket_owner (str) – bucket owner’s username. Used only if looking up for bucket by it’s name. Default is current user.
- coroutine fetch_blob(bucket_id_or_name: str, key: str, offset: int = 0, cluster_name: Optional[str] = None, bucket_owner: Optional[str) = None) AsyncIterator[bytes] [source]¶
Look up the blob and return it’s body content only. The content will be streamed using an asynchronous iterator, e.g.:
async with client.buckets.fetch_blob("my_bucket", key="file.txt") as content: async for data in content: print("Next chunk of data:", data)
- Parameters
bucket_id_or_name (str) – bucket’s id or name.
key (str) – Key of the blob.
offset (int) – Position in blob from which to read.
cluster_name (str) – cluster to look for a bucket. Default is current cluster.
bucket_owner (str) – bucket owner’s username. Used only if looking up for bucket by it’s name. Default is current user.
- coroutine delete_blob(bucket_id_or_name: str, key: str, cluster_name: Optional[str] = None, bucket_owner: Optional[str) = None) None [source]¶
Remove blob from the bucket.
- coroutine list_blobs(uri: URL, recursive: bool = False, limit: int = 10000) AsyncContextManager[AsyncIterator[BucketEntry]] [source]¶
List blobs in the bucket. You can filter by prefix and return results similar to a folder structure if
recursive=False
is provided.- Parameters
uri (URL) – URL that specifies bucket and prefix to list blobs, e.g.
yarl.URL("blob:bucket_name/path/in/bucket")
.bool (recursive) – If
True
listing will contain all keys filtered by prefix, while withFalse
only ones up to next/
will be returned. To indicate missing keys, all that were listed will be combined under a common prefix and returned asBlobCommonPrefix
.int (limit) – Maximum number of
BucketEntry
objects returned.
- coroutine glob_blobs(uri: URL) AsyncContextManager[AsyncIterator[BucketEntry]] [source]¶
Glob search for blobs in the bucket:
async with client.buckets.glob_blobs( uri=URL("blob:my_bucket/folder1/**/*.txt") ) as blobs: async for blob in blobs: print(blob.key)
Similar to
Storage.glob()
the“**”
pattern means “this directory and all sub-directories, recursively”.- Parameters
uri (URL) – URL that specifies bucket and pattern to glob blobs, e.g.
yarl.URL("blob:bucket_name/path/**/*.bin")
.
- coroutine upload_file(src: URL, dst: URL, *, update: bool = False, progress: Optional[AbstractFileProgress] = None) None: [source]¶
Similarly to
Storage.upload_file()
, allows to upload local file src to bucket URL dst.- Parameters
src (URL) – path to uploaded file on local disk, e.g.
yarl.URL("file:///home/andrew/folder/file.txt")
.dst (URL) – URL that specifies bucket and key to upload file e.g.
yarl.URL("blob:bucket_name/folder/file.txt")
.update (bool) – if true, upload only when the source file is newer than the destination file or when the destination file is missing.
progress (AbstractFileProgress) – a callback interface for reporting uploading progress,
None
for no progress report (default).
- coroutine download_file(src: URL, dst: URL, *, update: bool = False, continue_: bool = False, progress: Optional[AbstractFileProgress] = None) None: [source]¶
Similarly to
Storage.download_file()
, allows to download remote file src to local path dst.- Parameters
src (URL) – URL that specifies bucket and blob key to download e.g.
yarl.URL("blob:bucket_name/folder/file.bin")
.dst (URL) – local path to save downloaded file, e.g.
yarl.URL("file:///home/andrew/folder/file.bin")
.update (bool) – if true, download only when the source file is newer than the destination file or when the destination file is missing.
continue (bool) – if true, download only the part of the source file past the end of the destination file and append it to the destination file if the destination file is newer and not longer than the source file. Otherwise download and overwrite the whole file.
progress (AbstractFileProgress) – a callback interface for reporting downloading progress,
None
for no progress report (default).
- coroutine upload_dir(src: URL, dst: URL, *, update: bool = False, filter: Optional[Callable[[str], Awaitable[bool]]] = None, ignore_file_names: AbstractSet[str] = frozenset(), progress: Optional[AbstractRecursiveFileProgress] = None) None: [source]¶
Similarly to
Storage.upload_dir()
, allows to recursively upload local directory src to Blob Storage URL dst.- Parameters
src (URL) – path to uploaded directory on local disk, e.g.
yarl.URL("file:///home/andrew/folder")
.dst (URL) – path on Blob Storage for saving uploading directory e.g.
yarl.URL("blob:bucket_name/folder/")
.update (bool) – if true, download only when the source file is newer than the destination file or when the destination file is missing.
filter (Callable[[str], Awaitable[bool]]) – a callback function for determining which files and subdirectories be uploaded. It is called with a relative path of file or directory and if the result is false the file or directory will be skipped.
ignore_file_names (AbstractSet[str]) – a set of names of files which specify filters for skipping files and subdirectories. The format of ignore files is the same as
.gitignore
.progress (AbstractRecursiveFileProgress) – a callback interface for reporting uploading progress,
None
for no progress report (default).
- coroutine download_dir(src: URL, dst: URL, *, update: bool = False, continue_: bool = False, filter: Optional[Callable[[str], Awaitable[bool]]] = None, progress: Optional[AbstractRecursiveFileProgress] = None) None: [source]¶
Similarly to
Storage.download_dir()
, allows to recursively download remote directory src to local path dst.- Parameters
src (URL) – path on Blob Storage to download a directory from e.g.
yarl.URL("blob:bucket_name/folder/")
.dst (URL) – local path to save downloaded directory, e.g.
yarl.URL("file:///home/andrew/folder")
.update (bool) – if true, download only when the source file is newer than the destination file or when the destination file is missing.
continue (bool) – if true, download only the part of the source file past the end of the destination file and append it to the destination file if the destination file is newer and not longer than the source file. Otherwise download and overwrite the whole file.
filter (Callable[[str], Awaitable[bool]]) – a callback function for determining which files and subdirectories be downloaded. It is called with a relative path of file or directory and if the result is false the file or directory will be skipped.
progress (AbstractRecursiveFileProgress) – a callback interface for reporting downloading progress,
None
for no progress report (default).
- coroutine blob_is_dir(uri: URL) bool [source]¶
Check weather uri specifies a “folder” blob in a bucket.
- Parameters
src (URL) – URL that specifies bucket and blob key e.g.
yarl.URL("blob:bucket_name/folder/sub_folder")
.
- coroutine blob_rm(uri: URL, *, recursive: bool = False, progress: Optional[AbstractDeleteProgress] = None) None [source]¶
Remove blobs from bucket.
- Parameters
uri (URL) – URL that specifies bucket and blob key e.g.
yarl.URL("blob:bucket_name/folder/sub_folder")
.recursive (bool) – remove a directory recursively with all nested files and folders if
True
(False
by default).progress (AbstractDeleteProgress) – a callback interface for reporting delete progress,
None
for no progress report (default).
- Raises
IsADirectoryError
if uri points on a directory and recursive flag is not set.
- coroutine make_signed_url(uri: URL, expires_in_seconds: int = 3600) URL [source]¶
Generate a singed url that allows temporary access to blob.
- coroutine get_disk_usage(bucket_id_or_name: str, cluster_name: Optional[str] = None, bucket_owner: Optional[str) = None) AsyncContextManager[AsyncIterator[BucketUsage]] [source]¶
Get disk space usage of a given bucket. Iterator yield partial results as calculation for the whole bucket can take time.
- async-for persistent_credentials_list(cluster_name: Optional[str] = None) AsyncContextManager[AsyncIterator[PersistentBucketCredentials]] [source]¶
List user’s bucket persistent credentials, async iterator. Yields
PersistentBucketCredentials
instances.- Parameters
cluster_name (str) – cluster to list persistent credentials. Default is current cluster.
- coroutine persistent_credentials_create(bucket_ids: Iterable[str], name: Optional[str], read_only: Optional[bool] = False, cluster_name: Optional[str] = None) PersistentBucketCredentials [source]¶
Create a new persistent credentials for given set of buckets.
- Parameters
bucket_ids (Iterable[str]) – Iterable of bucket ids to create credentials for.
name (Optional[str]) – Name of the persistent credentials. Should be unique among all user’s bucket persistent credentials.
read_only (str) – Allow only read-only access using created credentials.
False
by default.cluster_name (str) – cluster to create a persistent credentials. Default is current cluster.
- Returns
Newly created credentials info (
PersistentBucketCredentials
)
- coroutine persistent_credentials_get(credential_id_or_name: str, cluster_name: Optional[str] = None) PersistentBucketCredentials [source]¶
Get a persistent credentials with id or name credential_id_or_name.
- Parameters
- Returns
Credentials info (
PersistentBucketCredentials
)
Bucket¶
- class neuro_sdk.Bucket¶
Read-only
dataclass
for describing single bucket.- provider¶
Blob storage provider this bucket belongs to,
Bucket.Provider
.
BucketCredentials¶
Bucket.Provider¶
PersistentBucketCredentials¶
- class neuro_sdk.PersistentBucketCredentials¶
Read-only
dataclass
for describing persistent credentials to some set of buckets created after user request.- name¶
The credentials name set by user, unique among all user’s bucket credentials,
str
orNone
if no name was set.
- credentials¶
List of per bucket credentials,
List[BucketCredentials]
BucketEntry¶
- class neuro_sdk.BucketEntry¶
An abstract class
dataclass
for describing bucket contents entries.- created_at¶
Blob creation timestamp,
datetime
orNone
if underlying blob engine do not store such information
BlobObject¶
- class neuro_sdk.BlobObject¶
An ancestor of
BucketEntry
used for key that are present directly in underlying blob storage.
BlobCommonPrefix¶
- class neuro_sdk.BlobCommonPrefix¶
An ancestor of
BucketEntry
for describing common prefixes for blobs in non-recursive listing. You can treat it as a kind of folder on Blob Storage.
BucketUsage¶
Parser Reference¶
Parser¶
- class neuro_sdk.Parser¶
A set of parsing helpers, useful for building helper dataclasses from string representations.
- volume(volume: str) Volume [source]¶
Parse volume string into
Volume
object.The string is a three fields separated by colon characters (
:
):<storage-uri:container-path[:ro]>
.storage-uri is a URL on local storage, e.g.
storage:folder
points on<user-root>/folder
directory.container-path is a path inside a job where storage-url is mounted.
Optional ro means that storage-url is mounted in read-only mode. Writable mode is used if ro is omitted.
- Raise
ValueError
if volume has invalid format.
- local_image(image: str) LocalImage [source]¶
Parse image string into
LocalImage
.The string should fit to the following pattern:
name[:tag]
, e.g."ubuntu:latest"
.- Raise
ValueError
if image has invalid format.
- remote_image(image: str) RemoteImage [source]¶
Parse image string into
RemoteImage
.The string should fit to
name[:tag]
orimage:name[tag]
patterns, e.g."ubuntu:latest"
orimage:my-image:latest
. The former is used for public DockerHub images, the later is for Neuro image registry.- Raise
ValueError
if image has invalid format.
- envs(env: Sequence[str], env_file: Sequence[str] = ()) EnvParseResult [source]¶
Parse a sequence of env variables and a sequence of env_file file names.
- Parameters
env (Sequence[str]) – Sequence of env variable specification. Each element can be either: - ENV_NAME. Current system env variable value will be used. Defaults to empty string. - ENV_NAME=VALUE. Given value will be used.
env_file (Sequence[str]) – Sequence of
.env
files to use. File content processed same way as env parameter.
- Returns
EnvParseResult
with parsing result
- volumes(volume: Sequence[str]) VolumeParseResult [source]¶
Parse a sequence of volume definition into a tuple of three mappings - first one for all regular volumes, second one for volumes using secrets and third for disk volumes.
- Parameters
env (Sequence[str]) – Sequence of volumes specification. Each element can be either: - STORAGE_URI:MOUNT_PATH:RW_FLAG. - SECRET_URI:MOUNT_PATH. - DISK_URI:MOUNT_PATH:RW_FLAG.
- Returns
VolumeParseResult
with parsing result
- str_to_uri(uri: str, *, allowed_schemes: Iterable[str] = (), cluster_name: Optional[str] = None, short: bool = False) URL [source]¶
Parse a string into normalized
URL
for future usage by SDK methods.- Parameters
uri (str) – an URI (
'storage:folder/file.txt'
) or local file path ('/home/user/folder/file.txt'
) to parse.allowed_schemes (Iterable[str]) – an iterable of accepted URI schemes, e.g.
('file', 'storage')
. No scheme check is performed by default.cluster_name (Optional[str]) – optional cluster name, the default cluster is used if not specified.
short (bool) – if
True
, return short URL (without cluster and user names if possible).False
by default.
- Returns
URL
with parsed URI.- Raises
ValueError – if
uri
is invalid or provides a scheme not enumerated byallowed_schemes
argument.
- uri_to_path(uri: URL, *, cluster_name: Optional[str] = None) Path [source]¶
-
- Raises
ValueError – if
uri
has no'file:'
scheme.
- normalize_uri(uri: URL, *, allowed_schemes: Iterable[str] = (), cluster_name: Optional[str] = None, short: bool = False) URL [source]¶
Normalize
uri
according to current user name, cluster and allowed schemes.Normalized form has two variants:
Long form: cluster and user names are always present, e.g. storage://cluster/user/dir/file.txt.
Short form: cluster and user are omitted if they are equal to default values given from client.config.cluster_name and client.config.username, e.g. storage:dir/file.txt.
- Parameters
uri (URL) – an URI to normalize.
allowed_schemes (Iterable[str]) – an iterable of accepted URI schemes, e.g.
('file', 'storage')
. No scheme check is performed by default.cluster_name (Optional[str]) – optional cluster name, the default cluster is used if not specified.
short (bool) – if
True
, return short URL (without cluster and user names if possible).False
by default.
- Returns
URL
with normalized URI.- Raises
ValueError – if
uri
is invalid or provides a scheme not enumerated byallowed_schemes
argument.
EnvParseResult¶
VolumeParseResult¶
Plugins API Reference¶
PluginManager¶
- class neuro_sdk.PluginManager¶
Allows plugins to register their features. Provided to neuro_api entrypoint (check https://packaging.python.org/specifications/entry-points/ for more info about entry points).
- config¶
Define new user config parameters
ConfigBuilder
.
ConfigBuilder¶
- class neuro_sdk.ConfigBuilder¶
Helper class that contains methods to define new user config variables (check
Config.get_user_config()
).- define_int(section: str, name: str) None [source]¶
Define new integer config parameter with given name in given section
- define_bool(section: str, name: str) None [source]¶
Define new bool config parameter with given name in given section
- define_float(section: str, name: str) None [source]¶
Define new float config parameter with given name in given section
- define_str(section: str, name: str) None [source]¶
Define new string config parameter with given name in given section
- define_int_list(section: str, name: str) None [source]¶
Define new integer list config parameter with given name in given section
- define_bool_list(section: str, name: str) None [source]¶
Define new bool list config parameter with given name in given section
Glossary¶
- CLI¶
Command line interface, a text interface program executed from a terminal (bash, cmd.exe, PowerShell, zsh etc.)
- tty¶
A mode when local terminal is connected to remote shell executed in a job. Any key pressed by user is sent to remote shell, any print to a screen from remote shell is displayed on local terminal.