Skip to main content

(Unofficial) Modern Python SDK for the Novita AI API

Project description

(Unofficial) Novita AI Python SDK

CI Python 3.11+ License: MIT

(Unofficial,) Modern, fully type-safe Python SDK for the Novita AI API. Built with Pydantic v2 and httpx.

Features

  • Fully Type-Safe: Complete type hints for excellent IDE support
  • Async & Sync: Both synchronous and asynchronous clients
  • Pydantic Models: Request/response validation with Pydantic v2
  • Modern Stack: Built on httpx and modern Python practices

Installation

pip install novita-sdk

Quick Start

Authentication

Set your API key as an environment variable:

export NOVITA_API_KEY="your-api-key-here"

Or pass it directly to the client:

from novita import NovitaClient

client = NovitaClient(api_key="your-api-key-here")

Synchronous Client

from novita import NovitaClient, CreateInstanceRequest, Kind

client = NovitaClient()

request = CreateInstanceRequest(
    name="my-gpu-instance",
    product_id="prod-123",  # fetch via client.gpu.products.list()
    gpu_num=1,
    rootfs_size=50,
    image_url="ubuntu:22.04",
    kind=Kind.gpu,
)
response = client.gpu.instances.create(request)
print(f"Created instance: {response.id}")

instances = client.gpu.instances.list()
for instance in instances:
    print(f"{instance.name}: {instance.status.value}")

client.close()

Asynchronous Client

import asyncio
from novita import AsyncNovitaClient, CreateInstanceRequest, Kind

async def main():
    async with AsyncNovitaClient() as client:
        request = CreateInstanceRequest(
            name="my-async-instance",
            product_id="prod-123",
            gpu_num=1,
            rootfs_size=50,
            image_url="ubuntu:22.04",
            kind=Kind.gpu,
        )
        response = await client.gpu.instances.create(request)
        print(f"Created: {response.id}")

        instance = await client.gpu.instances.get(response.id)
        print(f"Status: {instance.status.value}")

asyncio.run(main())

📚 Examples

For more detailed examples and use cases, check out the examples/ directory:

See the examples README for detailed instructions.

Advanced Usage

Context Managers

Both clients support context managers for automatic cleanup:

# Synchronous
with NovitaClient() as client:
    instances = client.gpu.instances.list()
    # Client automatically closed

# Asynchronous
async with AsyncNovitaClient() as client:
    instances = await client.gpu.instances.list()
    # Client automatically closed

Custom Configuration

client = NovitaClient(
    api_key="your-key",
    base_url="https://custom-api.novita.ai",  # Custom base URL
    timeout=120.0  # Custom timeout in seconds
)

Price Conversion

Important: The Novita API returns prices in an unusual format (units of 1/100,000 USD). This SDK automatically converts all prices to standard USD for your convenience.

For example:

  • API returns 67000 → SDK provides $0.67/hour
  • API returns 35000 → SDK provides $0.35/hour

This conversion is applied to:

  • GPUProduct.price - On-demand pricing
  • GPUProduct.spot_price - Spot instance pricing
  • SubscriptionPrice.price - Monthly subscription pricing
  • CPUProduct.price - CPU instance pricing

The raw API values are still available if needed via *_raw fields (price_raw, spot_price_raw, etc.):

products = client.gpu.products.list()
product = products[0]

print(f"Converted: ${product.price}/hour")  # e.g., $0.67/hour
print(f"Raw API value: {product.price_raw}")  # e.g., 67000
print(f"Spot (converted): ${product.spot_price}/hour")
print(f"Spot (raw): {product.spot_price_raw}")

API Resources

The SDK provides complete coverage of the Novita GPU Cloud API:

  • Instances - GPU instance lifecycle management
  • Products - GPU and CPU product listings with filtering
  • Endpoints - API endpoint management
  • Networks - VPC network configuration
  • Templates - Instance template management
  • Jobs - Job execution and control
  • Metrics - Instance performance metrics
  • Storages - Network storage management
  • Image Registry - Container registry authentication
  • Images - Image prewarm task management
  • Clusters - Available GPU cluster information

Development

Pre-commit Hooks

This project uses pre-commit hooks to ensure code quality. The hooks automatically run on every commit and check:

  • Linting - Ruff checks for code issues
  • Formatting - Ruff formats code consistently
  • Type checking - MyPy validates type hints
  • Unit tests - Fast test suite ensures no regressions
  • File checks - Trailing whitespace, end-of-file, YAML/TOML validation

Install the hooks:

make pre-commit-install

Run manually on all files:

make pre-commit-run

Skip hooks for a specific commit (use sparingly):

git commit --no-verify

Requirements

  • Python 3.11 or higher

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

novita_sdk-0.2.1.tar.gz (25.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

novita_sdk-0.2.1-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file novita_sdk-0.2.1.tar.gz.

File metadata

  • Download URL: novita_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 25.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for novita_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7925961ea4ecd4e5f37d4af266195aca0eee60b2b23d7e95c86b9bf54dc6f14c
MD5 fec7a7f1d2747735e57f7cdf8eeaf8c1
BLAKE2b-256 d897b6dc8fb37d06463b783378399ad85516b63db3c04bc35aa4f44d9118bc5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for novita_sdk-0.2.1.tar.gz:

Publisher: publish-pypi.yaml on php-workx/novita-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file novita_sdk-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: novita_sdk-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for novita_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a849a42915f408f3b9ae88531b72c5a462f162c332e6808925ce6c380a3c16d5
MD5 5ed9fb0c4b62ff27508ca097bbf5feb3
BLAKE2b-256 0617de91ede1809ec2a1718ee44855c7cd07a65b25b31977b6c86a652664a15c

See more details on using hashes here.

Provenance

The following attestation bundles were made for novita_sdk-0.2.1-py3-none-any.whl:

Publisher: publish-pypi.yaml on php-workx/novita-sdk-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page