Python API

The timelake package wraps the Rust library with PyO3. Data goes in and out as Apache Arrow, so pyarrow, polars, and anything that implements the Arrow C stream interface work without copies. Calls release the GIL while they run. It needs Python 3.10 or later; wheels cover Linux, macOS, and Windows.

pip install timelake
import timelake

Lake

lake = timelake.Lake(location, storage_options=None, settings=None)

Opens a warehouse. location is a local path or an s3://, gs://, az://, or file:// URL; storage_options is a dict of object store options (see Storage & configuration); settings is a dict of session settings for every query, such as {"read_dedup": "false"}, which override the tables' own (datafusion.* keys set DataFusion options). lake.location returns the normalized URL.

MethodReturns
create_table(name, schema, time_column=None, series_key=None, chunk=None, retention=None, dedup=None, ingest_time=None, properties=None)Table. schema is a pyarrow schema or anything with a .schema. chunk is "hour", "day", or "month"; retention a duration such as "90d"; ingest_time=False leaves out the _ingest_ts column; properties table settings and Iceberg properties.
table(name)Table at its latest version.
tables()list[str] of namespace.table.
sql(query, namespace="default")pyarrow.Table. Unqualified names resolve in namespace. Also runs CREATE, DROP, and REFRESH MATERIALIZED ROLLUP (Rollups), which return one row with the rollup and the rows it took.
latest(table)pyarrow.Table with the newest row per series, from the last-value index (or a scan when the table has none). table is a full name such as "iot.readings".
drop_table(name)Deletes the table and its files. Does nothing if the table doesn't exist.
cache_stats()dict: memory_hits, disk_hits, misses (blocks), bytes_fetched, counted since the lake was opened; None with the block cache off.

Table

Properties: name, location, version, schema (pyarrow). Methods that commit advance the handle to the new version.

MethodReturns
append(data, batch_id=None, maintain=None)dict: rows, files, bytes, version, commit_ms, attempts, duplicate; maintenance when inline maintenance did work, or maintenance_error if it failed after the append committed (the data is in the table: run maintain() later rather than retrying the append). A skipped duplicate batch reports 0 rows, files, and bytes. maintain overrides the table’s auto-maintain setting.
upgrade(dry_run=False, compact=True, keep_snapshots="7d")dict: steps (empty if the table was current), version_before, snapshot_before, keep_snapshots_until_ms. Brings the table to the current format; see Upgrading.
set_properties(properties)Changes table settings, such as {"read_dedup": "false"}; a value of None returns one to its default. One commit of new metadata, no new snapshot. ValueError for an unknown setting, a bad value, or one fixed at creation.
rollback(snapshot_id)Makes an earlier snapshot current again (KeyError if the table has none with that id).
maintain(compact=True, retention=True, expire=True, rollups=True)dict: partitions_compacted, files_rewritten, files_written, rows_rewritten, bytes_rewritten, duplicates_removed, more_to_compact (a group of more than 24 files was merged in parts: run again to finish), partitions_dropped, files_dropped, rollups_refreshed, rollup_rows, snapshots_expired, objects_deleted, seconds. rollups=False skips refreshing the table's rollups.
info()dict, as timelake info --json: name, version, location, contract (time_column, series_key, chunk, dedup, ingest_time_column, retention), schema, size (rows, files, bytes, partitions), snapshot_count and the newest 50 snapshots, manifests, last_value_index.
refresh()Reloads the latest committed version.

Input data

append accepts a pyarrow RecordBatch, Table or RecordBatchReader, a polars DataFrame, or any object with __arrow_c_stream__. Columns are matched by name and converted to the table types where no value is lost (which conversions): an int64 column fits an int32 one if every value is in range, and a float column an integer one if every value is whole. A value that doesn't fit is a ValueError, never a null. Missing nullable columns become nulls, and columns not in the table are an error.

Types

The package ships type information (py.typed and a stub), so editors complete Lake and Table methods and type checkers (ty, mypy, pyright) check calls. The result dicts are typed as timelake.AppendResult, timelake.MaintainReport, and timelake.TableInfo.

Errors

ExceptionWhen
KeyErrorThe table doesn’t exist.
FileExistsErrorCreating a table that already exists.
ValueErrorInvalid input or configuration: a column not in the table, a missing required column, a value that can't be cast to the column type, an unknown storage option, a bad duration (retention="90 parsecs"), chunk name, or property value.
timelake.ConflictErrorAnother writer kept committing first and the change could not be rebased (a subclass of RuntimeError).
RuntimeErrorStorage and query failures. A commit whose outcome can't be told (its write may have landed) says “commit outcome unknown”: load the table again to see whether it committed.

Examples

Create a table and append

import datetime as dt
import pyarrow as pa
import timelake
 
lake = timelake.Lake("s3://my-bucket/lake", storage_options={"aws_region": "eu-west-1"})
schema = pa.schema([("time", pa.timestamp("us", tz="UTC")), ("device_id", pa.string()), ("temp", pa.float64())])
t = lake.create_table("iot.readings", schema, time_column="time", series_key=["device_id"], retention="365d")
 
batch = pa.table({"time": [dt.datetime.now(dt.timezone.utc)], "device_id": ["pump-7"], "temp": [71.5]}, schema=schema)
print(t.append(batch, batch_id="gateway-3-000042"))
 
hourly = lake.sql("""
  SELECT time_bucket(INTERVAL '1 hour', time) AS hour, avg(temp) AS temp
  FROM iot.readings WHERE device_id = 'pump-7' GROUP BY 1 ORDER BY 1
""")

Open an existing table

lake = timelake.Lake("s3://my-bucket/lake")
print(lake.tables())                 # ['iot.readings', ...]
t = lake.table("iot.readings")
print(t.version, t.schema)
print(t.info()["rows"])

Write from polars or pandas

import polars as pl
 
df = pl.DataFrame({
    "time": [dt.datetime(2026, 1, 5, 10, 0, tzinfo=dt.timezone.utc)],
    "device_id": ["pump-7"],
    "temp": [71.5],
})
t.append(df)                                   # polars works directly
 
import pandas as pd
t.append(pa.Table.from_pandas(pdf))            # pandas: convert to Arrow first

Read into pandas or polars

result = lake.sql("SELECT * FROM iot.readings WHERE time > now() - INTERVAL '1 hour'")
pdf = result.to_pandas()
pldf = pl.from_arrow(result)

Retries with a batch id

If a load may be retried (a queue redelivers a message, a network call times out), give each batch a stable id. A repeat is skipped and reported with duplicate: True:

r = t.append(batch, batch_id="kinesis-shard-7-seq-1234")
r = t.append(batch, batch_id="kinesis-shard-7-seq-1234")
r["duplicate"]                                 # True: nothing was written the second time

Maintenance

report = t.maintain()                          # compact, apply retention, refresh rollups, expire snapshots
print(report["duplicates_removed"], report["files_rewritten"])
t.maintain(expire=False)                       # keep old snapshots this time