@@ -1167,3 +1167,153 @@ def generic_query(
11671167 if use_job :
11681168 return job_request (client = client , request_obj = req )
11691169 return client .request (request_obj = req , raise_for_status = raise_for_status )
1170+
1171+
1172+ def estimate (
1173+ client : AitoClient , query : Dict , raise_for_status : Optional [bool ] = None , use_job : bool = False
1174+ ) -> Union [aito_responses .EstimateResponse , RequestError ]:
1175+ """send a query to the `Estimate API <https://aito.ai/docs/api/#post-api-v1-estimate>`__
1176+
1177+ The Estimate operation predicts numeric values using K-NN with transformation pipelines.
1178+
1179+ :param client: the AitoClient instance
1180+ :type client: AitoClient
1181+ :param query: the estimate query
1182+ :type query: Dict
1183+ :param raise_for_status: raise :class:`.RequestError` if the request fails instead of returning the error
1184+ If set to None, value from Client will be used. Defaults to None
1185+ :type raise_for_status: Optional[bool]
1186+ :param use_job: use job fo request that takes longer than 30 seconds, defaults to False
1187+ :type use_job: bool
1188+ :return: :class:`.EstimateResponse` or :class:`.RequestError` if an error occurred and not raise_for_status
1189+ :rtype: Union[EstimateResponse, RequestError]
1190+ """
1191+ req = aito_requests .EstimateRequest (query )
1192+ if use_job :
1193+ return job_request (client = client , request_obj = req )
1194+ return client .request (request_obj = req , raise_for_status = raise_for_status )
1195+
1196+
1197+ def aggregate (
1198+ client : AitoClient , query : Dict , raise_for_status : Optional [bool ] = None , use_job : bool = False
1199+ ) -> Union [aito_responses .AggregateResponse , RequestError ]:
1200+ """send a query to the `Aggregate API <https://aito.ai/docs/api/#post-api-v1-aggregate>`__
1201+
1202+ Returns aggregated values like averages, sums, counts, etc.
1203+
1204+ :param client: the AitoClient instance
1205+ :type client: AitoClient
1206+ :param query: the aggregate query
1207+ :type query: Dict
1208+ :param raise_for_status: raise :class:`.RequestError` if the request fails instead of returning the error
1209+ If set to None, value from Client will be used. Defaults to None
1210+ :type raise_for_status: Optional[bool]
1211+ :param use_job: use job fo request that takes longer than 30 seconds, defaults to False
1212+ :type use_job: bool
1213+ :return: :class:`.AggregateResponse` or :class:`.RequestError` if an error occurred and not raise_for_status
1214+ :rtype: Union[AggregateResponse, RequestError]
1215+ """
1216+ req = aito_requests .AggregateRequest (query )
1217+ if use_job :
1218+ return job_request (client = client , request_obj = req )
1219+ return client .request (request_obj = req , raise_for_status = raise_for_status )
1220+
1221+
1222+ def modify (
1223+ client : AitoClient ,
1224+ query : Union [Dict , 'aito_requests.ModifyOperation' , List ['aito_requests.ModifyOperation' ]],
1225+ raise_for_status : Optional [bool ] = None ,
1226+ use_job : bool = False
1227+ ) -> Union [aito_responses .ModifyResponse , RequestError ]:
1228+ """perform atomic modifications on table data using the
1229+ `Modify API <https://aito.ai/docs/api/#post-api-v1-data-modify>`__
1230+
1231+ The modify endpoint allows individual modifications or a sequence
1232+ of modifications in one atomic operation.
1233+
1234+ Can accept a raw query dict, a single ModifyOperation, or a list of ModifyOperations::
1235+
1236+ from aito.client.requests import Insert, Update, Delete
1237+
1238+ # Insert a single entry
1239+ api.modify(client, Insert("products", {"id": "1", "name": "Apple"}))
1240+
1241+ # Update entries matching a condition
1242+ api.modify(client, Update("products").where({"id": "1"}).set({"name": "New Name"}))
1243+
1244+ # Delete entries matching a condition
1245+ api.modify(client, Delete("products", {"id": "1"}))
1246+
1247+ # Multiple operations atomically
1248+ api.modify(client, [
1249+ Insert("products", {"id": "1", "name": "Apple"}),
1250+ Update("products").where({"id": "2"}).set({"name": "Banana"}),
1251+ Delete("products", {"id": "3"})
1252+ ])
1253+
1254+ :param client: the AitoClient instance
1255+ :type client: AitoClient
1256+ :param query: the modify query - can be a Dict, a ModifyOperation (Insert/Update/Delete),
1257+ or a list of ModifyOperations
1258+ :type query: Union[Dict, ModifyOperation, List[ModifyOperation]]
1259+ :param raise_for_status: raise :class:`.RequestError` if the request fails instead of returning the error
1260+ If set to None, value from Client will be used. Defaults to None
1261+ :type raise_for_status: Optional[bool]
1262+ :param use_job: use job fo request that takes longer than 30 seconds, defaults to False
1263+ :type use_job: bool
1264+ :return: :class:`.ModifyResponse` or :class:`.RequestError` if an error occurred and not raise_for_status
1265+ :rtype: Union[ModifyResponse, RequestError]
1266+ """
1267+ # Convert ModifyOperation(s) to query dict
1268+ if isinstance (query , aito_requests .ModifyOperation ):
1269+ query = query .to_query ()
1270+ elif isinstance (query , list ) and len (query ) > 0 and isinstance (query [0 ], aito_requests .ModifyOperation ):
1271+ # Multiple operations must be wrapped in {"operations": [...]}
1272+ query = {"operations" : [op .to_query () for op in query ]}
1273+ elif isinstance (query , list ):
1274+ # Raw list of dicts also needs wrapping
1275+ query = {"operations" : query }
1276+
1277+ req = aito_requests .ModifyRequest (query )
1278+ if use_job :
1279+ return job_request (client = client , request_obj = req )
1280+ return client .request (request_obj = req , raise_for_status = raise_for_status )
1281+
1282+
1283+ def batch (
1284+ client : AitoClient ,
1285+ queries : List [Dict ],
1286+ raise_for_status : Optional [bool ] = None
1287+ ) -> Union [aito_responses .BatchResponse , RequestError ]:
1288+ """execute multiple queries in a single request using the
1289+ `Batch API <https://aito.ai/docs/api/#post-api-v1-batch>`__
1290+
1291+ The batch endpoint allows executing multiple queries (predict, similarity,
1292+ search, etc.) in a single HTTP request for improved performance.
1293+
1294+ Example::
1295+
1296+ import aito.api as api
1297+
1298+ # Execute multiple queries in one request
1299+ results = api.batch(client, [
1300+ {"from": "products", "where": {"name": "rye bread"}, "predict": "category"},
1301+ {"from": "products", "similarity": {"name": "rye bread"}, "limit": 5}
1302+ ])
1303+
1304+ # Access individual results
1305+ predict_result = results[0] # First query result
1306+ similarity_result = results[1] # Second query result
1307+
1308+ :param client: the AitoClient instance
1309+ :type client: AitoClient
1310+ :param queries: a list of query dictionaries to execute in batch
1311+ :type queries: List[Dict]
1312+ :param raise_for_status: raise :class:`.RequestError` if the request fails instead of returning the error
1313+ If set to None, value from Client will be used. Defaults to None
1314+ :type raise_for_status: Optional[bool]
1315+ :return: :class:`.BatchResponse` containing results for each query, or :class:`.RequestError` if an error occurred
1316+ :rtype: Union[BatchResponse, RequestError]
1317+ """
1318+ req = aito_requests .BatchRequest (queries )
1319+ return client .request (request_obj = req , raise_for_status = raise_for_status )
0 commit comments