Metadata-Version: 2.4
Name: nebius-serverless
Version: 0.2.0
Summary: Unofficial Python client for Nebius Serverless AI: jobs, endpoints, images and tasks
Author: Mikhail Rozhkov, Evgeny Zholkovskiy
License-Expression: Apache-2.0
Project-URL: Documentation, https://mnrozhkov.github.io/nebius-serverless/
Project-URL: Repository, https://github.com/mnrozhkov/nebius-serverless
Project-URL: Issues, https://github.com/mnrozhkov/nebius-serverless/issues
Keywords: nebius,serverless,gpu,jobs,endpoints
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: nebius<0.7,>=0.6.43
Requires-Dist: pydantic<3,>=2
Requires-Dist: PyYAML>=6
Requires-Dist: rich>=13
Provides-Extra: prefect
Requires-Dist: prefect<4,>=3; extra == "prefect"
Dynamic: license-file

# nebius-serverless

[![PyPI](https://img.shields.io/pypi/v/nebius-serverless)](https://pypi.org/project/nebius-serverless/)
[![Python](https://img.shields.io/pypi/pyversions/nebius-serverless)](https://pypi.org/project/nebius-serverless/)
[![Docs](https://img.shields.io/badge/docs-mnrozhkov.github.io-3f51b5)](https://mnrozhkov.github.io/nebius-serverless/)
[![License](https://img.shields.io/badge/license-Apache--2.0-blue)](https://github.com/mnrozhkov/nebius-serverless/blob/main/LICENSE)

Unofficial Python client for Nebius Serverless AI: jobs, endpoints, images and tasks. Describe a container workload in Python or YAML, create it on a Nebius GPU or CPU, and wait for it from a script, a notebook, or CI.

> **Unofficial package.** Not an official Nebius product, and Nebius does not support it. For the official Python SDK, see [github.com/nebius/pysdk](https://github.com/nebius/pysdk). Report problems in this project's [GitHub issues](https://github.com/mnrozhkov/nebius-serverless/issues).
>
> **Beta.** 0.x releases may change the API.

<!-- --8<-- [start:install] -->
## Install

```bash
pip install nebius-serverless
```

Python 3.10 or later. It depends on `nebius>=0.6.43,<0.7`, `PyYAML>=6`, and `rich>=13`. The import name is `nebius_serverless`.

`create()` and `jobs.get()` need a Nebius CLI profile ([`nebius profile create`](https://docs.nebius.com/cli/configure)), or in CI a service account or `NEBIUS_IAM_TOKEN` ([Run in CI](https://mnrozhkov.github.io/nebius-serverless/guides/ci/)). `ns.whoami()` shows the account, and the project and region `create()` will use, without creating anything.
<!-- --8<-- [end:install] -->

<!-- --8<-- [start:job] -->
## Run a job

```python
import nebius_serverless as ns

job = ns.Job(
    command=["nvidia-smi"],
    image="nvidia/cuda:13.1.1-runtime-ubuntu24.04",
    gpu="h100",
    timeout="1h",
)
job.dry_run()  # the request as data; nothing is created
job.create()   # once; sets job.id
job.wait()
job.display()
```

Building a `Job` makes no Nebius calls. `gpu="h100"` asks Nebius for one H100, and Nebius picks the platform and preset in the project's region. On a GPU, jobs run on spot by default: cheaper, but Nebius can preempt them. Pass `pricing="on-demand"` to avoid that. `job.create()` creates the job once and returns when Nebius has accepted it. `job.wait()` polls until the job ends and prints each new state. `job.get()` fetches once, `job.cancel()` requests cancellation, and `ns.jobs.get(id)` reloads a job from a saved id. `job.dry_run()` returns the request and creates nothing. Logs are `nebius ai job logs <id>`: this library does not stream them.

To load a job from YAML, reuse it with changes, or save it, use a spec: `ns.Job(ns.JobSpec.from_yaml("job.yaml"))`. See [Specs as data](https://mnrozhkov.github.io/nebius-serverless/reference/jobs/#jobspec).
<!-- --8<-- [end:job] -->

<!-- --8<-- [start:task] -->
## Run a function as a task

```python
def count_words(text: str) -> dict[str, int]:
    """Count each word in a text. Runs in the job, so it imports there."""
    from collections import Counter

    return dict(Counter(text.split()))


count = ns.Task(count_words, image="python:3.12-slim-bookworm", timeout="10m")
print(count(text="to be or not to be"))  # runs a job, returns the dict
```

A task runs a Python function as a job and returns what it returned. Reading the result needs Object Storage credentials, and the first run creates the bucket `ns-workspace-<project id>`: see [First task](https://mnrozhkov.github.io/nebius-serverless/quickstarts/first-task/).
<!-- --8<-- [end:task] -->

<!-- --8<-- [start:endpoint] -->
## Serve an endpoint

An endpoint is a container that stays up and answers on a managed `https://` URL. It bills for compute while it runs, until you stop or delete it. On a GPU it runs on spot by default: a preemption stops it, and `endpoint.start()` runs it again.

```python
endpoint = ns.Endpoint(
    image="vllm/vllm-openai:v0.19.1",
    command=["bash", "-c", "vllm serve Qwen/Qwen3-0.6B --port 8000"],
    gpu="h100",
    port=8000,
)
endpoint.dry_run()                 # the request as data; nothing is created
endpoint.create()                  # once; sets endpoint.id and endpoint.token
endpoint.wait(probe="/v1/models")  # RUNNING, and the server answers
print(endpoint.url, endpoint.token)
endpoint.delete()
```

Endpoints require a bearer token by default: callers send `Authorization: Bearer {endpoint.token}`. A random token is generated on create, and `endpoint.reveal_token()` fetches it again later. For production, keep it in MysteryBox with `token_secret=`. `auth="none"` makes a public URL that anyone who has it can call, at your cost.
<!-- --8<-- [end:endpoint] -->

## Documentation

The documentation site is [mnrozhkov.github.io/nebius-serverless](https://mnrozhkov.github.io/nebius-serverless/):

- [Quickstarts](https://mnrozhkov.github.io/nebius-serverless/quickstarts/): install, first job, first endpoint, first image, first task, first Prefect flow, notebooks
- [Examples](https://mnrozhkov.github.io/nebius-serverless/examples/): fine-tuning with Axolotl and a parallel sweep, serving a model with vLLM, batch jobs, a pipeline of tasks, agents
- [Integrations](https://mnrozhkov.github.io/nebius-serverless/integrations/): run tasks as a Prefect flow
- [Guides](https://mnrozhkov.github.io/nebius-serverless/guides/): machines, storage, secrets, retries, CI, YAML and the CLI
- [Reference](https://mnrozhkov.github.io/nebius-serverless/reference/): every class, function, and error

The runnable scripts are in [`examples/`](https://github.com/mnrozhkov/nebius-serverless/tree/main/examples), and the pages themselves in [`docs/`](https://github.com/mnrozhkov/nebius-serverless/tree/main/docs).

## Work on the client

From a checkout, [uv](https://docs.astral.sh/uv/) installs the package with the locked dependencies (`nebius==0.6.43`, `PyYAML==6.0.3`, `rich==15.0.0`) and the test and lint tools:

```bash
uv sync
uv run pytest
uv run python examples/quickstarts/job_quickstart.py
uv run --group docs mkdocs serve   # the documentation site, locally
```

## License

Apache-2.0. Copyright 2026 Mikhail Rozhkov and Evgeny Zholkovskiy. See [LICENSE](https://github.com/mnrozhkov/nebius-serverless/blob/main/LICENSE) and [NOTICE](https://github.com/mnrozhkov/nebius-serverless/blob/main/NOTICE).
