Skip to main content
Datastore parts handle recording driving data to tubs and managing tub datasets.

Tub (v2)

The primary datastore class for recording and reading driving data. Constructor:
str
Path to tub directory
list
default:"[]"
List of input channel names (e.g., [‘cam/image_array’, ‘user/angle’])
list
default:"[]"
List of data types corresponding to inputs (e.g., [‘image_array’, ‘float’])
list
default:"[]"
List of metadata key:value pairs
int
default:"1000"
Maximum catalog size before flushing
bool
default:"false"
Open tub in read-only mode
Supported Data Types:
  • 'float': Floating point numbers
  • 'int': Integers
  • 'str': Strings
  • 'boolean': Boolean values
  • 'image_array': NumPy image arrays (saved as JPEG)
  • 'gray16_array': 16-bit grayscale images (saved as PNG)
  • 'nparray': Generic NumPy arrays (saved as list)
  • 'list' or 'vector': Lists of values
Methods:
(record: dict) -> None
Write a single record to the tub
(record_indexes: list) -> None
Delete specific records by index
(n: int) -> None
Delete the last N records
(record_indexes: list) -> None
Restore previously deleted records
() -> None
Close the tub and flush data
() -> Iterator
Iterate over all records in the tub
() -> int
Get number of records in the tub
Usage Example:

TubWriter

Donkeycar part for writing records to a tub. Constructor:
str
Path to tub directory
list
List of input channel names
list
List of data types
list
Metadata key:value pairs
Methods:
(*args) -> int
Donkeycar part interface. Accepts values matching inputs list and writes record. Returns current record index.
() -> None
Close the tub
Usage Example:

TubHandler

Helper class for managing multiple tubs. Constructor:
str
Base path containing tubs
Methods:
(path: str) -> list
Get list of tub directories
(path: str) -> int
Get next available tub number
() -> str
Create a new tub path with incremented number and date
(inputs, types, user_meta) -> TubWriter
Create a new TubWriter with auto-generated path
Usage Example:

TubWiper

Part for deleting recent records during recording (delete bad data on the fly). Constructor:
Tub or TubWriter
Tub to operate on
int
default:"20"
Number of records to delete when triggered
Methods:
(is_delete: bool) -> None
Delete records when trigger switches from False to True (debounced)
Usage Example:

Legacy Tub (v1)

Older tub implementation (deprecated, use Tub v2 instead). Constructor:
Methods: Similar to v2 but with different internal implementation.

Record Structure

Record Format

Each record contains:
  • User-defined fields (inputs)
  • Private metadata:
    • _timestamp_ms: Timestamp in milliseconds
    • _index: Record index
    • _session_id: Recording session ID

Example Record

Tub Directory Structure

Manifest File

The manifest.json contains:
  • Input channel names and types
  • Metadata
  • Current index
  • Session information
  • Record catalog
Example:

Configuration

Typical datastore configuration in myconfig.py:

Integration Example

From templates like complete.py:

Reading Tubs for Training