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

entry-interface.mddocs/

Entry Interface

Type-safe interface to individual NetworkTables entries with efficient access patterns. Provides the most performant way to read and write NetworkTable values by avoiding repeated key lookups and table navigation.

Capabilities

Entry Information

Get metadata and status information about entries.

class NetworkTableEntry:
    def exists() -> bool:
        """
        Check if the entry currently exists in NetworkTables.
        
        Returns:
            bool: True if entry exists, False otherwise
        """
    
    def getName() -> str:
        """
        Get the full name/path of the entry.
        
        Returns:
            str: Full entry path (e.g., "/SmartDashboard/speed")
        """
    
    def getType() -> int:
        """
        Get the type of the entry.
        
        Returns:
            int: Entry type constant (NT_BOOLEAN, NT_DOUBLE, NT_STRING, etc.)
        """
    
    def getFlags() -> int:
        """
        Get the flags bitmask for the entry.
        
        Returns:
            int: Bitmask of entry flags (e.g., NT_PERSISTENT)
        """
    
    def getInfo() -> tuple:
        """
        Get combined information about the entry.
        
        Returns:
            tuple: (name, type, flags) tuple with entry metadata
        """
    
    def getHandle() -> int:
        """
        Get the internal handle for this entry.
        
        Returns:
            int: Internal entry handle for advanced use
        """

Current Value Access

Access the current value of an entry with type safety.

@property
def value:
    """
    Property to access the current value of this entry, or None if uninitialized.
    
    Returns:
        Any: Current entry value or None
    """

def getBoolean(defaultValue) -> bool:
    """
    Get the entry's value as a boolean.
    
    Parameters:
    - defaultValue: bool. Value to return if entry doesn't exist or is wrong type
    
    Returns:
        bool: Entry value or default value
    """

def getDouble(defaultValue) -> float:
    """
    Get the entry's value as a double/float.
    
    Parameters:
    - defaultValue: float. Value to return if entry doesn't exist or is wrong type
    
    Returns:
        float: Entry value or default value
    """

def getString(defaultValue) -> str:
    """
    Get the entry's value as a string.
    
    Parameters:
    - defaultValue: str. Value to return if entry doesn't exist or is wrong type
    
    Returns:
        str: Entry value or default value
    """

def getRaw(defaultValue) -> bytes:
    """
    Get the entry's value as raw bytes.
    
    Parameters:
    - defaultValue: bytes. Value to return if entry doesn't exist or is wrong type
    
    Returns:
        bytes: Entry value or default value
    """

def getBooleanArray(defaultValue) -> List[bool]:
    """
    Get the entry's value as a boolean array.
    
    Parameters:
    - defaultValue: List[bool]. Value to return if entry doesn't exist or is wrong type
    
    Returns:
        List[bool]: Entry value or default value
    """

def getDoubleArray(defaultValue) -> List[float]:
    """
    Get the entry's value as a double array.
    
    Parameters:
    - defaultValue: List[float]. Value to return if entry doesn't exist or is wrong type
    
    Returns:
        List[float]: Entry value or default value
    """

def getStringArray(defaultValue) -> List[str]:
    """
    Get the entry's value as a string array.
    
    Parameters:
    - defaultValue: List[str]. Value to return if entry doesn't exist or is wrong type
    
    Returns:
        List[str]: Entry value or default value
    """

Value Setting

Set entry values with type safety and validation.

def setValue(value):
    """
    Set the entry's value with automatic type detection.
    
    Parameters:
    - value: Any. Value to set (bool, float, str, bytes, or arrays thereof)
    """

def setBoolean(value: bool):
    """
    Set the entry's value as a boolean.
    
    Parameters:
    - value: bool. Boolean value to set
    """

def setDouble(value: float):
    """
    Set the entry's value as a double/float.
    
    Parameters:
    - value: float. Numeric value to set
    """

def setString(value: str):
    """
    Set the entry's value as a string.
    
    Parameters:
    - value: str. String value to set
    """

def setRaw(value: bytes):
    """
    Set the entry's value as raw bytes.
    
    Parameters:
    - value: bytes. Raw data to set
    """

def setBooleanArray(value: List[bool]):
    """
    Set the entry's value as a boolean array.
    
    Parameters:
    - value: List[bool]. Boolean array to set
    """

def setDoubleArray(value: List[float]):
    """
    Set the entry's value as a double array.
    
    Parameters:
    - value: List[float]. Numeric array to set
    """

def setStringArray(value: List[str]):
    """
    Set the entry's value as a string array.
    
    Parameters:
    - value: List[str]. String array to set
    """

Forced Value Setting

Force value setting with type conversion when needed.

def forceSetValue(value):
    """
    Force set the entry's value, allowing type changes.
    
    Parameters:
    - value: Any. Value to set, changing type if necessary
    """

def forceSetBoolean(value: bool):
    """
    Force set the entry's value as a boolean, changing type if necessary.
    
    Parameters:
    - value: bool. Boolean value to set
    """

def forceSetDouble(value: float):
    """
    Force set the entry's value as a double, changing type if necessary.
    
    Parameters:
    - value: float. Numeric value to set
    """

def forceSetString(value: str):
    """
    Force set the entry's value as a string, changing type if necessary.
    
    Parameters:
    - value: str. String value to set
    """

def forceSetRaw(value: bytes):
    """
    Force set the entry's value as raw bytes, changing type if necessary.
    
    Parameters:
    - value: bytes. Raw data to set
    """

def forceSetBooleanArray(value: List[bool]):
    """
    Force set the entry's value as a boolean array, changing type if necessary.
    
    Parameters:
    - value: List[bool]. Boolean array to set
    """

def forceSetDoubleArray(value: List[float]):
    """
    Force set the entry's value as a double array, changing type if necessary.
    
    Parameters:
    - value: List[float]. Numeric array to set
    """

def forceSetStringArray(value: List[str]):
    """
    Force set the entry's value as a string array, changing type if necessary.
    
    Parameters:
    - value: List[str]. String array to set
    """

Default Values

Set default values without overwriting existing data.

def setDefaultValue(defaultValue):
    """
    Set default value for the entry without overwriting existing values.
    
    Parameters:
    - defaultValue: Any. Default value to set if entry doesn't exist
    """

def setDefaultBoolean(defaultValue: bool):
    """
    Set default boolean value for the entry.
    
    Parameters:
    - defaultValue: bool. Default boolean value
    """

def setDefaultDouble(defaultValue: float):
    """
    Set default numeric value for the entry.
    
    Parameters:
    - defaultValue: float. Default numeric value
    """

def setDefaultString(defaultValue: str):
    """
    Set default string value for the entry.
    
    Parameters:
    - defaultValue: str. Default string value
    """

def setDefaultRaw(defaultValue: bytes):
    """
    Set default raw bytes value for the entry.
    
    Parameters:
    - defaultValue: bytes. Default raw data
    """

def setDefaultBooleanArray(defaultValue: List[bool]):
    """
    Set default boolean array value for the entry.
    
    Parameters:
    - defaultValue: List[bool]. Default boolean array
    """

def setDefaultDoubleArray(defaultValue: List[float]):
    """
    Set default numeric array value for the entry.
    
    Parameters:
    - defaultValue: List[float]. Default numeric array
    """

def setDefaultStringArray(defaultValue: List[str]):
    """
    Set default string array value for the entry.
    
    Parameters:
    - defaultValue: List[str]. Default string array
    """

Persistence and Flags

Control entry persistence and flags.

def setPersistent():
    """Make the entry persistent across NetworkTables restarts."""

def clearPersistent():
    """Remove persistence from the entry."""

def isPersistent() -> bool:
    """
    Check if the entry is persistent.
    
    Returns:
        bool: True if entry is persistent, False otherwise
    """

def setFlags(flags: int):
    """
    Set flags for the entry.
    
    Parameters:
    - flags: int. Bitmask of flags to set
    """

def clearFlags(flags: int):
    """
    Clear flags for the entry.
    
    Parameters:
    - flags: int. Bitmask of flags to clear
    """

Entry Management

Delete entries and manage their lifecycle.

def delete() -> bool:
    """
    Delete the entry from NetworkTables.
    
    Returns:
        bool: True if entry was deleted, False if it didn't exist
    """

Listener Management

Add and remove listeners for this specific entry.

def addListener(listener: Callable, flags: int, paramIsNew: bool = True) -> int:
    """
    Add a listener for changes to this entry.
    
    Parameters:
    - listener: Callable. Function called when entry changes
    - flags: int. Bitmask of notification flags (NT_NOTIFY_NEW, NT_NOTIFY_UPDATE, etc.)
    - paramIsNew: bool. Whether to pass isNew parameter to listener
    
    Returns:
        int: Listener ID for removal
    """

def removeListener(listener_id: int):
    """
    Remove a listener by ID.
    
    Parameters:
    - listener_id: int. ID returned from addListener
    """

Static Utilities

Static methods for type validation.

@staticmethod
def isValidDataType(data) -> bool:
    """
    Check if data is a valid NetworkTables type.
    
    Parameters:
    - data: Any. Data to validate
    
    Returns:
        bool: True if data type is supported by NetworkTables
    """

Usage Examples

Efficient Value Access

from networktables import NetworkTables

# Get entry once and reuse for efficiency
speed_entry = NetworkTables.getEntry('/SmartDashboard/speed')
heading_entry = NetworkTables.getEntry('/SmartDashboard/heading')

# Read values efficiently (no key lookup each time)
current_speed = speed_entry.getDouble(0.0)
current_heading = heading_entry.getDouble(0.0)

# Write values efficiently
speed_entry.setDouble(42.5)
heading_entry.setDouble(180.0)

Type Safety and Default Values

from networktables import NetworkTables

# Create entry with default value
enabled_entry = NetworkTables.getEntry('/robot/enabled')
enabled_entry.setDefaultBoolean(False)

# Type-safe access with fallback
is_enabled = enabled_entry.getBoolean(False)

# Check entry status
if enabled_entry.exists():
    print(f"Entry type: {enabled_entry.getType()}")
    print(f"Entry name: {enabled_entry.getName()}")

Persistence Management

from networktables import NetworkTables

# Make configuration persistent
config_entry = NetworkTables.getEntry('/config/maxSpeed')
config_entry.setDefaultDouble(1.0)
config_entry.setPersistent()

# Check persistence status
if config_entry.isPersistent():
    print("Configuration will survive restart")

Array Operations

from networktables import NetworkTables

# Work with arrays efficiently
pose_entry = NetworkTables.getEntry('/robot/pose')
target_entry = NetworkTables.getEntry('/vision/targets')

# Set array values
pose_entry.setDoubleArray([1.2, 3.4, 0.785])
target_entry.setStringArray(['target1', 'target2', 'target3'])

# Get array values with defaults
current_pose = pose_entry.getDoubleArray([0.0, 0.0, 0.0])
visible_targets = target_entry.getStringArray([])

Entry Listeners

from networktables import NetworkTables

def on_speed_change(entry, value, isNew):
    print(f"Speed changed to: {value}")

# Add listener to specific entry
speed_entry = NetworkTables.getEntry('/SmartDashboard/speed')
listener_id = speed_entry.addListener(
    on_speed_change, 
    NetworkTables.NotifyFlags.UPDATE | NetworkTables.NotifyFlags.NEW
)

# Remove listener later
speed_entry.removeListener(listener_id)

Entry Type Constants

# Entry type constants for getType() results
NT_BOOLEAN = 0x01
NT_DOUBLE = 0x02
NT_STRING = 0x04
NT_RAW = 0x08
NT_BOOLEAN_ARRAY = 0x10
NT_DOUBLE_ARRAY = 0x20
NT_STRING_ARRAY = 0x40

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