Skip to content
Closed
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
72 changes: 72 additions & 0 deletions openapi/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,35 @@ paths:
schema:
$ref: '#/components/schemas/PolicyVersion'
description: ''
/v1/tables/upload/:
post:
operationId: upload_table
description: Create a Roe table in the authenticated organization from an uploaded
CSV file. Organization API keys are scoped to one organization; if organization_id
is supplied, it must match that organization.
summary: Upload a CSV as a Roe table
tags:
- tables
- sdk
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/TableUploadRequest'
required: true
responses:
'201':
content:
application/json:
schema:
$ref: '#/components/schemas/TableUploadResponse'
description: ''
'400':
content:
application/json:
schema:
$ref: '#/components/schemas/ErrorResponse'
description: Bad request
/v1/users/current_user/:
get:
operationId: users_current_user_retrieve
Expand Down Expand Up @@ -2734,6 +2763,49 @@ components:
- display_name
- email
- id
TableUploadRequest:
type: object
description: Serializer for public CSV table uploads.
properties:
table_name:
type: string
minLength: 1
description: Name of the Roe table to create from the uploaded CSV
maxLength: 128
file:
type: string
format: binary
description: CSV file to upload
with_headers:
type: boolean
default: true
description: Whether the first row of the CSV contains column headers
organization_id:
type:
- string
- 'null'
format: uuid
description: Optional organization ID. Organization API keys are already
scoped to one organization; if supplied, this must match that organization.
required:
- file
- table_name
TableUploadResponse:
type: object
description: Response payload for a public CSV table upload.
properties:
table_name:
type: string
description: Created Roe table name
organization_id:
type: string
format: uuid
description: Organization that owns the table
summary:
description: ClickHouse import summary for the uploaded file
required:
- organization_id
- table_name
UpdatePolicy:
type: object
description: Serializer for updating policy metadata (name, description)
Expand Down
2 changes: 2 additions & 0 deletions src/roe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
)
from roe.models import FileUpload
from roe.models.job import Job, JobBatch, JobStatus
from roe.api.tables import TablesAPI

try:
__version__ = version("roe-ai")
Expand All @@ -51,6 +52,7 @@
"JobStatus",
# File upload helper
"FileUpload",
"TablesAPI",
# Exceptions
"RoeAPIException",
"AuthenticationError",
Expand Down
1 change: 1 addition & 0 deletions src/roe/_generated/api/tables/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
""" Contains endpoint functions for accessing the API """
202 changes: 202 additions & 0 deletions src/roe/_generated/api/tables/upload_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
from http import HTTPStatus
from typing import Any, cast
from urllib.parse import quote

import httpx

from ...client import AuthenticatedClient, Client
from ...types import Response, UNSET
from ... import errors

from ...models.error_response import ErrorResponse
from ...models.table_upload_request import TableUploadRequest
from ...models.table_upload_response import TableUploadResponse
from typing import cast
Comment thread
jadenfix marked this conversation as resolved.



def _get_kwargs(
*,
body: TableUploadRequest,

) -> dict[str, Any]:
headers: dict[str, Any] = {}






_kwargs: dict[str, Any] = {
"method": "post",
"url": "/v1/tables/upload/",
}

_kwargs["files"] = body.to_multipart()



_kwargs["headers"] = headers
return _kwargs



def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> ErrorResponse | TableUploadResponse | None:
if response.status_code == 201:
response_201 = TableUploadResponse.from_dict(response.json())



return response_201

if response.status_code == 400:
response_400 = ErrorResponse.from_dict(response.json())



return response_400

if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[ErrorResponse | TableUploadResponse]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
*,
client: AuthenticatedClient | Client,
body: TableUploadRequest,

) -> Response[ErrorResponse | TableUploadResponse]:
""" Upload a CSV as a Roe table

Create a Roe table in the authenticated organization from an uploaded CSV file. Organization API
keys are scoped to one organization; if organization_id is supplied, it must match that
organization.

Args:
body (TableUploadRequest): Serializer for public CSV table uploads.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[ErrorResponse | TableUploadResponse]
"""


kwargs = _get_kwargs(
body=body,

)

response = client.get_httpx_client().request(
**kwargs,
)

return _build_response(client=client, response=response)

def sync(
*,
client: AuthenticatedClient | Client,
body: TableUploadRequest,

) -> ErrorResponse | TableUploadResponse | None:
""" Upload a CSV as a Roe table

Create a Roe table in the authenticated organization from an uploaded CSV file. Organization API
keys are scoped to one organization; if organization_id is supplied, it must match that
organization.

Args:
body (TableUploadRequest): Serializer for public CSV table uploads.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
ErrorResponse | TableUploadResponse
"""


return sync_detailed(
client=client,
body=body,

).parsed

async def asyncio_detailed(
*,
client: AuthenticatedClient | Client,
body: TableUploadRequest,

) -> Response[ErrorResponse | TableUploadResponse]:
""" Upload a CSV as a Roe table

Create a Roe table in the authenticated organization from an uploaded CSV file. Organization API
keys are scoped to one organization; if organization_id is supplied, it must match that
organization.

Args:
body (TableUploadRequest): Serializer for public CSV table uploads.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[ErrorResponse | TableUploadResponse]
"""


kwargs = _get_kwargs(
body=body,

)

response = await client.get_async_httpx_client().request(
**kwargs
)

return _build_response(client=client, response=response)

async def asyncio(
*,
client: AuthenticatedClient | Client,
body: TableUploadRequest,

) -> ErrorResponse | TableUploadResponse | None:
""" Upload a CSV as a Roe table

Create a Roe table in the authenticated organization from an uploaded CSV file. Organization API
keys are scoped to one organization; if organization_id is supplied, it must match that
organization.

Args:
body (TableUploadRequest): Serializer for public CSV table uploads.

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
ErrorResponse | TableUploadResponse
"""


return (await asyncio_detailed(
client=client,
body=body,

)).parsed
4 changes: 4 additions & 0 deletions src/roe/_generated/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
from .policy import Policy
from .policy_version import PolicyVersion
from .policy_version_created_by import PolicyVersionCreatedBy
from .table_upload_request import TableUploadRequest
from .table_upload_response import TableUploadResponse
from .update_policy import UpdatePolicy
from .update_policy_request import UpdatePolicyRequest
from .user_info import UserInfo
Expand Down Expand Up @@ -69,6 +71,8 @@
"Policy",
"PolicyVersion",
"PolicyVersionCreatedBy",
"TableUploadRequest",
"TableUploadResponse",
"UpdatePolicy",
"UpdatePolicyRequest",
"UserInfo",
Expand Down
Loading
Loading