A pure Python implementation of NetworkTables, used for robot communications in the FIRST Robotics Competition.
75
Core NetworkTables instance functionality for connection management, server operations, and global configuration. Provides both singleton access and support for multiple independent instances for complex applications.
Create and access NetworkTables instances for connection management.
class NetworkTablesInstance:
@classmethod
def getDefault() -> NetworkTablesInstance:
"""
Get the global singleton NetworkTables instance.
Returns:
NetworkTablesInstance: The default global instance
"""
@classmethod
def create() -> NetworkTablesInstance:
"""
Create a new independent NetworkTables instance.
Returns:
NetworkTablesInstance: New instance completely independent from others
"""Initialize and manage NetworkTables connections as client or server.
def initialize(server=None):
"""
Initialize NetworkTables. Call this before any other NT operations.
Parameters:
- server: str or list, optional. Server address(es) to connect to as client.
If None, operates in standalone mode.
"""
def startClient(server_or_servers):
"""
Start NetworkTables client and connect to server(s).
Parameters:
- server_or_servers: str or list. Server address or list of addresses to connect to
"""
def startClientTeam(team: int, port: int = 1735):
"""
Start NetworkTables client using FRC team number for server discovery.
Parameters:
- team: int. FRC team number (e.g., 1234 for team 1234)
- port: int. Port number (default: 1735)
"""
def startDSClient(port: int = 1735):
"""
Start NetworkTables client and connect to Driver Station.
Parameters:
- port: int. Port number (default: 1735)
"""
def setServer(server_or_servers):
"""
Set server address(es) without connecting immediately.
Parameters:
- server_or_servers: str or list. Server address or list of addresses
"""
def setServerTeam(team: int, port: int = 1735):
"""
Set server using FRC team number without connecting immediately.
Parameters:
- team: int. FRC team number
- port: int. Port number (default: 1735)
"""
def stopClient():
"""Stop NetworkTables client and disconnect from server."""
def isConnected() -> bool:
"""
Check if NetworkTables is connected to a server.
Returns:
bool: True if connected, False otherwise
"""
def getConnections() -> List[dict]:
"""
Get information about current connections.
Returns:
List[dict]: Connection information including remote addresses and protocol versions
"""
def getRemoteAddress() -> Optional[str]:
"""
Get the remote address if connected as client.
Returns:
Optional[str]: Remote server address, or None if server or not connected
"""
def getNetworkMode() -> int:
"""
Get the current network mode.
Returns:
int: Bitmask of current network modes (SERVER, CLIENT, STARTING, etc.)
"""
def isServer() -> bool:
"""
Check if running in server mode.
Returns:
bool: True if configured as server, False otherwise
"""Start and manage NetworkTables server for hosting data.
def startServer(persistFilename: str = "networktables.ini",
listenAddress: str = "",
port: int = 1735):
"""
Start NetworkTables server to host data for clients.
Parameters:
- persistFilename: str. File to load/save persistent entries (default: "networktables.ini")
- listenAddress: str. Network interface to listen on (default: "" for all interfaces)
- port: int. Port number to listen on (default: 1735)
"""
def stopServer():
"""Stop NetworkTables server."""Control global NetworkTables behavior and lifecycle.
def shutdown():
"""
Stop all NetworkTables activity (client, server, listeners).
After calling this, NetworkTables must be reinitialized.
"""
def flush():
"""
Force immediate network update of all pending changes.
Normally updates are sent automatically at regular intervals.
"""
def setUpdateRate(interval: float):
"""
Set the network update rate in seconds.
Parameters:
- interval: float. Time interval in seconds between network updates (default: 0.1)
"""
def setNetworkIdentity(name: str):
"""
Set the network identity for this instance.
Parameters:
- name: str. Identity name used in connection handshake
"""
def startTestMode(server: bool = True):
"""
Start NetworkTables in test mode for unit testing.
Parameters:
- server: bool. Whether to start as server (default: True)
"""
def enableVerboseLogging():
"""Enable verbose logging for debugging NetworkTables issues."""
def waitForEntryListenerQueue(timeout: float) -> bool:
"""
Wait for entry listener queue to be empty (for testing).
Parameters:
- timeout: float. Maximum time to wait in seconds
Returns:
bool: True if queue emptied, False if timeout
"""
def waitForConnectionListenerQueue(timeout: float) -> bool:
"""
Wait for connection listener queue to be empty (for testing).
Parameters:
- timeout: float. Maximum time to wait in seconds
Returns:
bool: True if queue emptied, False if timeout
"""Access entries and tables from the instance level.
def getEntry(name: str) -> NetworkTableEntry:
"""
Get a NetworkTable entry by full path.
Parameters:
- name: str. Full path to entry (e.g., "/SmartDashboard/speed")
Returns:
NetworkTableEntry: Entry object for type-safe value access
"""
def getEntries(prefix: str, types: int = 0) -> List[NetworkTableEntry]:
"""
Get all entries with names starting with the given prefix.
Parameters:
- prefix: str. Path prefix to match (e.g., "/SmartDashboard/")
- types: int. Bitmask of entry types to include (default: 0 for all types)
Returns:
List[NetworkTableEntry]: List of matching entries
"""
def getTable(key: str) -> NetworkTable:
"""
Get a NetworkTable by path.
Parameters:
- key: str. Table path (e.g., "SmartDashboard", "/Vision")
Returns:
NetworkTable: Table object for key-value operations
"""
def getGlobalTable() -> NetworkTable:
"""
Get the root table (equivalent to getTable("/")).
Returns:
NetworkTable: The root table containing all entries
"""
def getGlobalAutoUpdateValue(key: str, defaultValue, writeDefault: bool) -> NetworkTableEntry:
"""
Get an auto-updating entry from global scope.
Parameters:
- key: str. Full path to entry
- defaultValue: Any. Default value if entry doesn't exist
- writeDefault: bool. Whether to write default value to table
Returns:
NetworkTableEntry: Auto-updating entry object
"""Manage entries across the entire NetworkTables instance.
def deleteAllEntries():
"""Delete all entries in this NetworkTables instance."""
def getEntryInfo(prefix: str, types: int = 0) -> List[tuple]:
"""
Get information about entries matching the prefix.
Parameters:
- prefix: str. Path prefix to match
- types: int. Bitmask of entry types to include (default: 0 for all types)
Returns:
List[tuple]: List of (name, type, flags) tuples for matching entries
"""from networktables import NetworkTables
# Connect to robot using team number
NetworkTables.initialize()
NetworkTables.startClientTeam(1234)
# Wait for connection
import time
while not NetworkTables.isConnected():
time.sleep(0.1)
print("Connected to robot!")from networktables import NetworkTables
# Start as server for testing or coprocessor use
NetworkTables.initialize()
NetworkTables.startServer()
print("NetworkTables server started on port 1735")from networktables import NetworkTablesInstance
# Create separate instances for different purposes
robot_nt = NetworkTablesInstance.create()
vision_nt = NetworkTablesInstance.create()
# Configure robot connection
robot_nt.startClientTeam(1234)
# Configure vision processing server
vision_nt.startServer(port=1736)# Network modes
class NetworkModes:
NONE = 0
SERVER = 1
CLIENT = 2
STARTING = 3
FAILURE = 4
TEST = 5
# Default values
PATH_SEPARATOR = "/"
DEFAULT_PORT = 1735Install with Tessl CLI
npx tessl i tessl/pypi-pynetworktablesdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10