Skip to main content

NDTkit Python API

Python API for NDTkit License

This Python API provides a high-level interface to interact with the NDTkit desktop application. It allows developers to script and automate NDTkit features remotely, leveraging the full power of the underlying Java application through a simple and pythonic library.

📋 Prerequisites

Before using this API, you must have:

  1. Python 3.11+ installed.
  2. The NDTkit 4.1+ installed.
  3. [OPTIONAL] For developers that want to add user interface directly in NDTkit (side panel or new menu), Open JDK 21 must be installed.

⬇️ Installation & Configuration

  1. Install the library
pip install ndtkit-api
  1. Configure the connection: This library needs to connect to NDTkit's socket server. No change is needed unless you explicitly changed the NDTkit's socket server configuration. If the NDTkit software needs to be launched from this library, set NDTKIT_FILEPATH, this will automatically launch NDTkit if no socket server is detected. Here is an example on how to configure these variables:

    from ndtkit_api.config import config
    
    config.SERVER_HOST = "127.0.0.1"          # default value
    config.SERVER_PORT = 32146                # default value
    config.SERVER_CONNECTION_TIMEOUT = 120    # default value
    config.NDTKIT_FILEPATH = "C:/Program Files/NDTkit/NDTkit.vbs"
    
    • SERVER_HOST: The IP address of the machine running NDTkit. Use 127.0.0.1 if it's on the same machine.
    • SERVER_PORT: The port for the socket communication. This must match the port of the NDTkit socket server.
    • SERVER_CONNECTION_TIMEOUT: After this timeout (in seconds), the API will stop attempting to connect to NDTkit's socket server.
    • NDTKIT_FILEPATH: Your Python source code will try to launch NDTkit, using this path, if no socket server is detected.

📝 Usage Example

Here is a simple example showing how to open a C-Scan, modify a pixel, and save it to a new file.

# examples.py

from ndtkit_api import NDTKitCScanInterface, ndtkit_socket_connection
from ndtkit_api.model.frame.NICartographyFrameCScan import NICartographyFrameCScan


def change_pixel_value(input_file: str, output_file: str):
    """
    Opens a C-Scan, modifies the value of the first pixel, saves it,
    and re-opens it for display.
    """
    print(f"Opening C-Scan: {input_file}")
    # The server is launched automatically if not running
    cscan: NICartographyFrameCScan = NDTKitCScanInterface.open_cscan(input_file)

    if not cscan:
        print("Failed to open C-Scan.")
        return

    print(f"C-Scan opened successfully with UUID: {cscan.get_uuid()}")

    print("Retrieving data matrix...")
    data: list[list[float]] = cscan.get_data()
    print(f"Original value at [0][0]: {data[0][0]}")

    # Modify the data
    data[0][0] = 12.0
    print(f"Setting new value at [0][0] to 12.0")
    cscan.set_data(data)

    print(f"Saving modified C-Scan to: {output_file}")
    NDTKitCScanInterface.save_cscan(cscan, output_file)

    print("Re-opening the saved C-Scan to verify.")
    NDTKitCScanInterface.open_cscan(output_file, displayResult=True)
    print("Done.")


if __name__ == "__main__":
    ndtkit_socket_connection.launch_ndtkit() # Launch NDTkit if it is not already done
    # Make sure to use paths that are valid on your system
    input_cscan_path = "C:/Users/admin/Documents/Data/dd_carto.nkc"
    output_cscan_path = "C:/Users/admin/Documents/Data/result.nkc"
    change_pixel_value(input_cscan_path, output_cscan_path)

You can find practical usage examples for this API on the dedicated Github page.

✨ A class/method is available in the Java API but it is not appearing in this Python API

It can be reachable anyway, it's just the auto-completion of your IDE that is not working. Actually this Python API is using py4j that allows to access any Java API function. Here's an example on how to access to agi.ndtkit.api.NDTKitCScanInterface.openCScan(String) without using directly the API:

from ndtkit_api.ndtkit_socket_connection import gateway

gateway.jvm.agi.ndtkit.api.NDTKitCScanInterface.openCScan("path/to/my/cscan") # type: ignore

So please refer to the NDTkit Javadoc to have an exhaustive look at all the available actions and call them using this solution if they are not available directly in this Python API.

🛠️ CLI workflow (create / modify / deploy)

This library comes with several command lines that help you to create a new plugin. Here are the different commands that can be called:

  • ndtkit create: start a prompt that guide you for creating a new plugin

  • ndtkit modify: allows to change some configurations of the plugin (eg: ndtkit modify --port 1212)

  • ndtkit deploy: deploys your plugin so it is loaded by NDTkit. Don't forget to restart NDTkit to take the changes into account.

Note: If a .spec file matching the plugin name or the target script is detected, the script will prioritize it. This allows you to define complex build rules (like custom data inclusions, specific binary bundles, or advanced hooks) directly in the .spec file.

Note: On subsequent runs, the script will reuse the settings from build_config.json. If you need to change your configuration (e.g., to target a new version), you can simply delete this file and run ndtkit_deploy again to be re-prompted.

Metadata

Release files for ndtkit-api 0.0.32

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ndtkit-api 0.0.32
File Size Uploaded Provenance Actions
ndtkit_api-0.0.32.tar.gz 68.9 kB Without provenance Details for ndtkit_api-0.0.32.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ndtkit-api 0.0.32
File Interpreter ABI Platform Actions
ndtkit_api-0.0.32-py3-none-any.whl Python 3 none any Details for ndtkit_api-0.0.32-py3-none-any.whl

Total release size: 155.1 kB

Release files / ndtkit_api-0.0.32.tar.gz

Download URL ndtkit_api-0.0.32.tar.gz
Size 68.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ba0eb7b2e6b24cc9303010695db17fc015772d35dd381055828db5c43ee9f18c
BLAKE2b-256 checksum
How to use checksums
6a0a9482933414310fa7e197f1c83a4eeaef9325b49e98dc207c81d1ba3e4a03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / ndtkit_api-0.0.32-py3-none-any.whl

Download URL ndtkit_api-0.0.32-py3-none-any.whl
Size 86.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
89ae3d453269a746808db08e41cf6d94aa19911b25dda4b3199b07b9b45dec2a
BLAKE2b-256 checksum
How to use checksums
b78890b1ee40044097cd0f2cd90f0e6d91347207acb4cf9f5c0e24fa744163d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Security for ndtkit-api 0.0.32

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.32 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page