Skip to main content

Python package for Nexthink API

Project description

Python Nexthink

This Python library provides a small client for the Nexthink API.

Installation

pip install nexthink_api
# or
uv add nexthink_api

Source And Documentation

Quickstart

The recommended entrypoint for new code is NexthinkClient. The historical NxtApiClient remains available as a compatibility facade.

The examples below assume these environment variables are set:

export nexthink_tenant="your-tenant-name"
export nexthink_region="eu"
export client_id="your-client-id"
export client_secret="your-client-secret"

When running behind a corporate proxy with TLS inspection, for example Zscaler, call enable_truststore() before creating the client. This enables the operating system trust store for Nexthink HTTP calls without permanently patching Python SSL for the whole process.

import os

from nexthink_api import NexthinkClient, NxtRegionName, enable_truststore

enable_truststore()

client = NexthinkClient(
    os.environ["nexthink_tenant"],
    NxtRegionName(os.getenv("nexthink_region", NxtRegionName.eu.value)),
    client_id=os.environ["client_id"],
    client_secret=os.environ["client_secret"],
)

NQL Execute

The NQL query must already exist in Nexthink Administration as an API query.

import os

from nexthink_api import NxtNqlApiExecuteRequest

request = NxtNqlApiExecuteRequest(
    queryId=os.environ["nexthink_nql_query_id"],
)

response = client.nql.execute(request, version="v2")
print(response.rows)
print(response.data)

Enrichment

This example updates one custom device field for one device identified by name.

import os
from datetime import datetime

from nexthink_api import (
    MAX_ENRICHMENTS_PER_REQUEST,
    NxtEnrichment,
    NxtEnrichmentRequest,
    NxtField,
    NxtFieldName,
    NxtIdentification,
    NxtIdentificationName,
)

identification = NxtIdentification(
    name=NxtIdentificationName.DEVICE_DEVICE_NAME,
    value=os.environ["nexthink_enrichment_device_name"],
)
field = NxtField(
    name=NxtFieldName.CUSTOM_DEVICE,
    custom_value="nexthink_api_example",
    value=datetime.now().isoformat(),
)
enrichments = [NxtEnrichment(identification=[identification], fields=[field])]

if len(enrichments) > MAX_ENRICHMENTS_PER_REQUEST:
    raise ValueError("Too many enrichment objects for one request")

request = NxtEnrichmentRequest(
    domain=os.getenv("nexthink_enrichment_domain", "nexthink_api_example"),
    enrichments=enrichments,
)

response = client.enrichment.run(request)
print(response)

Data Management Device Deletion

The Data Management deletion API is asynchronous and destructive. Keep an explicit confirmation in scripts and validate identifiers before calling it.

import os

from nexthink_api import NxtDeviceEntry, NxtUidValidationMode

if os.getenv("confirm_data_management_delete") != "yes":
    raise SystemExit("Set confirm_data_management_delete=yes before deleting devices.")

devices = [
    NxtDeviceEntry(
        uid=os.environ["nexthink_device_uid"],
        name=os.environ["nexthink_device_name"],
    )
]

response = client.data_management.delete_devices(
    devices=devices,
    request_id=os.environ["nexthink_request_id"],
    uid_validation=NxtUidValidationMode.WARN,
)
print(response)

Examples

Runnable examples are available in examples/:

uv run python examples/nql_query_example.py
uv run python examples/enrichment_example.py
uv run python examples/data_management_device_deletion_example.py
uv run python examples/remote_actions_example.py
uv run python examples/campaigns_example.py
uv run python examples/workflows_example.py
uv run python examples/spark_handoff_example.py

API Classes

Most request and response classes are Pydantic models. Use:

  • model_dump() to serialize to a dictionary.
  • model_dump_json() to serialize to JSON.
  • model_validate(data) to build a model from serialized data.

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

nexthink_api-0.1.3.tar.gz (183.7 kB view details)

Uploaded Source

Built Distribution

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

nexthink_api-0.1.3-py3-none-any.whl (79.6 kB view details)

Uploaded Python 3

File details

Details for the file nexthink_api-0.1.3.tar.gz.

File metadata

  • Download URL: nexthink_api-0.1.3.tar.gz
  • Upload date:
  • Size: 183.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nexthink_api-0.1.3.tar.gz
Algorithm Hash digest
SHA256 0e9ed56c80adcd3eed8ef5d4a59eb51332bfa9e2905810a01ebeaa2af4ba354f
MD5 1ae6e7cfdf724146327f2cb7ce26f64d
BLAKE2b-256 1b1a0f55291d4489a2878fb73880d0c5f864ddca4a19c7df7c69a2dfb509b64d

See more details on using hashes here.

File details

Details for the file nexthink_api-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: nexthink_api-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 79.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for nexthink_api-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 cae607aad02644db47f931eff895b05fbd5414892022a560347ecbdc4966d84b
MD5 99607eb0062cd4054d1d49938e01b693
BLAKE2b-256 b115cdd6cbf628ac928c24fcfc6f730f54e87dddb0263ab7ae3b0fffe01d1bb0

See more details on using hashes here.

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