API Reference

NetworkTables API

class networktables.NetworkTablesInstance[source]

The object networktables.NetworkTables is a global singleton that you can use to initialize NetworkTables connections, configure global settings and listeners, and to create table objects which can be used to send data to/from NetworkTable servers and clients.

First, you must initialize NetworkTables:

from networktables import NetworkTables

# As a client to connect to a robot
NetworkTables.initialize(server='roborio-XXX-frc.local')

Then, to interact with the SmartDashboard you get an instance of the table, and you can call the various methods:

sd = NetworkTables.getTable('SmartDashboard')

sd.putNumber('someNumber', 1234)
otherNumber = sd.getNumber('otherNumber')

You can create additional NetworkTablesInstance objects. Instances are completely independent from each other. Table operations on one instance will not be visible to other instances unless the instances are connected via the network. The main limitation on instances is that you cannot have two servers on the same network port. The main utility of instances is for unit testing, but they can also enable one program to connect to two different NetworkTables networks.

The global “default” instance (as returned by NetworkTablesInstance.getDefault()) is always available, and is intended for the common case when there is only a single NetworkTables instance being used in the program.

Additional instances can be created with the create() function.

See also

DEFAULT_PORT = 1735

The default port that network tables operates on

class EntryFlags[source]

NetworkTables entry flags

PERSISTENT = 1

Indicates a value that will be persisted on the server

class EntryTypes[source]

NetworkTable value types used in NetworkTable.getKeys()

BOOLEAN = '\x01'

True or False

BOOLEAN_ARRAY = '\x10'

List of booleans

DOUBLE = '\x02'

Floating point number

DOUBLE_ARRAY = ' '

List of numbers

RAW = '\x08'

Raw bytes

STRING = '\x04'

Strings

STRING_ARRAY = '@'

List of strings

class NetworkModes[source]

Bitflags returend from getNetworkMode()

CLIENT = 2

Running in client mode

FAILURE = 8

Flag for failure (either client or server)

NONE = 0

Not running

SERVER = 1

Running in server mode

STARTING = 4

Flag for starting (either client or server)

TEST = 16

Flag indicating in test mode

class NotifyFlags[source]

Bitflags passed to entry callbacks

DELETE = 8

Key deleted

FLAGS = 32

Flags changed

IMMEDIATE = 1

Initial listener addition

LOCAL = 2

Changed locally

NEW = 4

Newly created entry

UPDATE = 16

Value changed

PATH_SEPARATOR = '/'

The path separator for sub-tables and keys

addConnectionListener(listener, immediateNotify=False)[source]

Adds a listener that will be notified when a new connection to a NetworkTables client/server is established.

The listener is called from a NetworkTables owned thread and should return as quickly as possible.

Parameters:
  • listener (fn(bool, ConnectionInfo)) – A function that will be called with two parameters
  • immediateNotify (bool) – If True, the listener will be called immediately with any active connection information

Warning

You may call the NetworkTables API from within the listener, but it is not recommended.

Changed in version 2017.0.0: The listener is now a function

addEntryListener(listener, immediateNotify=True, localNotify=True, paramIsNew=True)[source]

Adds a listener that will be notified when any key in any NetworkTable is changed. The keys that are received using this listener will be full NetworkTable keys. Most users will not want to use this listener type.

The listener is called from the NetworkTables I/O thread, and should return as quickly as possible.

Parameters:
  • listener – A callable that has this signature: callable(key, value, isNew)
  • immediateNotify (bool) – If True, the listener will be called immediately with the current values of the table
  • localNotify (bool) – True if you wish to be notified of changes made locally (default is True)
  • paramIsNew (bool) – If True, the listener third parameter is a boolean set to True if the listener is being called because of a new value in the table. Otherwise, the parameter is an integer of the raw NT_NOTIFY_* flags

New in version 2015.2.0.

Changed in version 2017.0.0: paramIsNew parameter added

Changed in version 2018.0.0: Renamed to addEntryListener, no longer initializes NetworkTables

Warning

You may call the NetworkTables API from within the listener, but it is not recommended as we are not currently sure if deadlocks will occur

addEntryListenerEx(listener, flags, paramIsNew=True)[source]

Adds a listener that will be notified when any key in any NetworkTable is changed. The keys that are received using this listener will be full NetworkTable keys. Most users will not want to use this listener type.

The listener is called from the NetworkTables I/O thread, and should return as quickly as possible.

Parameters:
  • listener – A callable that has this signature: callable(key, value, isNew)
  • flags (NotifyFlags) – Bitmask of flags that indicate the types of notifications you wish to receive
  • paramIsNew (bool) – If True, the listener third parameter is a boolean set to True if the listener is being called because of a new value in the table. Otherwise, the parameter is an integer of the raw NT_NOTIFY_* flags

New in version 2017.0.0.

Changed in version 2018.0.0: Renamed to addEntryListenerEx, no longer initializes NetworkTables

classmethod create()[source]

Create an instance.

Returns:Newly created instance
deleteAllEntries()[source]

Deletes ALL keys in ALL subtables (except persistent values). Use with caution!

New in version 2018.0.0.

enableVerboseLogging()[source]

Enable verbose logging that can be useful when trying to diagnose NetworkTables issues.

Warning

Don’t enable this in normal use, as it can potentially cause performance issues due to the volume of logging.

New in version 2017.0.0.

flush()[source]

Flushes all updated values immediately to the network.

Note

This is rate-limited to protect the network from flooding. This is primarily useful for synchronizing network updates with user code.

New in version 2017.0.0.

getConnections()[source]

Gets information on the currently established network connections. If operating as a client, this will return either zero or one values.

Returns:list of connection information
Return type:list

New in version 2018.0.0.

classmethod getDefault()[source]

Get global default instance.

getEntries(prefix, types=0)[source]

Get entries starting with the given prefix. The results are optionally filtered by string prefix and entry type to only return a subset of all entries.

Parameters:
  • prefix – entry name required prefix; only entries whose name starts with this string are returned
  • types – bitmask of types; 0 is treated as a “don’t care”
Returns:

List of matching entries.

Return type:

list of NetworkTableEntry

New in version 2018.0.0.

getEntry(name)[source]

Gets the entry for a key.

Parameters:name – Absolute path of key
Returns:Network table entry.

New in version 2018.0.0.

getEntryInfo(prefix, types=0)[source]

Get information about entries starting with the given prefix. The results are optionally filtered by string prefix and entry type to only return a subset of all entries.

Parameters:
  • prefix – entry name required prefix; only entries whose name starts with this string are returned
  • types – bitmask of types; 0 is treated as a “don’t care”
Returns:

List of entry information.

New in version 2018.0.0.

getGlobalAutoUpdateValue(key, defaultValue, writeDefault)[source]

Global version of getAutoUpdateValue.

Parameters:
  • key (str) – the full NT path of the value (must start with /)
  • defaultValue (any) – The default value to return if the key doesn’t exist
  • writeDefault (bool) – If True, force the value to the specified default
Return type:

NetworkTableEntry

See also

ntproperty() is a read-write alternative to this

New in version 2015.3.0.

Changed in version 2018.0.0: This now returns the same as NetworkTablesInstance.getEntry()

getGlobalTable()[source]

Returns an object that allows you to write values to absolute NetworkTable keys (which are paths with / separators).

Note

This is now an alias for NetworkTables.getTable('/')

New in version 2015.2.0.

Changed in version 2017.0.0: Returns a NetworkTable instance

Changed in version 2018.0.0: No longer automatically initializes network tables

Return type:NetworkTable
getNetworkMode()[source]

Get the current network mode

New in version 2018.0.0.

getRemoteAddress()[source]

Only returns a valid address if connected to the server. If this is a server, returns None

Returns:IP address of server or None
Return type:str

New in version 2015.3.2.

getTable(key)[source]

Gets the table with the specified key.

Parameters:key (str) – the key name
Returns:the network table requested
Return type:NetworkTable

Changed in version 2018.0.0: No longer automatically initializes network tables

initialize(server=None)[source]

Initializes NetworkTables and begins operations

Parameters:server (str) –

If specified, NetworkTables will be set to client mode and attempt to connect to the specified server. This is equivalent to executing:

self.startClient(server)
Returns:True if initialized, False if already initialized

New in version 2017.0.0: The server parameter

isConnected()[source]
Returns:True if connected to at least one other NetworkTables instance
Return type:bool
isServer()[source]
Returns:True if configured in server mode
loadEntries(filename, prefix)[source]

Load table values from a file. The file format used is identical to that used for SavePersistent / LoadPersistent.

Parameters:
  • filename – filename
  • prefix – load only keys starting with this prefix
Returns:

None if success, or a string describing the error on failure

New in version 2018.0.0.

loadPersistent(filename)[source]

Loads persistent keys from a file. WPILib will do this automatically on a robot server.

Parameters:filename (str) – Name of file to load keys from
Returns:None if success, or a string describing the error on failure

New in version 2017.0.0.

removeConnectionListener(listener)[source]

Removes a connection listener

Parameters:listener – The function registered for connection notifications
removeEntryListener(listener)[source]

Remove an entry listener.

Parameters:listener – Listener to remove

New in version 2018.0.0.

saveEntries(filename, prefix)[source]

Save table values to a file. The file format used is identical to that used for SavePersistent.

Parameters:
  • filename – filename
  • prefix – save only keys starting with this prefix
Returns:

None if success, or a string describing the error on failure

New in version 2018.0.0.

savePersistent(filename)[source]

Saves persistent keys to a file. The server does this automatically.

Parameters:filename (str) – Name of file to save keys to
Returns:None if success, or a string describing the error on failure

New in version 2017.0.0.

setDashboardMode(port=1735)

Starts requesting server address from Driver Station. This connects to the Driver Station running on localhost to obtain the server IP address.

Parameters:port – server port to use in combination with IP from DS

New in version 2018.0.0: Was formerly called setDashboardMode

setNetworkIdentity(name)[source]

Sets the network identity of this node. This is the name used in the initial connection handshake, and is provided in the connection info on the remote end.

Parameters:name (str) – A string to communicate to other NetworkTables instances

New in version 2017.0.0.

setServer(server_or_servers)[source]

Sets server addresses and port for client (without restarting client). The client will attempt to connect to each server in round robin fashion.

Parameters:server_or_servers – a string, a tuple of (server, port), array of (server, port), or an array of strings

New in version 2018.0.0.

setServerTeam(team, port=1735)[source]

Sets server addresses and port for client based on the team number (without restarting client). The client will attempt to connect to each server in round robin fashion.

Parameters:
  • team – Team number
  • port – Port to communicate over

New in version 2018.0.0.

setUpdateRate(interval)[source]

Sets the period of time between writes to the network.

WPILib’s networktables and SmartDashboard default to 100ms, we have set it to 50ms instead for quicker response time. You should not set this value too low, as it could potentially increase the volume of data sent over the network.

Parameters:interval (float) – Write flush period in seconds (default is 0.050, or 50ms)

Warning

If you don’t know what this setting affects, don’t mess with it!

New in version 2017.0.0.

shutdown()[source]

Stops all NetworkTables activities and unregisters all tables and callbacks. You can call initialize() again after calling this.

New in version 2017.0.0.

startClient(server_or_servers)[source]

Sets server addresses and port for client (without restarting client). The client will attempt to connect to each server in round robin fashion.

Parameters:server_or_servers – a string, a tuple of (server, port), array of (server, port), or an array of strings

New in version 2018.0.0.

startClientTeam(team, port=1735)[source]

Starts a client using commonly known robot addresses for the specified team.

Parameters:
  • team – team number
  • port – port to communicate over

New in version 2018.0.0.

startDSClient(port=1735)[source]

Starts requesting server address from Driver Station. This connects to the Driver Station running on localhost to obtain the server IP address.

Parameters:port – server port to use in combination with IP from DS

New in version 2018.0.0: Was formerly called setDashboardMode

startServer(persistFilename='networktables.ini', listenAddress='', port=1735)[source]

Starts a server using the specified filename, listening address, and port.

Parameters:
  • persistFilename – the name of the persist file to use
  • listenAddress – the address to listen on, or empty to listen on any address
  • port – port to communicate over

New in version 2018.0.0.

startTestMode(server=True)[source]

Setup network tables to run in unit test mode, and enables verbose logging.

Returns:True if successful

New in version 2018.0.0.

stopClient()[source]

Stops the client if it is running.

New in version 2018.0.0.

stopServer()[source]

Stops the server if it is running.

New in version 2018.0.0.

waitForConnectionListenerQueue(timeout)[source]

Wait for the connection listener queue to be empty. This is primarily useful for deterministic testing. This blocks until either the connection listener queue is empty (e.g. there are no more events that need to be passed along to callbacks or poll queues) or the timeout expires.

Parameters:timeout – timeout, in seconds. Set to 0 for non-blocking behavior, or a negative value to block indefinitely
Returns:False if timed out, otherwise true.

New in version 2018.0.0.

waitForEntryListenerQueue(timeout)[source]

Wait for the entry listener queue to be empty. This is primarily useful for deterministic testing. This blocks until either the entry listener queue is empty (e.g. there are no more events that need to be passed along to callbacks or poll queues) or the timeout expires.

Parameters:timeout – timeout, in seconds. Set to 0 for non-blocking behavior, or None to block indefinitely
Returns:False if timed out, otherwise true.

NetworkTable Objects

class networktables.networktable.NetworkTable(path, api, inst)[source]

This is a NetworkTable object, it allows you to interact with NetworkTables in a table-based manner. You should not directly create a NetworkTable object, but instead use NetworkTables.getTable() to retrieve a NetworkTable instance.

For example, to interact with the SmartDashboard:

from networktables import NetworkTables
sd = NetworkTables.getTable('SmartDashboard')

someNumberEntry = sd.getEntry('someNumber')
someNumberEntry.putNumber(1234)
...

See also

PATH_SEPARATOR = '/'
addEntryListener(listener, immediateNotify=False, key=None, localNotify=False)[source]

Adds a listener that will be notified when any key in this NetworkTable is changed, or when a specified key changes.

The listener is called from the NetworkTables I/O thread, and should return as quickly as possible.

Parameters:
  • listener – A callable with signature callable(source, key, value, isNew)
  • immediateNotify (bool) – If True, the listener will be called immediately with the current values of the table
  • key (str) – If specified, the listener will only be called when this key is changed
  • localNotify (bool) – True if you wish to be notified of changes made locally (default is False)

Warning

You may call the NetworkTables API from within the listener, but it is not recommended

Changed in version 2017.0.0: Added localNotify parameter (defaults to False, which is different from NT2)

addEntryListenerEx(listener, flags, key=None, paramIsNew=True)[source]

Adds a listener that will be notified when any key in this NetworkTable is changed, or when a specified key changes.

The listener is called from the NetworkTables I/O thread, and should return as quickly as possible.

Parameters:
  • listener – A callable with signature callable(source, key, value, param)
  • flags (NotifyFlags) – Bitmask of flags that indicate the types of notifications you wish to receive
  • key (str) – If specified, the listener will only be called when this key is changed
  • paramIsNew (bool) – If True, the listener fourth parameter is a boolean set to True if the listener is being called because of a new value in the table. Otherwise, the parameter is an integer of the raw NT_NOTIFY_* flags

Warning

You may call the NetworkTables API from within the listener, but it is not recommended

New in version 2017.0.0.

addSubTableListener(listener, localNotify=False)[source]

Adds a listener that will be notified when any key in a subtable of this NetworkTable is changed.

The listener is called from the NetworkTables I/O thread, and should return as quickly as possible.

Parameters:
  • listener – Callable to call when previously unseen table appears. Function signature is callable(source, key, subtable, True)
  • localNotify (bool) – True if you wish to be notified when local changes result in a new table

Warning

You may call the NetworkTables API from within the listener, but it is not recommended as we are not currently sure if deadlocks will occur

Changed in version 2017.0.0: Added localNotify parameter

clearFlags(key, flags)[source]

Clears entry flags on the specified key in this table.

Parameters:
  • key (str) – the key name
  • flags (EntryFlags) – the flags to clear (bitmask)

New in version 2017.0.0.

clearPersistent(key)[source]

Stop making a key’s value persistent through program restarts.

Parameters:key (str) – the key name

New in version 2017.0.0.

containsKey(key)[source]

Determines whether the given key is in this table.

Parameters:key (str) – the key to search for
Returns:True if the table as a value assigned to the given key
Return type:bool
containsSubTable(key)[source]

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

Parameters:key (str) – the key to search for (must not end with path separator)
Returns:True if there is a subtable with the key which contains at least one key/subtable of its own
Return type:bool
delete(key)[source]

Deletes the specified key in this table.

Parameters:key (str) – the key name

New in version 2017.0.0.

getAutoUpdateValue(key, defaultValue, writeDefault=True)[source]

Returns an object that will be automatically updated when the value is updated by networktables.

Parameters:
  • key (str) – the key name
  • defaultValue (any) – Default value to use if not in the table
  • writeDefault (bool) – If True, put the default value to the table, overwriting existing values
Return type:

NetworkTableEntry

Note

If you modify the returned value, the value will NOT be written back to NetworkTables (though now there are functions you can use to write values). See ntproperty() if you’re looking for that sort of thing.

See also

ntproperty() is a better alternative to use

New in version 2015.1.3.

Changed in version 2018.0.0: This now returns the same as NetworkTable.getEntry()

getBoolean(key, defaultValue)[source]

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 (str) – the key name
  • defaultValue (bool) – the default value if the key is None. If not specified, raises KeyError if the key is None.
Returns:

the key

Return type:

bool

getBooleanArray(key, defaultValue)[source]

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 (str) – 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

Return type:

tuple(bool)

New in version 2017.0.0.

getEntry(key)[source]

Gets the entry for a subkey. This is the preferred API to use to access NetworkTable keys.

Return type:NetworkTableEntry

New in version 2018.0.0.

getFlags(key)[source]

Returns the entry flags for the specified key.

Parameters:key (str) – the key name
Returns:the flags, or 0 if the key is not defined
Return type:EntryFlags

New in version 2017.0.0.

getKeys(types=0)[source]
Parameters:types (EntryTypes) – bitmask of types; 0 is treated as a “don’t care”.
Returns:keys currently in the table
Return type:list

New in version 2017.0.0.

getNumber(key, defaultValue)[source]

Gets the number associated with the given name.

Parameters:
  • key (str) – the key to look up
  • defaultValue (int, float) – 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

Return type:

int, float

getNumberArray(key, defaultValue)[source]

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 (str) – 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

Return type:

tuple(int or float)

New in version 2017.0.0.

getRaw(key, defaultValue)[source]

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 (str) – the key to look up
  • defaultValue (bytes) – 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

Return type:

bytes

New in version 2017.0.0.

getString(key, defaultValue)[source]

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 (str) – the key to look up
  • defaultValue (str) – 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

Return type:

str

getStringArray(key, defaultValue)[source]

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 (str) – 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

Return type:

tuple(str)

New in version 2017.0.0.

getSubTable(key)[source]

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

Parameters:key (str) – the key name
Returns:the networktable to be returned
Return type:NetworkTable
getSubTables()[source]
Returns:subtables currently in the table
Return type:list

New in version 2017.0.0.

getValue(key, defaultValue)[source]

Gets the value associated with a key. This supports all NetworkTables types (unlike putValue()).

Parameters:
  • key (str) – the key of the value to look up
  • defaultValue (any) – The default value to return if the key doesn’t exist
Returns:

the value associated with the given key

Return type:

bool, int, float, str, bytes, tuple

New in version 2017.0.0.

isPersistent(key)[source]

Returns whether the value is persistent through program restarts.

Parameters:key (str) – the key name

New in version 2017.0.0.

path = None

Path of table without trailing slash

putBoolean(key, value)[source]

Put a boolean in the table

Parameters:
  • key (str) – the key to be assigned to
  • value (bool) – the value that will be assigned
Returns:

False if the table key already exists with a different type

Return type:

bool

putBooleanArray(key, value)[source]

Put a boolean array in the table

Parameters:
  • key (str) – the key to be assigned to
  • value (iterable(bool)) – the value that will be assigned
Returns:

False if the table key already exists with a different type

Return type:

bool

New in version 2017.0.0.

putNumber(key, value)[source]

Put a number in the table

Parameters:
  • key (str) – the key to be assigned to
  • value (int, float) – the value that will be assigned
Returns:

False if the table key already exists with a different type

Return type:

bool

putNumberArray(key, value)[source]

Put a number array in the table

Parameters:
  • key (str) – the key to be assigned to
  • value (iterable(float)) – the value that will be assigned
Returns:

False if the table key already exists with a different type

Return type:

bool

New in version 2017.0.0.

putRaw(key, value)[source]

Put a raw value (byte array) in the table

Parameters:
  • key (str) – the key to be assigned to
  • value (bytes) – the value that will be assigned
Returns:

False if the table key already exists with a different type

Return type:

bool

New in version 2017.0.0.

putString(key, value)[source]

Put a string in the table

Parameters:
  • key (str) – the key to be assigned to
  • value (str) – the value that will be assigned
Returns:

False if the table key already exists with a different type

Return type:

bool

putStringArray(key, value)[source]

Put a string array in the table

Parameters:
  • key (str) – the key to be assigned to
  • value (iterable(str)) – the value that will be assigned
Returns:

False if the table key already exists with a different type

Return type:

bool

New in version 2017.0.0.

putValue(key, value)[source]

Put a value in the table, trying to autodetect the NT type of the value. Refer to this table to determine the type mapping:

PyType NT Type Notes
bool EntryTypes.BOOLEAN  
int EntryTypes.DOUBLE  
float EntryTypes.DOUBLE  
str EntryTypes.STRING  
bytes EntryTypes.RAW Doesn’t work in Python 2.7
list Error Use putXXXArray methods instead
tuple Error Use putXXXArray methods instead
Parameters:
  • key (str) – the key to be assigned to
  • value (bool, int, float, str, bytes) – the value that will be assigned
Returns:

False if the table key already exists with a different type

Return type:

bool

New in version 2017.0.0.

removeEntryListener(listener)[source]

Removes a table listener

Parameters:listener – callable that was passed to addTableListener() or addSubTableListener()
setDefaultBoolean(key, defaultValue)[source]

If the key doesn’t currently exist, then the specified value will be assigned to the key.

Parameters:
  • key (str) – the key to be assigned to
  • defaultValue (bool) – the default value to set if key doesn’t exist.
Returns:

False if the table key exists with a different type

New in version 2017.0.0.

setDefaultBooleanArray(key, defaultValue)[source]

If the key doesn’t currently exist, then the specified value will be assigned to the key.

Parameters:
  • key (str) – the key to be assigned to
  • defaultValue (iterable(bool)) – the default value to set if key doesn’t exist.
Returns:

False if the table key exists with a different type

Return type:

bool

New in version 2017.0.0.

setDefaultNumber(key, defaultValue)[source]

If the key doesn’t currently exist, then the specified value will be assigned to the key.

Parameters:
  • key (str) – the key to be assigned to
  • defaultValue (int, float) – the default value to set if key doesn’t exist.
Returns:

False if the table key exists with a different type

Return type:

bool

New in version 2017.0.0.

setDefaultNumberArray(key, defaultValue)[source]

If the key doesn’t currently exist, then the specified value will be assigned to the key.

Parameters:
  • key (str) – the key to be assigned to
  • defaultValue (iterable(int or float)) – the default value to set if key doesn’t exist.
Returns:

False if the table key exists with a different type

Return type:

bool

New in version 2017.0.0.

setDefaultRaw(key, defaultValue)[source]

If the key doesn’t currently exist, then the specified value will be assigned to the key.

Parameters:
  • key (str) – the key to be assigned to
  • defaultValue (bytes) – the default value to set if key doesn’t exist.
Returns:

False if the table key exists with a different type

Return type:

bool

New in version 2017.0.0.

setDefaultString(key, defaultValue)[source]

If the key doesn’t currently exist, then the specified value will be assigned to the key.

Parameters:
  • key (str) – the key to be assigned to
  • defaultValue (str) – the default value to set if key doesn’t exist.
Returns:

False if the table key exists with a different type

Return type:

bool

New in version 2017.0.0.

setDefaultStringArray(key, defaultValue)[source]

If the key doesn’t currently exist, then the specified value will be assigned to the key.

Parameters:
  • key (str) – the key to be assigned to
  • defaultValue (iterable(str)) – the default value to set if key doesn’t exist.
Returns:

False if the table key exists with a different type

Return type:

bool

New in version 2017.0.0.

setDefaultValue(key, defaultValue)[source]

If the key doesn’t currently exist, then the specified value will be assigned to the key.

Parameters:
  • key (str) – the key to be assigned to
  • defaultValue (bool, int, float, str, bytes) – the default value to set if key doesn’t exist.
Returns:

False if the table key exists with a different type

New in version 2017.0.0.

See also

putValue()

setFlags(key, flags)[source]

Sets entry flags on the specified key in this table.

Parameters:
  • key (str) – the key name
  • flags (EntryFlags) – the flags to set (bitmask)

New in version 2017.0.0.

setPersistent(key)[source]

Makes a key’s value persistent through program restarts.

Parameters:key (str) – the key to make persistent

New in version 2017.0.0.

class networktables.entry.NetworkTableEntry(api, local_id, key)[source]

Holds a value from NetworkTables, and changes it as new entries come in. Do not create this object directly, use NetworkTablesInstance.getEntry() or NetworkTable.getEntry() to obtain an instance of this class.

Using NetworkTableEntry objects to access/change NT values is more efficient than the getX/putX methods of NetworkTable.

New in version 2018.0.0.

addListener(listener, flags, paramIsNew=True)[source]

Add a listener for changes to the entry

Parameters:
  • listener (callable(entry, key, value, param)) – the listener to add
  • flags (NetworkTablesInstance.NotifyFlags) – bitmask specifying desired notifications
  • paramIsNew (bool) – If True, the listener fourth parameter is a boolean set to True if the listener is being called because of a new value in the table. Otherwise, the parameter is an integer of the raw NT_NOTIFY_* flags
Returns:

listener handle

clearFlags(flags)[source]

Clears flags

Parameters:flags – the flags to clear (bitmask)
clearPersistent()[source]

Stop making value persistent through program restarts.

delete()[source]

Deletes the entry.

exists()[source]

Determines if the entry currently exists

forceSetBoolean(value)[source]

Sets the entry’s value.

Parameters:value – the value to set
forceSetBooleanArray(value)[source]

Sets the entry’s value.

Parameters:value – the value to set
forceSetDouble(value)[source]

Sets the entry’s value.

Parameters:value – the value to set
forceSetDoubleArray(value)[source]

Sets the entry’s value.

Parameters:value – the value to set
forceSetNumber(value)

Sets the entry’s value.

Parameters:value – the value to set
forceSetNumberArray(value)

Sets the entry’s value.

Parameters:value – the value to set
forceSetRaw(value)[source]

Sets the entry’s value.

Parameters:value – the value to set
forceSetString(value)[source]

Sets the entry’s value.

Parameters:value – the value to set
forceSetStringArray(value)[source]

Sets the entry’s value.

Parameters:value – the value to set
forceSetValue(value)[source]

Sets the entry’s value

Parameters:value – the value that will be assigned

Warning

Empty lists will fail

get()[source]
getBoolean(defaultValue)[source]

Gets the entry’s value as a boolean. If the entry does not exist or is of different type, it will return the default value.

Parameters:defaultValue – the value to be returned if no value is found
Returns:the entry’s value or the given default value
Return type:bool
getBooleanArray(defaultValue)[source]

Gets the entry’s value as a boolean array. If the entry does not exist or is of different type, it will return the default value.

Parameters:defaultValue – the value to be returned if no value is found
Returns:the entry’s value or the given default value
Return type:list(bool)
getDouble(defaultValue)[source]

Gets the entry’s value as a double. If the entry does not exist or is of different type, it will return the default value.

Parameters:defaultValue – the value to be returned if no value is found
Returns:the entry’s value or the given default value
Return type:float
getDoubleArray(defaultValue)[source]

Gets the entry’s value as a double array. If the entry does not exist or is of different type, it will return the default value.

Parameters:defaultValue – the value to be returned if no value is found
Returns:the entry’s value or the given default value
Return type:list(float)
getFlags()[source]

Returns the flags.

Returns:the flags (bitmask)
getHandle()[source]

Gets the native handle for the entry

getInfo()[source]

Gets combined information about the entry.

Returns:Entry information
Return type:tuple of (name, type, flags)
getName()[source]

Gets the name of the entry (the key)

getNumber(defaultValue)

Gets the entry’s value as a double. If the entry does not exist or is of different type, it will return the default value.

Parameters:defaultValue – the value to be returned if no value is found
Returns:the entry’s value or the given default value
Return type:float
getRaw(defaultValue)[source]

Gets the entry’s value as a raw value (byte array). If the entry does not exist or is of different type, it will return the default value.

Parameters:defaultValue – the value to be returned if no value is found
Returns:the entry’s value or the given default value
Return type:bytes
getString(defaultValue)[source]

Gets the entry’s value as a string. If the entry does not exist or is of different type, it will return the default value.

Parameters:defaultValue – the value to be returned if no value is found
Returns:the entry’s value or the given default value
Return type:str
getStringArray(defaultValue)[source]

Gets the entry’s value as a string array. If the entry does not exist or is of different type, it will return the default value.

Parameters:defaultValue – the value to be returned if no value is found
Returns:the entry’s value or the given default value
Return type:list(float)
getType()[source]

Gets the type of the entry

Return type:NetworkTablesInstance.EntryTypes
isPersistent()[source]

Returns whether the value is persistent through program restarts.

Returns:True if the value is persistent.
key
removeListener(listener_id)[source]

Remove a listener from receiving entry events

Parameters:listener – the callable that was passed to addListener
setBoolean(value)[source]

Sets the entry’s value.

Parameters:value – the value to set
Returns:False if the entry exists with a different type
setBooleanArray(value)[source]

Sets the entry’s value.

Parameters:value – the value to set
Returns:False if the entry exists with a different type
setDefaultBoolean(defaultValue)[source]

Sets the entry’s value if it does not exist.

Parameters:defaultValue – the default value to set
Returns:False if the entry exists with a different type
setDefaultBooleanArray(defaultValue)[source]

Sets the entry’s value if it does not exist.

Parameters:defaultValue – the default value to set
Returns:False if the entry exists with a different type
setDefaultDouble(defaultValue)[source]

Sets the entry’s value if it does not exist.

Parameters:defaultValue – the default value to set
Returns:False if the entry exists with a different type
setDefaultDoubleArray(defaultValue)[source]

Sets the entry’s value if it does not exist.

Parameters:defaultValue – the default value to set
Returns:False if the entry exists with a different type
setDefaultNumber(defaultValue)

Sets the entry’s value if it does not exist.

Parameters:defaultValue – the default value to set
Returns:False if the entry exists with a different type
setDefaultNumberArray(defaultValue)

Sets the entry’s value if it does not exist.

Parameters:defaultValue – the default value to set
Returns:False if the entry exists with a different type
setDefaultRaw(defaultValue)[source]

Sets the entry’s value if it does not exist.

Parameters:defaultValue – the default value to set
Returns:False if the entry exists with a different type
setDefaultString(defaultValue)[source]

Sets the entry’s value if it does not exist.

Parameters:defaultValue – the default value to set
Returns:False if the entry exists with a different type
setDefaultStringArray(defaultValue)[source]

Sets the entry’s value if it does not exist.

Parameters:defaultValue – the default value to set
Returns:False if the entry exists with a different type
setDefaultValue(defaultValue)[source]

Sets the entry’s value if it does not exist.

Parameters:defaultValue – the default value to set
Returns:False if the entry exists with a different type

Warning

Do not set an empty list, it will fail

setDouble(value)[source]

Sets the entry’s value.

Parameters:value – the value to set
Returns:False if the entry exists with a different type
setDoubleArray(value)[source]

Sets the entry’s value.

Parameters:value – the value to set
Returns:False if the entry exists with a different type
setFlags(flags)[source]

Sets flags.

Parameters:flags – the flags to set (bitmask)
setNumber(value)

Sets the entry’s value.

Parameters:value – the value to set
Returns:False if the entry exists with a different type
setNumberArray(value)

Sets the entry’s value.

Parameters:value – the value to set
Returns:False if the entry exists with a different type
setPersistent()[source]

Make value persistent through program restarts.

setRaw(value)[source]

Sets the entry’s value.

Parameters:value – the value to set
Returns:False if the entry exists with a different type
setString(value)[source]

Sets the entry’s value.

Parameters:value – the value to set
Returns:False if the entry exists with a different type
setStringArray(value)[source]

Sets the entry’s value.

Parameters:value – the value to set
Returns:False if the entry exists with a different type
setValue(value)[source]

Sets the entry’s value

Parameters:value – the value that will be assigned
Returns:False if the table key already exists with a different type

Warning

Empty lists will fail

value

Property to access the value of this entry, or None if the entry hasn’t been initialized yet (use setXXX or forceXXX)

Utilities

networktables.util.ntproperty(key, defaultValue, writeDefault=True, doc=None, persistent=False)[source]

A property that you can add to your classes to access NetworkTables variables like a normal variable.

Parameters:
  • key (str) – A full NetworkTables key (eg /SmartDashboard/foo)
  • defaultValue (any) – Default value to use if not in the table
  • writeDefault (bool) – If True, put the default value to the table, overwriting existing values
  • doc (str) – If given, will be the docstring of the property.
  • persistent (bool) – If True, persist set values across restarts. writeDefault is ignored if this is True.

Example usage:

class Foo(object):

    something = ntproperty('/SmartDashboard/something', True)
    
    ...
    
    def do_thing(self):
        if self.something:    # reads from value
            ...
            
            self.something = False # writes value

Note

Does not work with empty lists/tuples.

Getting the value of this property should be reasonably fast, but setting the value will have just as much overhead as NetworkTable.putValue()

Warning

When using python 2.x, the property must be assigned to a new-style class or it won’t work!

Additionally, this function assumes that the value’s type never changes. If it does, you’ll get really strange errors… so don’t do that.

New in version 2015.3.0.

Changed in version 2017.0.6: The doc parameter.

Changed in version 2018.0.0: The persistent parameter.

class networktables.util.ChooserControl(key, on_choices=None, on_selected=None)[source]

Interacts with a wpilib.sendablechooser.SendableChooser object over NetworkTables.

Parameters:
  • key (str) – NetworkTables key
  • on_choices – A function that will be called when the choices change. Signature: fn(value)
  • on_selection – A function that will be called when the selection changes. Signature: fn(value)
close()[source]

Stops listening for changes to the SendableChooser

getChoices()[source]

Returns the current choices. If the chooser doesn’t exist, this will return an empty tuple.

Return type:tuple
getSelected()[source]

Returns the current selection or None

Return type:str
setSelected(selection)[source]

Sets the active selection on the chooser

Parameters:selection – Active selection name