stampdb

class stampdb.stampdb.StampDB(filename: str, schema: dict | None = None)

Python wrapper for the StampDB C++ class.

A time-series database that stores CSV-like data with efficient time-based indexing and CRUD operations.

append_point(point: Point) bool

Append a new data point to the database.

Args:
point: Point

Point object to append.

Returns:

True if the point was successfully appended.

checkpoint() bool

Force a checkpoint operation.

Returns:

True if checkpoint was successful.

property checkpoint_threshold: int

Get the checkpoint threshold (number of operations before auto-compaction).

close()

Close the database connection.

compact() ndarray

Compact the database by removing deleted entries.

Returns:

NumPy structured array containing all remaining data after compaction.

delete_point(time: float | datetime) ndarray

Delete a data point at the specified time.

Args:
time: Union[float, datetime]

The time point to delete. Can be Unix timestamp or datetime object.

Returns:

NumPy structured array containing the deleted data (if any).

get_timestamps() Tuple[datetime, datetime]

Get the first and last timestamps in the database.

Returns:

Tuple[datetime, datetime]: (first_timestamp, last_timestamp) as datetime objects

Raises:

ValueError: If the database is empty

read(time: float | datetime) ndarray

Read data at a specific time.

Args:
time: Union[float, datetime]

The time point to read data from. Can be a Unix timestamp (float) or datetime object.

Returns:

NumPy structured array containing the data at the specified time.

read_range(start_time: float | datetime, end_time: float | datetime) ndarray

Read data within a time range.

Args:
start_time: Union[float, datetime]

Start of the time range (inclusive). Can be Unix timestamp or datetime object.

end_time: Union[float, datetime]

End of the time range (inclusive). Can be Unix timestamp or datetime object.

Returns:

NumPy structured array containing all data points within the time range.

update_point(point: Point) bool

Update an existing data point in the database.

Args:
point: Point

Point object to update.

Returns:

True if the point was successfully updated.