> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ntop.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python Examples

This directory holds self-contained examples of common operations you may want to perform using nTop Core library.

The examples themselves are meant to be fully self-contained in showing how you would utilize nTop Core to perform a commonly-requested task.
This necessitates, however, a somewhat verbose preamble section in which Python-to-C-Library data marshalling and data primitive definitions are established.
It is necessary to understand these sections if you want to use functionality of nTop Core that is not covered in these examples but we recommend starting by skipping to the sections which exercise the library first to get a feel for the library's use.

## Setup

The examples have been tested to run on [Python 3.11.4](https://www.python.org/downloads/release/python-3114/) but other recent releases should function similarly.

Now create an environment variable to locate the nTop Core library file.

```shell theme={null}
# Establish the path to the nTop Core library to test if not previously set up
# via the environment variable `NTOP_CORE_LIB`. You can do this per session
# or in a .bashrc or System Environment Variable.

# In windows powershell
$env:NTOP_CORE_LIB = "c:\path\to\ntop_core.dll"
# In *nix
export NTOP_CORE_LIB="/path/to/libntop_core.so.{major}.{minor}.{patch}"
```

We have some common external dependencies in these examples, the specification is stored in `requirements.txt`.
Install them using your package manager of choice.

```shell theme={null}
# Using `pip` from this directory
pip install -r requirements.txt
```

## Running the examples

You are now ready to run any of the examples using pattern similar to the following:

```shell theme={null}
python mesh.py
```

## Example Scripts

* [Bounding Box](/Product-Documentation/ntop-core/examples/python/boundingbox) — loads an implicit body and prints the minimum/maximum corners of its axis-aligned bounding box.
* [Mesh](/Product-Documentation/ntop-core/examples/python/mesh) — samples the body's field on a voxel grid via `ntop_core_query_field_array` and reconstructs a surface mesh using scikit-image's marching cubes.
* [Mesh by Dual Contouring](/Product-Documentation/ntop-core/examples/python/mesh-by-dc) — meshes the body directly using the library's native `ntop_core_generate_mesh_by_DC` dual contouring function.
* [Slice](/Product-Documentation/ntop-core/examples/python/slice) — slices the body at 11 heights via `ntop_core_query_contours` and plots each resulting contour stack.
* [Transform and Scale](/Product-Documentation/ntop-core/examples/python/transform-and-scale) — applies a scale and a rigid transform to an implicit body and exports the results to new `.implicit` files.
