ntopng/python
Copilot bda3c861b9
Add comprehensive unit tests for Python SDK and additional Lua ts_common tests (#10227)
- Add python/tests/test_ntopng_sdk.py with 86 unit tests covering:
  - Ntopng: constructor (auth_token / user+pass), request/post_request wrappers,
    all getter methods, debug flag, URL building
  - Interface: all data, alert, flow, L7/L4 and host methods
  - Host: get_host_data, get_l7_stats, get_dscp_stats (both directions), VLAN handling
  - Historical: all alert family delegates, timeseries, flows, conversations
- Fix bug in historical.py get_host_top_protocols(): self.ifid (int) was
  concatenated with strings without str() conversion, causing TypeError at runtime
- Add scripts/lua/modules/timeseries/tests/ts_common_test.lua with 11 test cases:
  - upsampleSerie: no-op when target <= source length, empty serie
  - calculateMinMax: basic, single element, NaN-skipping
  - calculateStatistics: counter (total*step), gauge+keep_total, gauge no-total, NaN-skipping
  - ninetififthPercentile: single element, all-NaN
- Register ts_common_test in the Lua test runner (run.lua)

Agent-Logs-Url: https://github.com/ntop/ntopng/sessions/32da23c3-306c-4100-9bbe-64b91191653b

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: lucaderi <4493366+lucaderi@users.noreply.github.com>
2026-05-10 22:22:58 +02:00
..
docs Added python API docs indexing (#7959) 2023-10-30 12:47:07 +01:00
examples Add example listing alerts 2023-02-17 18:32:46 +01:00
ntopng Add comprehensive unit tests for Python SDK and additional Lua ts_common tests (#10227) 2026-05-10 22:22:58 +02:00
tests Add comprehensive unit tests for Python SDK and additional Lua ts_common tests (#10227) 2026-05-10 22:22:58 +02:00
__init__.py.in Add logo to package. Add missing deps. 2023-01-30 12:56:17 +01:00
Makefile Update Makefile (#7003) 2022-12-12 12:29:34 +01:00
README.md Add upload instructions 2024-07-02 10:17:20 +00:00
requirements.txt Bump numpy from 1.21.5 to 1.22.0 in /python 2023-01-29 10:46:05 +00:00
setup.py.in Add logo to package. Add missing deps. 2023-01-30 12:56:17 +01:00
test.py Rework Historical class 2023-01-19 18:11:15 +01:00

Python API

This directory contains the Python 3.x API for querying ntopng using the Python language.

This API is based on ntopng's REST API and it allows users to perform operations such as:

  • Read host statistics
  • Get the active flows list
  • Query network interface stats and time series
  • Search historical data including alerts and flows

Prerequisites

The API is using Pandas and NumPy for working with time series data, plotly and fpdf for generating reports in PDF format. The examples are using additional modules, including redmail for sending reports by email.

In order to install prerequisites please do

  • pip3 install -r requirements.txt

API Information

For each ntopng REST API call there is a corresponding Python method for the defined Python classes:

The ntopng class is used to store information such as ntopng IP address and credentials used to connect it.

The test application can be used as example of the Python API

Installation

For you convenience, ntop periodically builds pip packages. You can install the latest available package as:

  • pip3 install ntopng

Developing the Python API

We encourage our users to extend this API. For your convenience we are sharing a Makefile that you can use as skeleton for installing the package locally or creating test packages.

The Makefile can be also used to update the upstream library. The build and twine modules are required.

  • pip install build twine
  • make upload

Documentation

For detailed documentation on each API class please visit:

For further information please visit the API documentation available at:

ntopng Python API ntopng REST API v2