A pure Python implementation of NetworkTables, used for robot communications in the FIRST Robotics Competition.
npx @tessl/cli install tessl/pypi-pynetworktables@2021.0.0A pure Python implementation of NetworkTables, used for robot communications in the FIRST Robotics Competition. This library enables non-Driver Station data transmission between robots and other systems across the network, serving as a Python alternative to the C++ ntcore implementation.
pip install pynetworktablesimport networktablesBasic usage with the global instance:
from networktables import NetworkTablesFor advanced usage with custom instances:
from networktables import NetworkTablesInstance, NetworkTable, NetworkTableEntry, ValueProperty decorator for class-based integration:
from networktables.util import ntproperty, ChooserControlfrom networktables import NetworkTables
# Initialize as client to connect to robot
NetworkTables.initialize(server='roborio-1234-frc.local')
# Get SmartDashboard table for robot data sharing
sd = NetworkTables.getTable('SmartDashboard')
# Send data to robot
sd.putNumber('driveSpeed', 0.8)
sd.putString('autonomousMode', 'defense')
sd.putBoolean('climbEnabled', True)
# Read data from robot
batteryVoltage = sd.getNumber('batteryVoltage', 0.0)
robotState = sd.getString('robotState', 'unknown')
isConnected = NetworkTables.isConnected()
# Using entries for more efficient operations
speedEntry = NetworkTables.getEntry('/SmartDashboard/driveSpeed')
speedEntry.setDouble(0.5)
currentSpeed = speedEntry.getDouble(0.0)PyNetworkTables uses a hierarchical table structure with type-safe entry operations:
The library supports dual backends: the preferred pyntcore (C++ implementation) with fallback to pure Python _pynetworktables for maximum compatibility.
Core NetworkTables instance functionality for connection management, server operations, and global configuration. Provides both singleton access and support for multiple independent instances.
class NetworkTablesInstance:
@classmethod
def getDefault() -> NetworkTablesInstance: ...
@classmethod
def create() -> NetworkTablesInstance: ...
def initialize(server=None): ...
def startServer(persistFilename="networktables.ini", listenAddress="", port=1735): ...
def startClient(server_or_servers): ...
def shutdown(): ...Table-based interface for reading and writing values in NetworkTable hierarchies. Provides convenient methods for all supported data types and table navigation.
class NetworkTable:
def getEntry(key: str) -> NetworkTableEntry: ...
def putNumber(key: str, value: float): ...
def getNumber(key: str, defaultValue: float) -> float: ...
def putString(key: str, value: str): ...
def getString(key: str, defaultValue: str) -> str: ...
def putBoolean(key: str, value: bool): ...
def getBoolean(key: str, defaultValue: bool) -> bool: ...Type-safe interface to individual NetworkTables entries with efficient access patterns. Provides the most performant way to read and write NetworkTable values.
class NetworkTableEntry:
def exists() -> bool: ...
def getType() -> int: ...
def setValue(value): ...
def setDouble(value: float): ...
def getDouble(defaultValue: float) -> float: ...
def setString(value: str): ...
def getString(defaultValue: str) -> str: ...Real-time notification system for NetworkTable changes including entry modifications, connection status, and table updates. Essential for responsive robotics applications.
def addEntryListener(listener: Callable, immediateNotify: bool = True, localNotify: bool = True): ...
def addConnectionListener(listener: Callable, immediateNotify: bool = False): ...
def removeEntryListener(listener): ...
def removeConnectionListener(listener): ...Data persistence across restarts, entry management, and bulk operations. Critical for maintaining configuration and state information between robot sessions.
def savePersistent(filename: str): ...
def loadPersistent(filename: str): ...
def setPersistent(key: str): ...
def clearPersistent(key: str): ...
def deleteAllEntries(): ...Persistence and Data Management
Property decorators and utility classes for seamless integration with object-oriented robotics code and WPILib components.
def ntproperty(key: str, defaultValue, writeDefault: bool = True,
doc: str = None, persistent: bool = False,
*, inst = NetworkTables) -> property: ...
class ChooserControl:
def __init__(key: str, on_choices=None, on_selected=None, *, inst=NetworkTables): ...
def getChoices() -> List[str]: ...
def getSelected() -> Optional[str]: ...class Value:
"""Immutable container for NetworkTables values with type information."""
type: int
value: Any
@classmethod
def makeBoolean(value: bool) -> Value: ...
@classmethod
def makeDouble(value: float) -> Value: ...
@classmethod
def makeString(value: str) -> Value: ...
@classmethod
def makeBooleanArray(value: List[bool]) -> Value: ...
@classmethod
def makeDoubleArray(value: List[float]) -> Value: ...
@classmethod
def makeStringArray(value: List[str]) -> Value: ...
# Entry Type Constants
NT_BOOLEAN = 0x01
NT_DOUBLE = 0x02
NT_STRING = 0x04
NT_RAW = 0x08
NT_BOOLEAN_ARRAY = 0x10
NT_DOUBLE_ARRAY = 0x20
NT_STRING_ARRAY = 0x40
# Entry Flag Constants
NT_PERSISTENT = 0x01
# Notification Flag Constants
NT_NOTIFY_IMMEDIATE = 0x01
NT_NOTIFY_LOCAL = 0x02
NT_NOTIFY_NEW = 0x04
NT_NOTIFY_DELETE = 0x08
NT_NOTIFY_UPDATE = 0x10
NT_NOTIFY_FLAGS = 0x20