Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ All notable changes to this project will be documented in this file.
## [0.1.0] - 2026-03-09
### Added
- Initial release of the Python SDK for the Altertable Lakehouse API.
- Implemented `append`, `upload`, `query`, `query_all`, `validate`, `get_query`, and `cancel_query` methods.
- Implemented `append`, `upsert`, `query`, `query_all`, `validate`, `get_query`, and `cancel_query` methods.
- Full typing support with `pydantic` models.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,17 @@ if res.task_id:
print(task.status)
```

### Upload
### Upsert

```python
from altertable_lakehouse.models import UploadFormat, UploadMode
from altertable_lakehouse.models import UpsertMode

with open("data.csv", "rb") as f:
client.upload(
client.upsert(
catalog="my_cat",
schema="my_schema",
table="my_table",
format=UploadFormat.CSV,
mode=UploadMode.APPEND,
mode=UpsertMode.APPEND,
content=f.read()
)
```
Expand Down
15 changes: 6 additions & 9 deletions src/altertable_lakehouse/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
ValidateResponse,
AutocompleteRequest,
AutocompleteResponse,
UploadFormat,
UploadMode,
UpsertMode,
QueryMetadata,
QueryResult,
)
Expand Down Expand Up @@ -119,31 +118,29 @@ def get_task(self, task_id: str) -> TaskResponse:
except httpx.RequestError as e:
self._handle_error(e)

def upload(
def upsert(
self,
catalog: str,
schema: str,
table: str,
format: UploadFormat,
mode: UploadMode,
content: bytes,
mode: Optional[UpsertMode] = None,
primary_key: Optional[str] = None,
) -> None:
params = {
"catalog": catalog,
"schema": schema,
"table": table,
"format": format.value,
"mode": mode.value,
}
if mode is not None:
params["mode"] = mode.value
if primary_key:
params["primary_key"] = primary_key
try:
res = self._client.post(
"/upload",
"/upsert",
params=params,
content=content,
headers={"Content-Type": "application/octet-stream"},
)
self._check_response(res)
except httpx.RequestError as e:
Expand Down
8 changes: 1 addition & 7 deletions src/altertable_lakehouse/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ class ComputeSize(str, Enum):
XL = "XL"


class UploadFormat(str, Enum):
CSV = "csv"
JSON = "json"
PARQUET = "parquet"


class UploadMode(str, Enum):
class UpsertMode(str, Enum):
CREATE = "create"
APPEND = "append"
UPSERT = "upsert"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def test_query_all(client):
assert isinstance(res.columns, list)
assert isinstance(res.rows, list)

def test_upload(client):
def test_upsert(client):
try:
client.upload(catalog="cat", schema="sch", table="tbl", format=models.UploadFormat.JSON, mode=models.UploadMode.APPEND, content=b'{"a":1}')
client.upsert(catalog="cat", schema="sch", table="tbl", mode=models.UpsertMode.APPEND, content=b'{"a":1}')
except errors.BadRequestError:
pass

Expand Down
Loading