NetworkTable

class ntcore.NetworkTable

Bases: pybind11_object

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

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

Overloaded function.

  1. addListener(self: ntcore._ntcore.NetworkTable, eventMask: int, listener: Callable[[ntcore._ntcore.NetworkTable, str, ntcore._ntcore.Event], None]) -> int

Listen to topics only within this table.

Parameters:
  • eventMask – Bitmask of EventFlags values

  • listener – listener to add

Returns:

Listener handle

  1. addListener(self: ntcore._ntcore.NetworkTable, key: str, eventMask: int, listener: Callable[[ntcore._ntcore.NetworkTable, str, ntcore._ntcore.Event], None]) -> int

Listen to a single key.

Parameters:
  • key – the key name

  • eventMask – Bitmask of EventFlags values

  • listener – listener to add

Returns:

Listener handle

addSubTableListener(listener: 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 basenameKey(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

clearPersistent(key: str) None

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

Parameters:

key – the key name

containsKey(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

containsSubTable(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

getBoolean(key: str, defaultValue: 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

  • defaultValue – 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

getBooleanArray(key: str, defaultValue: 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

  • defaultValue – 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.

getBooleanArrayTopic(name: str) ntcore._ntcore.BooleanArrayTopic

Get boolean[] topic.

Parameters:

name – topic name

Returns:

BooleanArrayTopic

getBooleanTopic(name: str) ntcore._ntcore.BooleanTopic

Get boolean topic.

Parameters:

name – topic name

Returns:

BooleanTopic

getDoubleArrayTopic(name: str) ntcore._ntcore.DoubleArrayTopic

Get double[] topic.

Parameters:

name – topic name

Returns:

DoubleArrayTopic

getDoubleTopic(name: str) ntcore._ntcore.DoubleTopic

Get double topic.

Parameters:

name – topic name

Returns:

DoubleTopic

getEntry(key: str) ntcore._ntcore.NetworkTableEntry

Gets the entry for a subkey.

Parameters:

key – the key name

Returns:

Network table entry.

getFloatArrayTopic(name: str) ntcore._ntcore.FloatArrayTopic

Get float[] topic.

Parameters:

name – topic name

Returns:

FloatArrayTopic

getFloatTopic(name: str) ntcore._ntcore.FloatTopic

Get float topic.

Parameters:

name – topic name

Returns:

FloatTopic

static getHierarchy(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

getInstance() ntcore._ntcore.NetworkTableInstance

Gets the instance for the table.

Returns:

Instance

getIntegerArrayTopic(name: str) ntcore._ntcore.IntegerArrayTopic

Get integer[] topic.

Parameters:

name – topic name

Returns:

IntegerArrayTopic

getIntegerTopic(name: str) ntcore._ntcore.IntegerTopic

Get integer topic.

Parameters:

name – topic name

Returns:

IntegerTopic

getKeys(types: int = 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

getNumber(key: str, defaultValue: object) object

Gets the number associated with the given name.

Parameters:
  • key – the key to look up

  • defaultValue – 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

getNumberArray(key: str, defaultValue: 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

  • defaultValue – 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.

getPath() str

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

Returns:

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

getRaw(key: str, defaultValue: 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

  • defaultValue – 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.

getRawTopic(name: str) ntcore._ntcore.RawTopic

Get raw topic.

Parameters:

name – topic name

Returns:

BooleanArrayTopic

getString(key: str, defaultValue: 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

  • defaultValue – 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

getStringArray(key: str, defaultValue: 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

  • defaultValue – 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.

getStringArrayTopic(name: str) ntcore._ntcore.StringArrayTopic

Get String[] topic.

Parameters:

name – topic name

Returns:

StringArrayTopic

getStringTopic(name: str) ntcore._ntcore.StringTopic

Get String topic.

Parameters:

name – topic name

Returns:

StringTopic

getSubTable(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

getSubTables() List[str]

Gets the names of all subtables in the table.

Returns:

subtables currently in the table

getTopic(name: str) ntcore._ntcore.Topic

Get (generic) topic.

Parameters:

name – topic name

Returns:

Topic

getTopicInfo(types: int = 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

getTopics(types: int = 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

getValue(key: str, value: object) object
isPersistent(key: str) bool

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

Parameters:

key – the key name

static normalizeKey(key: str, withLeadingSlash: 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

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

Returns:

normalized key

putBoolean(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

putBooleanArray(key: str, value: List[int]) 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.

putNumber(key: str, value: float) 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

putNumberArray(key: str, value: List[float]) 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

putRaw(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

putString(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

putStringArray(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

putValue(*args, **kwargs)

Overloaded function.

  1. putValue(self: ntcore._ntcore.NetworkTable, key: str, value: float) -> bool

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

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

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

  5. putValue(self: ntcore._ntcore.NetworkTable, key: str, value: sequence) -> bool

removeListener(listener: int) None

Remove a listener.

Parameters:

listener – listener handle

setDefaultBoolean(key: str, defaultValue: bool) bool

Gets the current value in the table, setting it if it does not exist.

Parameters:
  • key – the key

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

Returns:

False if the table key exists with a different type

setDefaultBooleanArray(key: str, defaultValue: List[int]) bool

Gets the current value in the table, setting it if it does not exist.

Parameters:
  • key – the key

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

Returns:

False if the table key exists with a different type

setDefaultNumber(key: str, defaultValue: float) bool

Gets the current value in the table, setting it if it does not exist.

Parameters:
  • key – the key

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

Returns:

False if the table key exists with a different type

setDefaultNumberArray(key: str, defaultValue: List[float]) bool

Gets the current value in the table, setting it if it does not exist.

Parameters:
  • key – the key

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

Returns:

False if the table key exists with a different type

setDefaultRaw(key: str, defaultValue: buffer) bool

Gets the current value in the table, setting it if it does not exist.

Parameters:
  • key – the key

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

Returns:

False if the table key exists with a different type

setDefaultString(key: str, defaultValue: str) bool

Gets the current value in the table, setting it if it does not exist.

Parameters:
  • key – the key

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

Returns:

False if the table key exists with a different type

setDefaultStringArray(key: str, defaultValue: List[str]) bool

Gets the current value in the table, setting it if it does not exist.

Parameters:
  • key – the key

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

Returns:

False if the table key exists with a different type

setDefaultValue(*args, **kwargs)

Overloaded function.

  1. setDefaultValue(self: ntcore._ntcore.NetworkTable, key: str, value: float) -> bool

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

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

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

  5. setDefaultValue(self: ntcore._ntcore.NetworkTable, key: str, value: sequence) -> bool

setPersistent(key: str) None

Makes a key’s value persistent through program restarts.

Parameters:

key – the key to make persistent