nebius/pysdk
Python
Captured source
source ↗nebius/pysdk
Description: Nebius Python SDK
Language: Python
License: MIT
Stars: 13
Forks: 2
Open issues: 4
Created: 2024-11-25T10:51:34Z
Pushed: 2026-06-09T12:18:46Z
Default branch: main
Fork: no
Archived: no
README:
Nebius Python® SDK
The Nebius Python® SDK is a comprehensive client library for interacting with nebius.com services. Built on gRPC, it supports all APIs defined in the Nebius API repository. This SDK simplifies resource management, authentication, and communication with Nebius services, making it a valuable tool for developers.
> Note: "Python" and the Python logos are trademarks or registered trademarks of the Python Software Foundation, used by Nebius B.V. with permission from the Foundation.
Full documentation and reference
To see all the services and their methods, look into the API reference.
Installation
pip install nebius
If you've received this module in a zip archive or checked out from git, install it as follows:
pip install ./path/to/your/pysdk
Migration from 0.2.x to 0.3.x
In version 0.3.0, we introduced a small breaking change aimed at improving the authorization process:
- Moved authorization options to direct request argument
- Removed
nebius.aio.authorization.options.options_to_metadata - Removed metadata cleanup, as it is not used
= 0.3.0:
service.request(
req,
metadata={'your':'metadata'},
auth_options={
OPTION_RENEW_REQUIRED: "true",
OPTION_RENEW_SYNCHRONOUS: "true",
OPTION_RENEW_REQUEST_TIMEOUT: ".9",
}
)Example
Working examples in src/examples. Try it out as follows:
NEBIUS_IAM_TOKEN=$(nebius iam get-access-token) python -m ./path/to/your/pysdk/src/examples/basic.py your-project-id
How-to
Initialize
from nebius.sdk import SDK sdk = SDK()
This will initialize the SDK with an IAM token from a NEBIUS_IAM_TOKEN env var. If you want to use different ways of authorization, read further.
See the following how-to's on how to provide your crerentials:
##### Initialize using an IAM Token
You can also initialize the SDK by providing the token directly or from the other environment variable, here are examples how to do that:
import os
from nebius.sdk import SDK
from nebius.aio.token.static import Bearer, EnvBearer # [1]
from nebius.aio.token.token import Token # [2]
sdk = SDK(credentials=os.environ.get("NEBIUS_IAM_TOKEN", ""))
#or
sdk = SDK(credentials=Bearer(os.environ.get("NEBIUS_IAM_TOKEN", "")))
#or
sdk = SDK(credentials=EnvBearer("NEBIUS_IAM_TOKEN"))
#or
sdk = SDK(credentials=Bearer(Token(os.environ.get("NEBIUS_IAM_TOKEN", ""))))Now, your application will get token from the local Env variable, as in the example above, but provided in several other ways.
##### Initialize using CLI config
If you've set up Nebius AI Cloud CLI, you can initialize the SDK using CLI config:
from nebius.sdk import SDK from nebius.aio.cli_config import Config sdk = SDK(config_reader=Config())
This will also import the domain if the endpoint parameter is in the config and the domain wasn't set explicitly.
*Keep in mind, that it will get the token from the NEBIUS_IAM_TOKEN environment variable if it is set, or use NEBIUS_PROFILE for selecting the profile, the same way CLI does. To stop that from happening, set Config(no_env=True)*
Config reader also helps with getting the default parent ID if necessary:
from nebius.aio.cli_config import Config
print(f"My default parent ID: {Config().parent_id}")Check the `Config` documentation for more settings like file path, profile name, metrics, or environment variables names. Config(metrics=...) receives config-reader and auth callbacks, while Config(auth_metrics=...) receives auth-only callbacks for credentials returned by the config reader. If callbacks are attached later with Config.set_metrics(...), the last recorded config load event is replayed.
##### Initialize with the private key file
If you have a private key and a service account, you may want to authorize using them. Here is an example of how to do it.
Replace in the IDs in the following example with your service account and public key ID pair, related to the private key you have. You need to have a private_key.pem file on your machine, modify the file path in the example accordingly.
from nebius.sdk import SDK from nebius.base.service_account.pk_file import Reader as PKReader # [1] sdk = SDK( credentials=PKReader( filename="location/of/your/private_key.pem", public_key_id="public-key-id", service_account_id="your-service-account-id", ), ) #or without importing PKReader: sdk = SDK( service_account_private_key_file_name="location/of/your/private_key.pem", service_account_public_key_id="public-key-id", service_account_id="your-service-account-id", )
[1]
##### Initialize with a credentials file
Assuming you have a joint credentials file with a private key and all the IDs inside.
from nebius.sdk import SDK from nebius.base.service_account.credentials_file import Reader as CredentialsReader # [1] sdk = SDK( credentials=CredentialsReader( filename="location/of/your/credentials.json", ), ) #or without importing CredentialsReader: sdk = SDK( credentials_file_name="location/of/your/credentials.json", )
[1]
Test the SDK
Now as you've initialized the SDK, you may want to test whether your credentials are ok, everything works and you have a good connection.
To test the SDK, we provide a convenient method `SDK.whoami`, that will return the basic information about the profile, you've authenticated with:
import asyncio async def my_call(): async with sdk: print(await sdk.whoami()) asyncio.run(my_call())
It is important to close the...
Excerpt shown — open the source for the full document.
Notability
notability 1.0/10Low-star routine SDK repo