or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

entry-interface.mdindex.mdinstance-management.mdintegration-utilities.mdlisteners-events.mdpersistence-data.mdtable-operations.md
tile.json

tessl/pypi-pynetworktables

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

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pynetworktables@2021.0.x

To install, run

npx @tessl/cli install tessl/pypi-pynetworktables@2021.0.0

index.mddocs/

PyNetworkTables

A 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.

Package Information

  • Package Name: pynetworktables
  • Language: Python
  • Installation: pip install pynetworktables
  • Python Requirements: >=3.5

Core Imports

import networktables

Basic usage with the global instance:

from networktables import NetworkTables

For advanced usage with custom instances:

from networktables import NetworkTablesInstance, NetworkTable, NetworkTableEntry, Value

Property decorator for class-based integration:

from networktables.util import ntproperty, ChooserControl

Basic Usage

from 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)

Architecture

PyNetworkTables uses a hierarchical table structure with type-safe entry operations:

  • NetworkTablesInstance: Main instance managing connections, servers, and global operations
  • NetworkTable: Represents a subtable in the hierarchy for grouped key-value operations
  • NetworkTableEntry: Individual entry providing type-safe access to specific keys
  • Value: Immutable container for NetworkTables data with type information

The library supports dual backends: the preferred pyntcore (C++ implementation) with fallback to pure Python _pynetworktables for maximum compatibility.

Capabilities

Instance Management

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(): ...

Instance Management

Table Operations

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: ...

Table Operations

Entry Interface

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: ...

Entry Interface

Listeners and Events

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): ...

Listeners and Events

Persistence and Data Management

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

Integration Utilities

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]: ...

Integration Utilities

Types

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