Send data to Deephaven from a Python client

This guide shows how to send data to Deephaven from an external Python application using pydeephaven and input tables. Input tables allow a client to add, update, and delete rows in a Deephaven table.

Note

If your data source can run directly on the Deephaven server, consider using server-side input tables or DynamicTableWriter instead. Server-side ingestion is generally more efficient because it avoids network overhead.

When to use client-side input tables

Use client-side input tables when:

  • Managing reference data: Upload configuration, lookup tables, or static datasets that may need updates.
  • Tracking state: Maintain the latest status per entity (e.g., device status, order state, user preferences).
  • Interactive editing: Allow users or external systems to add, update, or remove records.
  • Forwarding external data: Relay data from message queues, APIs, or sensors running in separate processes.

Basic pattern

The basic pattern for sending data from a Python client is:

  1. Create an input table on the server using Session.input_table.
  2. Prepare data in your client application.
  3. Convert to PyArrow and upload with Session.import_table.
  4. Add to the input table with InputTable.add. For keyed tables, this inserts new rows or updates existing ones.
  5. Close the uploaded table with Table.close to release server resources and prevent memory leaks.

Repeat steps 2-5 as needed.

Complete example

The following example tracks device status using a keyed input table. Each device has a unique ID, and updates replace the previous status for that device.

Memory management

Each call to import_table creates a temporary table on the server. If you don't release these tables, they accumulate and consume server memory.

Always call close on uploaded tables after adding data to the input table. This releases the server-side export and marks the local object as closed. Use try/finally to ensure cleanup even if the add fails:

Input table types

The client supports three types of input tables:

Keyed

Rows are identified by key columns. Adding a row with an existing key replaces that row. Deletion is supported.

With keyed tables, you can delete rows by providing just the key values:

Append-only

Rows are added to the end of the table. No key columns, no updates, no deletion. Use this when you need a simple log or event stream.

Rows are visible for only one update graph cycle, then disappear. Use this for event streams where you only need to process the latest batch.

Note

Blink tables cannot have key columns.

Batch uploads

For better performance, batch multiple rows into a single upload: