Skip to main content

Python NatNet Client

Python client for Optitrack NatNet streams.

Installation

Install this package via pip:

pip install natnet

Usage

The following example highlights the basic usage of this package:

import time

from natnet import DataDescriptions, DataFrame, NatNetClient


def receive_new_frame(data_frame: DataFrame):
    global num_frames
    num_frames += 1


def receive_new_desc(desc: DataDescriptions):
    print("Received data descriptions.")


num_frames = 0
if __name__ == "__main__":
    streaming_client = NatNetClient(server_ip_address="127.0.0.1", local_ip_address="127.0.0.1", use_multicast=False)
    streaming_client.on_data_description_received_event.handlers.append(receive_new_desc)
    streaming_client.on_data_frame_received_event.handlers.append(receive_new_frame)

    with streaming_client:
        streaming_client.request_modeldef()

        for i in range(10):
            time.sleep(1)
            streaming_client.update_sync()
            print(f"Received {num_frames} frames in {i + 1}s")

In this example, we first instantiate NatNetClient with the connection parameters and attach one callback function to each of its events. The streaming_client.on_data_description_received_event event is triggered whenever a new data description packet arrives, while the streaming_client.on_data_frame_received_event event is triggered on each incoming data frame. For the configuration of the NatNet server, please refer to the official documentation.

You can process data synchronously, as in this example, by calling streaming_client.update_sync() in your run loop. Alternatively, you can call streaming_client.run_async() once after connecting, which will handle data asynchronously in two additional threads.

We then use the streaming_client instance as a context manager, which is equivalent to calling streaming_client.connect() (and streaming_client.shutdown() afterwards). After the client has been connected, we request the model definitions from the server, which causes it to send a data description packet. Note that data frames do not have to be explicitly requested, but are continuously streamed once a connection has been established.

Apart from requesting model definitions, the NatNetClient class allows sending arbitrary commands to the NatNet server via the send_command and send_request functions. For a list of different commands and requests, please refer to the official documentations.

Notes

As of Motive version 2.3, the marker positions of rigid bodies are only transmitted correctly if "Y-up" is selected in the streaming pane. If "Z-up" is selected, the frame of the rigid bodies is rotated but the marker positions are not, resulting in wrong positions of the markers relative to the rigid body.

License

The project is licensed under the MIT license.

Contributing

If you wish to contribute to this project, you are welcome to create a pull request. Please run the pre-commit hooks before submitting your pull request. To install the pre-commit hooks, run:

  1. Install pre-commit
  2. Install the Git hooks by running pre-commit install or, alternatively, run `pre-commit run --all-files manually.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

natnet-0.3.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

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

natnet-0.3.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file natnet-0.3.0.tar.gz.

File metadata

  • Download URL: natnet-0.3.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for natnet-0.3.0.tar.gz
Algorithm Hash digest
SHA256 652b0fdc939a374e11559142cff4cfa104ec82e041c99652312c470dee7fd34b
MD5 0d492ac0ce3f7e91bc58c8522cb4271d
BLAKE2b-256 6a545a239bcb2e3bbb18615af7ed8bf67786f4751ebb81dc4d38056cb8506dc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for natnet-0.3.0.tar.gz:

Publisher: publish.yml on TimSchneider42/python-natnet-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file natnet-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: natnet-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for natnet-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 03502685885b8bdd292f74a3c4a791b21d9f90373f679e44671b52582619d0b7
MD5 92dec1b104dcda60a65033e2c352e4c0
BLAKE2b-256 d3199cc3248b9fc7c2765266a31e9d142f08dd1cccddfef3f18b77754a348546

See more details on using hashes here.

Provenance

The following attestation bundles were made for natnet-0.3.0-py3-none-any.whl:

Publisher: publish.yml on TimSchneider42/python-natnet-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.0

2 files

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