NetworkTable

class ntcore.NetworkTable

Bases: pybind11_object

A network table that knows its subtable path. @ingroup ntcore_cpp_api

PATH_SEPARATOR_CHAR = '/'
add_listener(*args, **kwargs)

Overloaded function.

  1. add_listener(self: ntcore._ntcore.NetworkTable, event_mask: typing.SupportsInt | typing.SupportsIndex, listener: collections.abc.Callable[[ntcore._ntcore.NetworkTable, str, ntcore._ntcore.Event], None]) -> int

Listen to topics only within this table.

Parameters:
  • event_mask – Bitmask of EventFlags values

  • listener – listener to add

Returns:

Listener handle

  1. add_listener(self: ntcore._ntcore.NetworkTable, key: str, event_mask: typing.SupportsInt | typing.SupportsIndex, listener: collections.abc.Callable[[ntcore._ntcore.NetworkTable, str, ntcore._ntcore.Event], None]) -> int

Listen to a single key.

Parameters:
  • key – the key name

  • event_mask – Bitmask of EventFlags values

  • listener – listener to add

Returns:

Listener handle

add_sub_table_listener(listener: collections.abc.Callable[[ntcore._ntcore.NetworkTable, str, ntcore._ntcore.NetworkTable], None]) int

Listen for sub-table creation. This calls the listener once for each newly created sub-table. It immediately calls the listener for any existing sub-tables.

Parameters:

listener – listener to add

Returns:

Listener handle

static basename_key(key: str) str

Gets the “base name” of a key. For example, “/foo/bar” becomes “bar”. If the key has a trailing slash, returns an empty string.

Parameters:

key – key

Returns:

base name

clear_persistent(key: str) None

Stop making a key’s value persistent through program restarts. The key cannot be null.

Parameters:

key – the key name

contains_key(key: str) bool

Determines whether the given key is in this table.

Parameters:

key – the key to search for

Returns:

true if the table as a value assigned to the given key

contains_sub_table(key: str) bool

Determines whether there exists a non-empty subtable for this key in this table.

Parameters:

key – the key to search for

Returns:

true if there is a subtable with the key which contains at least one key/subtable of its own

get_boolean(key: str, default_value: object) object

Gets the boolean associated with the given name. If the key does not exist or is of different type, it will return the default value.

Parameters:
  • key – the key to look up

  • default_value – the value to be returned if no value is found

Returns:

the value associated with the given key or the given default value if there is no value associated with the key

get_boolean_array(key: str, default_value: object) object

Returns the boolean array the key maps to. If the key does not exist or is of different type, it will return the default value.

Parameters:
  • key – the key to look up

  • default_value – the value to be returned if no value is found

Returns:

the value associated with the given key or the given default value if there is no value associated with the key

Note

This makes a copy of the array. If the overhead of this is a concern, use GetValue() instead.

Note

The returned array is std::vector<int> instead of std::vector<bool> because std::vector<bool> is special-cased in C++. 0 is false, any non-zero value is true.

get_boolean_array_topic(name: str) ntcore._ntcore.BooleanArrayTopic

Get boolean[] topic.

Parameters:

name – topic name

Returns:

BooleanArrayTopic

get_boolean_topic(name: str) ntcore._ntcore.BooleanTopic

Get boolean topic.

Parameters:

name – topic name

Returns:

BooleanTopic

get_double_array_topic(name: str) ntcore._ntcore.DoubleArrayTopic

Get double[] topic.

Parameters:

name – topic name

Returns:

DoubleArrayTopic

get_double_topic(name: str) ntcore._ntcore.DoubleTopic

Get double topic.

Parameters:

name – topic name

Returns:

DoubleTopic

get_entry(key: str) ntcore._ntcore.NetworkTableEntry

Gets the entry for a subkey.

Parameters:

key – the key name

Returns:

Network table entry.

get_float_array_topic(name: str) ntcore._ntcore.FloatArrayTopic

Get float[] topic.

Parameters:

name – topic name

Returns:

FloatArrayTopic

get_float_topic(name: str) ntcore._ntcore.FloatTopic

Get float topic.

Parameters:

name – topic name

Returns:

FloatTopic

static get_hierarchy(key: str) list[str]

Gets a list of the names of all the super tables of a given key. For example, the key “/foo/bar/baz” has a hierarchy of “/”, “/foo”, “/foo/bar”, and “/foo/bar/baz”.

Parameters:

key – the key

Returns:

List of super tables

get_instance() ntcore._ntcore.NetworkTableInstance

Gets the instance for the table.

Returns:

Instance

get_integer_array_topic(name: str) ntcore._ntcore.IntegerArrayTopic

Get integer[] topic.

Parameters:

name – topic name

Returns:

IntegerArrayTopic

get_integer_topic(name: str) ntcore._ntcore.IntegerTopic

Get integer topic.

Parameters:

name – topic name

Returns:

IntegerTopic

get_keys(types: SupportsInt | SupportsIndex = 0) list[str]

Gets all keys in the table (not including sub-tables).

Parameters:

types – bitmask of types; 0 is treated as a “don’t care”.

Returns:

keys currently in the table

get_number(key: str, default_value: object) object

Gets the number associated with the given name.

Parameters:
  • key – the key to look up

  • default_value – the value to be returned if no value is found

Returns:

the value associated with the given key or the given default value if there is no value associated with the key

get_number_array(key: str, default_value: object) object

Returns the number array the key maps to. If the key does not exist or is of different type, it will return the default value.

Parameters:
  • key – the key to look up

  • default_value – the value to be returned if no value is found

Returns:

the value associated with the given key or the given default value if there is no value associated with the key

Note

This makes a copy of the array. If the overhead of this is a concern, use GetValue() instead.

get_path() str

Gets the full path of this table. Does not include the trailing “/”.

Returns:

The path (e.g “”, “/foo”).

get_raw(key: str, default_value: object) object

Returns the raw value (byte array) the key maps to. If the key does not exist or is of different type, it will return the default value.

Parameters:
  • key – the key to look up

  • default_value – the value to be returned if no value is found

Returns:

the value associated with the given key or the given default value if there is no value associated with the key

Note

This makes a copy of the raw contents. If the overhead of this is a concern, use GetValue() instead.

get_raw_topic(name: str) ntcore._ntcore.RawTopic

Get raw topic.

Parameters:

name – topic name

Returns:

BooleanArrayTopic

get_string(key: str, default_value: object) object

Gets the string associated with the given name. If the key does not exist or is of different type, it will return the default value.

Parameters:
  • key – the key to look up

  • default_value – the value to be returned if no value is found

Returns:

the value associated with the given key or the given default value if there is no value associated with the key

get_string_array(key: str, default_value: object) object

Returns the string array the key maps to. If the key does not exist or is of different type, it will return the default value.

Parameters:
  • key – the key to look up

  • default_value – the value to be returned if no value is found

Returns:

the value associated with the given key or the given default value if there is no value associated with the key

Note

This makes a copy of the array. If the overhead of this is a concern, use GetValue() instead.

get_string_array_topic(name: str) ntcore._ntcore.StringArrayTopic

Get String[] topic.

Parameters:

name – topic name

Returns:

StringArrayTopic

get_string_topic(name: str) ntcore._ntcore.StringTopic

Get String topic.

Parameters:

name – topic name

Returns:

StringTopic

get_struct_array_topic(name: str, type: type) ntcore._ntcore.StructArrayTopic

Gets a raw struct serialized array topic.

Parameters:
  • name – topic name

  • type – optional struct type info

Returns:

Topic

get_struct_topic(name: str, type: type) ntcore._ntcore.StructTopic

Gets a raw struct serialized value topic.

Parameters:
  • name – topic name

  • type – optional struct type info

Returns:

Topic

get_sub_table(key: str) ntcore._ntcore.NetworkTable

Returns the table at the specified key. If there is no table at the specified key, it will create a new table

Parameters:

key – the key name

Returns:

the networktable to be returned

get_sub_tables() list[str]

Gets the names of all subtables in the table.

Returns:

subtables currently in the table

get_topic(name: str) ntcore._ntcore.Topic

Get (generic) topic.

Parameters:

name – topic name

Returns:

Topic

get_topic_info(types: SupportsInt | SupportsIndex = 0) list[ntcore._ntcore.TopicInfo]

Gets topic information for all keys in the table (not including sub-tables).

Parameters:

types – bitmask of types; 0 is treated as a “don’t care”.

Returns:

topic information for keys currently in the table

get_topics(types: SupportsInt | SupportsIndex = 0) list[ntcore._ntcore.Topic]

Gets all topics in the table (not including sub-tables).

Parameters:

types – bitmask of types; 0 is treated as a “don’t care”.

Returns:

topic for keys currently in the table

get_value(key: str, value: object) object
is_persistent(key: str) bool

Returns whether the value is persistent through program restarts. The key cannot be null.

Parameters:

key – the key name

static normalize_key(key: str, with_leading_slash: bool = True) str

Normalizes an network table key to contain no consecutive slashes and optionally start with a leading slash. For example:

<pre><code> normalizeKey(“/foo/bar”, true) == “/foo/bar” normalizeKey(“foo/bar”, true) == “/foo/bar” normalizeKey(“/foo/bar”, false) == “foo/bar” normalizeKey(“foo//bar”, false) == “foo/bar” </code></pre>

Parameters:
  • key – the key to normalize

  • with_leading_slash – whether or not the normalized key should begin with a leading slash

Returns:

normalized key

put_boolean(key: str, value: bool) bool

Put a boolean in the table

Parameters:
  • key – the key to be assigned to

  • value – the value that will be assigned

Returns:

False if the table key already exists with a different type

put_boolean_array(key: str, value: List[SupportsInt | SupportsIndex]) bool

Put a boolean array in the table

Parameters:
  • key – the key to be assigned to

  • value – the value that will be assigned

Returns:

False if the table key already exists with a different type

Note

The array must be of int’s rather than of bool’s because std::vector<bool> is special-cased in C++. 0 is false, any non-zero value is true.

put_number(key: str, value: SupportsFloat | SupportsIndex) bool

Put a number in the table

Parameters:
  • key – the key to be assigned to

  • value – the value that will be assigned

Returns:

False if the table key already exists with a different type

put_number_array(key: str, value: List[SupportsFloat | SupportsIndex]) bool

Put a number array in the table

Parameters:
  • key – the key to be assigned to

  • value – the value that will be assigned

Returns:

False if the table key already exists with a different type

put_raw(key: str, value: Buffer) bool

Put a raw value (byte array) in the table

Parameters:
  • key – the key to be assigned to

  • value – the value that will be assigned

Returns:

False if the table key already exists with a different type

put_string(key: str, value: str) bool

Put a string in the table

Parameters:
  • key – the key to be assigned to

  • value – the value that will be assigned

Returns:

False if the table key already exists with a different type

put_string_array(key: str, value: List[str]) bool

Put a string array in the table

Parameters:
  • key – the key to be assigned to

  • value – the value that will be assigned

Returns:

False if the table key already exists with a different type

put_value(*args, **kwargs)

Overloaded function.

  1. put_value(self: ntcore._ntcore.NetworkTable, key: str, value: typing.SupportsFloat | typing.SupportsIndex) -> bool

  2. put_value(self: ntcore._ntcore.NetworkTable, key: str, value: bool) -> bool

  3. put_value(self: ntcore._ntcore.NetworkTable, key: str, value: bytes) -> bool

  4. put_value(self: ntcore._ntcore.NetworkTable, key: str, value: str) -> bool

  5. put_value(self: ntcore._ntcore.NetworkTable, key: str, value: collections.abc.Sequence) -> bool

remove_listener(listener: SupportsInt | SupportsIndex) None

Remove a listener.

Parameters:

listener – listener handle

set_default_boolean(key: str, default_value: bool) bool

Set Default Entry Value

Parameters:
  • key – the key

  • default_value – the default value to set if key doesn’t exist.

Returns:

True if the table key did not already exist, otherwise False

set_default_boolean_array(key: str, default_value: List[SupportsInt | SupportsIndex]) bool

Set Default Entry Value

Parameters:
  • key – the key

  • default_value – the default value to set if key doesn’t exist.

Returns:

True if the table key did not already exist, otherwise False

set_default_number(key: str, default_value: SupportsFloat | SupportsIndex) bool

Set Default Entry Value

Parameters:
  • key – the key

  • default_value – the default value to set if key doesn’t exist.

Returns:

True if the table key did not already exist, otherwise False

set_default_number_array(key: str, default_value: List[SupportsFloat | SupportsIndex]) bool

Set Default Entry Value

Parameters:
  • key – the key

  • default_value – the default value to set if key doesn’t exist.

Returns:

True if the table key did not already exist, otherwise False

set_default_raw(key: str, default_value: Buffer) bool

Set Default Entry Value

Parameters:
  • key – the key

  • default_value – the default value to set if key doesn’t exist.

Returns:

True if the table key did not already exist, otherwise False

set_default_string(key: str, default_value: str) bool

Set Default Entry Value

Parameters:
  • key – the key

  • default_value – the default value to set if key doesn’t exist.

Returns:

True if the table key did not already exist, otherwise False

set_default_string_array(key: str, default_value: List[str]) bool

Set Default Entry Value

Parameters:
  • key – the key

  • default_value – the default value to set if key doesn’t exist.

Returns:

True if the table key did not already exist, otherwise False

set_default_value(*args, **kwargs)

Overloaded function.

  1. set_default_value(self: ntcore._ntcore.NetworkTable, key: str, value: typing.SupportsFloat | typing.SupportsIndex) -> bool

  2. set_default_value(self: ntcore._ntcore.NetworkTable, key: str, value: bool) -> bool

  3. set_default_value(self: ntcore._ntcore.NetworkTable, key: str, value: bytes) -> bool

  4. set_default_value(self: ntcore._ntcore.NetworkTable, key: str, value: str) -> bool

  5. set_default_value(self: ntcore._ntcore.NetworkTable, key: str, value: collections.abc.Sequence) -> bool

set_persistent(key: str) None

Makes a key’s value persistent through program restarts.

Parameters:

key – the key to make persistent