# Using Python (including Jupyter Notebook) with ntopng | ntop

[Blog](https://www.ntop.org/blog/)[ntopng](https://www.ntop.org/category/ntopng/)

# Using Python (including Jupyter Notebook) with ntopng

January 11, 20232 min read

Most programmers and network/security administrators are familiar with the Python language. As from time to time we receive requests from our users for creating custom reports, or extracting other type of data (e.g. alerts or timeseries) from ntopng, we have decided to create a Python API for ntopng. Such API allows developers to extract data from ntopng similar to what other Python APIs do (e.g. [pyshark](https://github.com/KimiNewt/pyshark) for [Wireshark](https://www.wireshark.org)).

Using this API you can

-   Read host statistics
-   Get the active flows list
-   Query network interface stats
-   Search historical flows

Those familiar with Jupyter Notebooks can also use them to interact with ntopng. You can see [this example](https://github.com/ntop/ntopng) as starting point fo your experiments.

[![](/images/2023/01/Screen-Shot-2023-01-11-at-10.26.32.webp)](https://www.ntop.org/images/2023/01/Screen-Shot-2023-01-11-at-10.26.32.webp)

Using the python API is simple. What you need is the latest ntopng dev version (any version will work) and the python APi that you can easily install with

-   `pip3 install ntopng`

Done that you can write your first application. The API is basically a wrapper around the ntopng REST API so in essence the first thing you need to do is to connect to a remote ntopng instance (using login and password, or the authentication token) and issue queries via the python API.

try:
    my\_ntopng = Ntopng(username, password, auth\_token, ntopng\_url)
    my\_historical = Historical(my\_ntopng)

    epoch\_end   = int(time.time())
    epoch\_begin = epoch\_end - 3600
    host = "28:37:37:00:6D:C8"
    ifid = 0

    print(my\_historical.get\_timeseries("mac:traffic", "ifid:"+str(ifid)+",mac:"+host, epoch\_begin, epoch\_end))

except ValueError as e:
    print(e)

Above you can find a simple example for extracting a time series of the last hour traffic of a specific MAC address. In the example below we extract historical flows from the ClickHouse database.

try:
    my\_ntopng = Ntopng(username, password, auth\_token, ntopng\_url)
    my\_historical = Historical(my\_ntopng)

    epoch\_end   = int(time.time())
    epoch\_begin = epoch\_end - 3600
    host = "192.168.1.1"
    ifid = 0
    
    select\_clause = "IPV4\_SRC\_ADDR,IPV4\_DST\_ADDR,PROTOCOL,IP\_SRC\_PORT,IP\_DST\_PORT,L7\_PROTO,L7\_PROTO\_MASTER"
    where\_clause  = "(PROTOCOL=6) AND IPV4\_SRC\_ADDR=(\\""+host+"\\")"
    maxhits       = 10 # 10 records max
    print(my\_historical.get\_flows(ifid, epoch\_begin, epoch\_end, select\_clause, where\_clause, maxhits, None, None))
except ValueError as e:
    print(e)

You can find the python API on [github](https://github.com/ntop/ntopng/tree/dev/python) as well as simple examples. Soon we will produce additional code examples and documentation that shows you how to interact with ntopng. Please let us know your feedback on the [community channels](https://www.ntop.org/support/need-help/community/) and feel free to contribute to the API with a pull request.

Enjoy !

## Keep reading

nDPINov 7, 2026

### [Detecting CVE-2026-98432 using nDPI/ntopng](https://www.ntop.org/detecting-cve-2026-98432-using-ndpi-ntopng/)

CVE-2026-98432 is a critical, 9.8-severity use-after-free (UAF) vulnerability in the Linux kernel’s IPv4 TCP networking stack. It allows an unauthenticated remote attacker to potentially cause system crashes, memory corruption, or execute arbitrary commands with root privileges. From a network stand

[![](/images/2026/09/Screenshot-2026-09-09-151028-1.webp)](https://www.ntop.org/october-20th-join-us-for-the-ntopng-7-0-webinar/)

AnnounceOct 5, 2026

### [October 20th: Join us for the ntopng 7.0 Webinar](https://www.ntop.org/october-20th-join-us-for-the-ntopng-7-0-webinar/)

Is your network monitoring keeping pace with AI, larger infrastructures, and the growing need for real observability? We’re excited to introduce ntopng 7.0, alongside new releases of the rest of the ntop…

[![](/images/2026/09/Screenshot-2026-09-09-163410-1.webp)](https://www.ntop.org/ntopng-user-interface-introducing-the-new-navigation-bar/)

ntopngSep 21, 2026

### [ntopng User Interface: Introducing the New Navigation Bar](https://www.ntop.org/ntopng-user-interface-introducing-the-new-navigation-bar/)

In our continuous effort to improve user experience and make network monitoring more intuitive, we have completely redesigned the ntopng Navigation Bar. As our feature set expands—with crucial additions like the nAnalyst…

## Try it on your own network

Download the free Community edition and see your first flows in five minutes.

[Download ntopng free](https://www.ntop.org/support/documentation/software-installation/)[Talk to an engineer](https://www.ntop.org/support/need-help/contacts/)
Source: https://www.ntop.org/using-python-including-jupyter-notebook-with-ntopng/