CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pynetworktables

A pure Python implementation of NetworkTables, used for robot communications in the FIRST Robotics Competition.

75

1.01x
Overview
Eval results
Files

table-operations.mddocs/

Table Operations

Table-based interface for reading and writing values in NetworkTable hierarchies. Provides convenient methods for all supported data types, table navigation, and bulk operations on related data.

Capabilities

Entry Access and Navigation

Navigate tables and access entries within the hierarchy.

class NetworkTable:
    def getEntry(key: str) -> NetworkTableEntry:
        """
        Get an entry by key within this table.
        
        Parameters:
        - key: str. Entry key within this table (not full path)
        
        Returns:
            NetworkTableEntry: Entry object for type-safe operations
        """
    
    def containsKey(key: str) -> bool:
        """
        Check if a key exists in this table.
        
        Parameters:
        - key: str. Entry key to check
        
        Returns:
            bool: True if key exists, False otherwise
        """
    
    def getKeys(types: int = 0) -> List[str]:
        """
        Get all keys in this table, optionally filtered by type.
        
        Parameters:
        - types: int. Bitmask of entry types to include (default: 0 for all)
        
        Returns:
            List[str]: List of keys in this table
        """
    
    def getSubTables() -> List[str]:
        """
        Get names of all subtables within this table.
        
        Returns:
            List[str]: List of subtable names
        """
    
    def getSubTable(key: str) -> NetworkTable:
        """
        Get a subtable by name.
        
        Parameters:
        - key: str. Subtable name
        
        Returns:
            NetworkTable: Subtable object
        """
    
    def containsSubTable(key: str) -> bool:
        """
        Check if a subtable exists.
        
        Parameters:
        - key: str. Subtable name to check
        
        Returns:
            bool: True if subtable exists, False otherwise
        """
    
    def getPath() -> str:
        """
        Get the full path of this table.
        
        Returns:
            str: Full table path (e.g., "/SmartDashboard")
        """

Numeric Value Operations

Store and retrieve numeric (double) values.

def putNumber(key: str, value: float):
    """
    Put a numeric value into the table.
    
    Parameters:
    - key: str. Entry key
    - value: float. Numeric value to store
    """

def getNumber(key: str, defaultValue: float) -> float:
    """
    Get a numeric value from the table.
    
    Parameters:
    - key: str. Entry key
    - defaultValue: float. Value to return if key doesn't exist
    
    Returns:
        float: Entry value or default value
    """

def setDefaultNumber(key: str, defaultValue: float):
    """
    Set default value for a numeric entry without overwriting existing values.
    
    Parameters:
    - key: str. Entry key
    - defaultValue: float. Default value to set
    """

String Value Operations

Store and retrieve string values.

def putString(key: str, value: str):
    """
    Put a string value into the table.
    
    Parameters:
    - key: str. Entry key
    - value: str. String value to store
    """

def getString(key: str, defaultValue: str) -> str:
    """
    Get a string value from the table.
    
    Parameters:
    - key: str. Entry key
    - defaultValue: str. Value to return if key doesn't exist
    
    Returns:
        str: Entry value or default value
    """

def setDefaultString(key: str, defaultValue: str):
    """
    Set default value for a string entry without overwriting existing values.
    
    Parameters:
    - key: str. Entry key
    - defaultValue: str. Default value to set
    """

Boolean Value Operations

Store and retrieve boolean values.

def putBoolean(key: str, value: bool):
    """
    Put a boolean value into the table.
    
    Parameters:
    - key: str. Entry key
    - value: bool. Boolean value to store
    """

def getBoolean(key: str, defaultValue: bool) -> bool:
    """
    Get a boolean value from the table.
    
    Parameters:
    - key: str. Entry key
    - defaultValue: bool. Value to return if key doesn't exist
    
    Returns:
        bool: Entry value or default value
    """

def setDefaultBoolean(key: str, defaultValue: bool):
    """
    Set default value for a boolean entry without overwriting existing values.
    
    Parameters:
    - key: str. Entry key
    - defaultValue: bool. Default value to set
    """

Array Value Operations

Store and retrieve array values of various types.

def putNumberArray(key: str, value: List[float]):
    """
    Put a numeric array into the table.
    
    Parameters:
    - key: str. Entry key
    - value: List[float]. Numeric array to store
    """

def getNumberArray(key: str, defaultValue: List[float]) -> List[float]:
    """
    Get a numeric array from the table.
    
    Parameters:
    - key: str. Entry key
    - defaultValue: List[float]. Value to return if key doesn't exist
    
    Returns:
        List[float]: Entry value or default value
    """

def putStringArray(key: str, value: List[str]):
    """
    Put a string array into the table.
    
    Parameters:
    - key: str. Entry key
    - value: List[str]. String array to store
    """

def getStringArray(key: str, defaultValue: List[str]) -> List[str]:
    """
    Get a string array from the table.
    
    Parameters:
    - key: str. Entry key
    - defaultValue: List[str]. Value to return if key doesn't exist
    
    Returns:
        List[str]: Entry value or default value
    """

def putBooleanArray(key: str, value: List[bool]):
    """
    Put a boolean array into the table.
    
    Parameters:
    - key: str. Entry key
    - value: List[bool]. Boolean array to store
    """

def getBooleanArray(key: str, defaultValue: List[bool]) -> List[bool]:
    """
    Get a boolean array from the table.
    
    Parameters:
    - key: str. Entry key
    - defaultValue: List[bool]. Value to return if key doesn't exist
    
    Returns:
        List[bool]: Entry value or default value
    """

Raw Data Operations

Store and retrieve raw byte data.

def putRaw(key: str, value: bytes):
    """
    Put raw byte data into the table.
    
    Parameters:
    - key: str. Entry key
    - value: bytes. Raw data to store
    """

def getRaw(key: str, defaultValue: bytes) -> bytes:
    """
    Get raw byte data from the table.
    
    Parameters:
    - key: str. Entry key
    - defaultValue: bytes. Value to return if key doesn't exist
    
    Returns:
        bytes: Entry value or default value
    """

Generic Value Operations

Store and retrieve values with automatic type detection.

def putValue(key: str, value):
    """
    Put a value into the table with automatic type detection.
    
    Parameters:
    - key: str. Entry key
    - value: Any. Value to store (bool, float, str, bytes, or arrays thereof)
    """

def getValue(key: str, defaultValue) -> Any:
    """
    Get a value from the table with automatic type handling.
    
    Parameters:
    - key: str. Entry key
    - defaultValue: Any. Value to return if key doesn't exist
    
    Returns:
        Any: Entry value or default value
    """

def setDefaultValue(key: str, defaultValue):
    """
    Set default value for an entry without overwriting existing values.
    
    Parameters:
    - key: str. Entry key
    - defaultValue: Any. Default value to set
    """

Entry Management

Manage entries within the table.

def delete(key: str):
    """
    Delete an entry from the table.
    
    Parameters:
    - key: str. Entry key to delete
    """

Persistence Control

Control which values persist across NetworkTables restarts.

def setPersistent(key: str):
    """
    Make an entry persistent across restarts.
    
    Parameters:
    - key: str. Entry key to make persistent
    """

def clearPersistent(key: str):
    """
    Remove persistence from an entry.
    
    Parameters:
    - key: str. Entry key to make non-persistent
    """

def isPersistent(key: str) -> bool:
    """
    Check if an entry is persistent.
    
    Parameters:
    - key: str. Entry key to check
    
    Returns:
        bool: True if entry is persistent, False otherwise
    """

def setFlags(key: str, flags: int):
    """
    Set flags for an entry.
    
    Parameters:
    - key: str. Entry key
    - flags: int. Bitmask of flags to set
    """

def clearFlags(key: str, flags: int):
    """
    Clear flags for an entry.
    
    Parameters:
    - key: str. Entry key
    - flags: int. Bitmask of flags to clear
    """

def getFlags(key: str) -> int:
    """
    Get flags for an entry.
    
    Parameters:
    - key: str. Entry key
    
    Returns:
        int: Bitmask of entry flags
    """

Listener Management

Add and remove listeners for table changes.

def addEntryListener(listener: Callable, immediateNotify: bool = False, 
                     key: str = None, localNotify: bool = False):
    """
    Add a listener for entry changes in this table.
    
    Parameters:
    - listener: Callable. Function called when entries change
    - immediateNotify: bool. Call listener immediately with current values
    - key: str, optional. Specific key to watch (None for all keys in table)
    - localNotify: bool. Whether to notify on local changes
    """

def removeEntryListener(listener):
    """
    Remove an entry listener.
    
    Parameters:
    - listener: Callable. Previously added listener function
    """

def addSubTableListener(listener: Callable, localNotify: bool = False):
    """
    Add a listener for subtable creation/deletion.
    
    Parameters:
    - listener: Callable. Function called when subtables change
    - localNotify: bool. Whether to notify on local changes
    """

Advanced Entry Access

Get auto-updating entry objects for efficient access patterns.

def getAutoUpdateValue(key: str, defaultValue, writeDefault: bool = True) -> NetworkTableEntry:
    """
    Get an auto-updating entry that caches the latest value.
    
    Parameters:
    - key: str. Entry key
    - defaultValue: Any. Default value if entry doesn't exist
    - writeDefault: bool. Whether to write default value to table
    
    Returns:
        NetworkTableEntry: Entry that automatically updates with latest value
    """

Usage Examples

Basic Table Operations

from networktables import NetworkTables

# Get SmartDashboard table
sd = NetworkTables.getTable('SmartDashboard')

# Store different types of data
sd.putNumber('speed', 42.5)
sd.putString('status', 'running')
sd.putBoolean('enabled', True)
sd.putNumberArray('pose', [1.2, 3.4, 0.5])

# Read data with defaults
speed = sd.getNumber('speed', 0.0)
status = sd.getString('status', 'unknown')
enabled = sd.getBoolean('enabled', False)
pose = sd.getNumberArray('pose', [0.0, 0.0, 0.0])

Table Navigation

from networktables import NetworkTables

# Navigate table hierarchy
root = NetworkTables.getGlobalTable()
vision = root.getSubTable('Vision')
camera1 = vision.getSubTable('Camera1')

# List available data
print("Available keys:", vision.getKeys())
print("Available subtables:", vision.getSubTables())

# Check for specific data
if vision.containsKey('targetDistance'):
    distance = vision.getNumber('targetDistance', 0.0)

Persistence and Flags

from networktables import NetworkTables

sd = NetworkTables.getTable('SmartDashboard')

# Make configuration values persistent
sd.putNumber('maxSpeed', 1.0)
sd.setPersistent('maxSpeed')

# Set defaults without overwriting
sd.setDefaultString('autonomousMode', 'defense')
sd.setDefaultBoolean('compressorEnabled', True)

# Check persistence
if sd.isPersistent('maxSpeed'):
    print("Max speed will persist across restarts")

Constants

# Table path separator
PATH_SEPARATOR = "/"

Install with Tessl CLI

npx tessl i tessl/pypi-pynetworktables

docs

entry-interface.md

index.md

instance-management.md

integration-utilities.md

listeners-events.md

persistence-data.md

table-operations.md

tile.json