Skip to content

About

Official Python SDK for the NodeRings API: typed sync and asyncio clients for virtual machines, DNS, firewalls, snapshots, the marketplace and more.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

noderings-python

ci live PyPI Python versions OpenSSF Scorecard License: Apache-2.0

The official Python SDK for the NodeRings API. It covers the whole public API: virtual machines, DNS, firewalls, snapshots and backups, game servers, IP address management, the marketplace, billing, access control, support tickets, and the provider side for hosts who sell on NodeRings. That is 485 operations in 69 services, all typed, with a sync and an asyncio client.

pip install noderings

Requires Python 3.10 or later. It depends on httpx and pydantic 2.

Quick start

from noderings import NodeRings
from noderings.models import Distro, DNSRecord, OperationStatus

client = NodeRings()  # reads NODERINGS_TOKEN

# Every virtual machine, page by page.
for vm in client.virtual_machine.list_virtual_machines_all():
    print(vm.hostname, vm.operation_status, vm.ipv4)

# Order a server and wait until it runs.
created = client.virtual_machine.create_virtual_machine(
    hostname="web-1",
    plan_id=plan_id,  # from client.marketplace.list_providers(...)
    region_id=region_id,
    distro=Distro.UBUNTU_26_04,
    ssh_key_ids=[ssh_key_id],
)
vm = client.wait_for_virtual_machine_status(created.virtual_machine.id, OperationStatus.STARTED)

# Give it a DNS name.
client.dns_record.upsert_dns_record(zone_id, record=DNSRecord(name="web-1", type="A", ttl=300, rdata=[vm.ipv4]))

The same with asyncio:

from noderings import AsyncNodeRings

async with AsyncNodeRings() as client:
    async for vm in client.virtual_machine.list_virtual_machines_all():
        print(vm.hostname)

examples/quickstart.py is a complete program.

Authentication

Create a service account in the NodeRings console under Organization → Access Control → Service accounts, give it the permissions your program needs, and pass its token to the client, or set NODERINGS_TOKEN. Keep the token out of source code.

Argument Environment variable Use
token NODERINGS_TOKEN The service account token. Required.
organization_id NODERINGS_ORGANIZATION_ID Act in another organization the token can access (the X-Organization-ID header). By default the token's own organization is used.
base_url NODERINGS_BASE_URL Another API endpoint. The default is https://api.noderings.com.
timeout Seconds per request, or an httpx.Timeout. Default 60. Every method also takes timeout=.
max_retries, min_backoff, max_backoff Retry count and backoff in seconds (default 3, 0.5, 10).
user_agent Add your product to the User-Agent, for example "my-app/1.2".
http_client Your own httpx.Client (or httpx.AsyncClient) for proxies or custom TLS.

Use the client as a context manager, or call close(), to release its connections. The logger noderings writes one debug line per request; tokens and bodies are never logged.

A few user-account operations (sign-in, MFA, linked identities, the OAuth authorize step) only work with a signed-in user's session, not with a service account token.

Services

Every area of the API is an attribute of the client, and every method is one API operation, named as in the API description in snake_case.

Area Attributes
Compute virtual_machine (create, start, stop, restart, reinstall, delete, tags, firewall, backups, extra IPs, console), snapshot, backup, vm_template, cloud_init_user_data, cloud_init_template, instant_app, metadata (distro catalog)
Game servers game_server (lifecycle, files, databases, backups, schedules, allocations), game_server_template
DNS dns_zone, dns_record, dnssec, domain
Network firewall (rulesets, rules, address groups), ipam
Marketplace marketplace (regions, plan codes, offers, plans), region, plan, client_provider_review
Billing subscription, addon, invoice, payment, payment_method, refund, credit, coupon, usage_report, exchange_rate
Organization and access organization, user, service_account, group, role, permission, invite, secret, environment_variable, oauth2
Monitoring monitoring, business_monitoring, metric, metrics_credential, client_dashboard
Support ticket, chat, roadmap
Providers (hosts selling on NodeRings) provider_plan, provider_storefront, provider_customer, provider_dashboard, provider_dashboard_plans_tab, provider_review, provider_network, provider_connect, provider_onboarding, provider_ticket_notification, payout_configuration, payout_invoice, manual_payout, live_validation, preflight, platform, node, node_placement, agent, hook_script

For an operation the SDK does not have yet, client.request("GET", "/v1/...", query=..., body=...) sends a request with the same authentication, retries and error handling and returns the JSON.

How it works

Arguments. Path parameters are positional; query parameters and the fields of the request body are keyword arguments, so your editor completes them. Only arguments you pass are sent, so False and 0 are sent and None is not. Nested objects can be models or plain dicts (with snake_case or camelCase keys). extra_body= and extra_query= add fields the SDK does not know yet.

Models. Every response is a pydantic model in noderings.models (also importable from noderings), with snake_case attributes and the API's camelCase names as aliases. Missing fields have their zero value ("", 0, False, []), as in the API's own JSON; nested objects, timestamps and enums are None when missing. 64-bit numbers, which the API sends as strings, are int; timestamps are datetime. model.to_dict() gives the API's JSON back.

Forward compatible. Enums are str subclasses (OperationStatus.STARTED == "OPERATION_STATUS_STARTED"), and a value this SDK version does not know is kept as a string instead of failing. Fields the API adds later are kept in model.model_extra.

Paging. List operations that take page and page_size have an ..._all variant that yields every result (an async iterator on AsyncNodeRings). It reads 100 rows per page and stops when you stop iterating.

Errors. API errors raise noderings.APIError subclasses by HTTP status: BadRequestError, AuthenticationError, PermissionDeniedError, NotFoundError, ConflictError, RateLimitError, QuotaExceededError (a plan limit such as the number of servers, with .reason like VM_LIMIT_REACHED) and InternalServerError. Each has .status_code, .code (the API's status code), .message, .details and .is_busy (another operation on the resource is still running; try again later). Network failures raise APIConnectionError and APITimeoutError.

Retries. A request is retried when the API rate-limits it (HTTP 429, unless a plan quota is used up, honoring Retry-After), and on connection errors and HTTP 502, 503 and 504 when it is safe to repeat: reads, PUT, DELETE, and creates that carry an idempotency key.

Idempotency. Creates that take an idempotency key (virtual machines, game servers) get a new UUID automatically, so a retry never orders a second server. Pass idempotency_key= yourself to retry a create safely after your program restarts.

Waiting. wait_for_virtual_machine_status, wait_for_virtual_machine_deleted and the general wait_for_virtual_machine(id, until=...) poll until a condition holds, with interval and timeout in seconds. They raise WaitTimeoutError with the last state read.

Testing

Suite What it checks
pytest Calls every one of the 485 generated methods, sync and async, against a fake API and checks the HTTP method, the path and its escaping, every query parameter's name, every body field's name and the auth headers against the API description. Also covers retries, Retry-After, errors, idempotency keys, paging, waiting, nulls, unknown enum values, and 64-bit and bytes encoding.
pytest -m live Against the real API: every read that needs no ID, checked for fields the description lacks; SSH keys, a DNS zone with records, firewall rulesets and rules, and cloud-init data created and deleted; async reads. With NODERINGS_TEST_BILLED=1, a virtual machine is created, started, stopped, started, restarted, tagged, snapshotted, given a firewall and deleted.

The live suite runs nightly in CI. See CONTRIBUTING.md.

Versioning

The SDK is generated from api/openapi.json by tools/generate.py. A weekly job fetches the published description and opens a pull request when it changed. Releases follow semantic versioning; while the version is 0.x, a minor release can rename a field when the API itself renames it, and CHANGELOG.md says so. RELEASING.md describes how a release is published.

Not included: the payment-provider webhook endpoint (it receives calls, it does not make them) and NodeRings staff-only enforcement endpoints.

Related

Go SDK · Terraform provider · Pulumi · Ansible · Apache Libcloud driver · Salt extension

License

Apache 2.0

About

Official Python SDK for the NodeRings API: typed sync and asyncio clients for virtual machines, DNS, firewalls, snapshots, the marketplace and more.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages