diff --git a/google/genai/batches.py b/google/genai/batches.py index 72daf6b24..b3703b86f 100644 --- a/google/genai/batches.py +++ b/google/genai/batches.py @@ -1902,6 +1902,34 @@ def delete( self._api_client._verify_response(return_value) return return_value + def list( + self, *, config: Optional[types.ListBatchJobsConfigOrDict] = None + ) -> Pager[types.BatchJob]: + """Lists batch jobs. + + Args: + config (ListBatchJobsConfig): Optional configuration for the list request. + + Returns: + A Pager object that contains one page of batch jobs. When iterating over + the pager, it automatically fetches the next page if there are more. + + Usage: + + .. code-block:: python + config = {'page_size': 10} + for batch_job in client.batches.list(config): + print(batch_job.name) + """ + + list_request = self._list + return Pager( + 'batch_jobs', + list_request, + self._list(config=config), + config, + ) + def create( self, *, @@ -1997,35 +2025,6 @@ def create_embeddings( else: return self._create_embeddings(model=model, src=src, config=config) - def list( - self, *, config: Optional[types.ListBatchJobsConfigOrDict] = None - ) -> Pager[types.BatchJob]: - """Lists batch jobs. - - Args: - config (ListBatchJobsConfig): Optional configuration for the list request. - - Returns: - A Pager object that contains one page of batch jobs. When iterating over - the pager, it automatically fetches the next page if there are more. - - Usage: - - .. code-block:: python - - batch_jobs = client.batches.list(config={"page_size": 10}) - for batch_job in batch_jobs: - print(f"Batch job: {batch_job.name}, state {batch_job.state}") - """ - if config is None: - config = types.ListBatchJobsConfig() - return Pager( - 'batch_jobs', - self._list, - self._list(config=config), - config, - ) - class AsyncBatches(_api_module.BaseModule): @@ -2452,6 +2451,33 @@ async def delete( self._api_client._verify_response(return_value) return return_value + async def list( + self, *, config: Optional[types.ListBatchJobsConfigOrDict] = None + ) -> AsyncPager[types.BatchJob]: + """Lists batch jobs asynchronously. + + Args: + config (ListBatchJobsConfig): Optional configuration for the list request. + + Returns: + A Pager object that contains one page of batch jobs. When iterating over + the pager, it automatically fetches the next page if there are more. + + Usage: + + .. code-block:: python + async for batch_job in await client.aio.batches.list(): + print(batch_job.name) + """ + + list_request = self._list + return AsyncPager( + 'batch_jobs', + list_request, + await self._list(config=config), + config, + ) + async def create( self, *, @@ -2552,33 +2578,3 @@ async def create_embeddings( raise ValueError('Vertex AI does not support batches.create_embeddings.') else: return await self._create_embeddings(model=model, src=src, config=config) - - async def list( - self, *, config: Optional[types.ListBatchJobsConfigOrDict] = None - ) -> AsyncPager[types.BatchJob]: - """Lists batch jobs asynchronously. - - Args: - config (ListBatchJobsConfig): Optional configuration for the list request. - - Returns: - A Pager object that contains one page of batch jobs. When iterating over - the pager, it automatically fetches the next page if there are more. - - Usage: - - .. code-block:: python - - batch_jobs = await client.aio.batches.list(config={'page_size': 5}) - print(f"current page: {batch_jobs.page}") - await batch_jobs_pager.next_page() - print(f"next page: {batch_jobs_pager.page}") - """ - if config is None: - config = types.ListBatchJobsConfig() - return AsyncPager( - 'batch_jobs', - self._list, - await self._list(config=config), - config, - ) diff --git a/google/genai/caches.py b/google/genai/caches.py index a7376398b..e905f7187 100644 --- a/google/genai/caches.py +++ b/google/genai/caches.py @@ -1129,15 +1129,6 @@ def update( def _list( self, *, config: Optional[types.ListCachedContentsConfigOrDict] = None ) -> types.ListCachedContentsResponse: - """Lists cached content configurations. - - .. code-block:: python - - cached_contents = client.caches.list(config={'page_size': 2}) - for cached_content in cached_contents: - print(cached_content) - """ - parameter_model = types._ListCachedContentsParameters( config=config, ) @@ -1196,9 +1187,28 @@ def _list( def list( self, *, config: Optional[types.ListCachedContentsConfigOrDict] = None ) -> Pager[types.CachedContent]: + """Lists cached contents. + + Args: + config (ListCachedContentsConfig): Optional configuration for the list + request. + + Returns: + A Pager object that contains one page of cached contents. When iterating + over + the pager, it automatically fetches the next page if there are more. + + Usage: + + .. code-block:: python + for cached_content in client.caches.list(): + print(cached_content.name) + """ + + list_request = self._list return Pager( 'cached_contents', - self._list, + list_request, self._list(config=config), config, ) @@ -1505,15 +1515,6 @@ async def update( async def _list( self, *, config: Optional[types.ListCachedContentsConfigOrDict] = None ) -> types.ListCachedContentsResponse: - """Lists cached content configurations. - - .. code-block:: python - - cached_contents = await client.aio.caches.list(config={'page_size': 2}) - async for cached_content in cached_contents: - print(cached_content) - """ - parameter_model = types._ListCachedContentsParameters( config=config, ) @@ -1574,9 +1575,28 @@ async def _list( async def list( self, *, config: Optional[types.ListCachedContentsConfigOrDict] = None ) -> AsyncPager[types.CachedContent]: + """Lists cached contents asynchronously. + + Args: + config (ListCachedContentsConfig): Optional configuration for the list + request. + + Returns: + A Pager object that contains one page of cached contents. When iterating + over + the pager, it automatically fetches the next page if there are more. + + Usage: + + .. code-block:: python + async for cached_content in await client.aio.caches.list(): + print(cached_content.name) + """ + + list_request = self._list return AsyncPager( 'cached_contents', - self._list, + list_request, await self._list(config=config), config, ) diff --git a/google/genai/documents.py b/google/genai/documents.py index 740163a76..0e7016156 100644 --- a/google/genai/documents.py +++ b/google/genai/documents.py @@ -249,17 +249,6 @@ def _list( parent: str, config: Optional[types.ListDocumentsConfigOrDict] = None, ) -> types.ListDocumentsResponse: - """Lists all Documents in a FileSearchStore. - - Args: - parent (str): The name of the FileSearchStore containing the Documents. - config (ListDocumentsConfig | None): Optional parameters for the request, - such as page_size. - - Returns: - ListDocumentsResponse: A paginated list of Documents. - """ - parameter_model = types._ListDocumentsParameters( parent=parent, config=config, @@ -328,6 +317,7 @@ def list( for document in client.documents.list(parent='rag_store_name'): print(f"document: {document.name} - {document.display_name}") """ + list_request = partial(self._list, parent=parent) return Pager( 'documents', @@ -461,17 +451,6 @@ async def _list( parent: str, config: Optional[types.ListDocumentsConfigOrDict] = None, ) -> types.ListDocumentsResponse: - """Lists all Documents in a FileSearchStore. - - Args: - parent (str): The name of the FileSearchStore containing the Documents. - config (ListDocumentsConfig | None): Optional parameters for the request, - such as page_size. - - Returns: - ListDocumentsResponse: A paginated list of Documents. - """ - parameter_model = types._ListDocumentsParameters( parent=parent, config=config, @@ -540,9 +519,10 @@ async def list( Usage: .. code-block:: python async for document in await - client.documents.list(parent='rag_store_name'): + client.aio.documents.list(parent='rag_store_name'): print(f"document: {document.name} - {document.display_name}") """ + list_request = partial(self._list, parent=parent) return AsyncPager( 'documents', diff --git a/google/genai/file_search_stores.py b/google/genai/file_search_stores.py index 38b9e8730..02e63fc86 100644 --- a/google/genai/file_search_stores.py +++ b/google/genai/file_search_stores.py @@ -499,16 +499,6 @@ def delete( def _list( self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None ) -> types.ListFileSearchStoresResponse: - """Lists all FileSearchStore owned by the user. - - Args: - config (ListFileSearchStoresConfig | None): Optional parameters for the - request, such as page_size. - - Returns: - ListFileSearchStoresResponse: A paginated list of FileSearchStore. - """ - parameter_model = types._ListFileSearchStoresParameters( config=config, ) @@ -705,6 +695,36 @@ def import_file( self._api_client._verify_response(return_value) return return_value + def list( + self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None + ) -> Pager[types.FileSearchStore]: + """Lists FileSearchStores. + + Args: + config (ListFileSearchStoresConfig): Optional configuration for the list + request. + + Returns: + A Pager object that contains one page of file search stores. When + iterating over + the pager, it automatically fetches the next page if there are more. + + Usage: + + .. code-block:: python + for file_search_store in client.file_search_stores.list(): + print(f"file search store: {file_search_store.name} - + {file_search_store.display_name}") + """ + + list_request = self._list + return Pager( + 'file_search_stores', + list_request, + self._list(config=config), + config, + ) + def upload_to_file_search_store( self, *, @@ -781,34 +801,6 @@ def upload_to_file_search_store( response=response_dict, kwargs={} ) - def list( - self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None - ) -> Pager[types.FileSearchStore]: - """Lists FileSearchStores. - - Args: - config (ListFileSearchStoresConfig): Optional configuration for the list - request. - - Returns: - A Pager object that contains one page of file search stores. When - iterating over - the pager, it automatically fetches the next page if there are more. - - Usage: - - .. code-block:: python - for file_search_store in client.file_search_stores.list(): - print(f"file search store: {file_search_store.name} - - {file_search_store.display_name}") - """ - return Pager( - 'file_search_stores', - self._list, - self._list(config=config), - config, - ) - class AsyncFileSearchStores(_api_module.BaseModule): @@ -999,16 +991,6 @@ async def delete( async def _list( self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None ) -> types.ListFileSearchStoresResponse: - """Lists all FileSearchStore owned by the user. - - Args: - config (ListFileSearchStoresConfig | None): Optional parameters for the - request, such as page_size. - - Returns: - ListFileSearchStoresResponse: A paginated list of FileSearchStore. - """ - parameter_model = types._ListFileSearchStoresParameters( config=config, ) @@ -1207,6 +1189,36 @@ async def import_file( self._api_client._verify_response(return_value) return return_value + async def list( + self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None + ) -> AsyncPager[types.FileSearchStore]: + """Lists FileSearchStores asynchronously. + + Args: + config (ListFileSearchStoresConfig): Optional parameters for the request, + such as page_size. + + Returns: + A Pager object that contains one page of FileSearchStores. When iterating + over + the pager, it automatically fetches the next page if there are more. + + Usage: + + .. code-block:: python + async for file_search_store in await client.aio.file_search_stores.list(): + print(f"file search store: {file_search_store.name} - + {file_search_store.display_name}") + """ + + list_request = self._list + return AsyncPager( + 'file_search_stores', + list_request, + await self._list(config=config), + config, + ) + async def upload_to_file_search_store( self, *, @@ -1282,31 +1294,3 @@ async def upload_to_file_search_store( return types.UploadToFileSearchStoreOperation._from_response( response=response_dict, kwargs={} ) - - async def list( - self, *, config: Optional[types.ListFileSearchStoresConfigOrDict] = None - ) -> AsyncPager[types.FileSearchStore]: - """Lists FileSearchStores asynchronously. - - Args: - config (ListFileSearchStoresConfig): Optional configuration for the list - request. - - Returns: - A Pager object that contains one page of FileSearchStores. When iterating - over - the pager, it automatically fetches the next page if there are more. - - Usage: - - .. code-block:: python - async for file_search_store in await client.file_search_stores.list(): - print(f"file search store: {file_search_store.name} - - {file_search_store.display_name}") - """ - return AsyncPager( - 'file_search_stores', - self._list, - await self._list(config=config), - config, - ) diff --git a/google/genai/files.py b/google/genai/files.py index 034bd9b6e..7cb23a89f 100644 --- a/google/genai/files.py +++ b/google/genai/files.py @@ -154,23 +154,6 @@ class Files(_api_module.BaseModule): def _list( self, *, config: Optional[types.ListFilesConfigOrDict] = None ) -> types.ListFilesResponse: - """Lists all files from the service. - - Args: - config (ListFilesConfig): Optional, configuration for the list method. - - Returns: - ListFilesResponse: The response for the list method. - - Usage: - - .. code-block:: python - - pager = client.files.list(config={'page_size': 10}) - for file in pager.page: - print(file.name) - """ - parameter_model = types._ListFilesParameters( config=config, ) @@ -419,6 +402,34 @@ def delete( self._api_client._verify_response(return_value) return return_value + def list( + self, *, config: Optional[types.ListFilesConfigOrDict] = None + ) -> Pager[types.File]: + """Lists all files from the service. + + Args: + config (ListFilesConfig): Optional, configuration for the list method. + + Returns: + A Pager object that contains one page of files. When iterating over + the pager, it automatically fetches the next page if there are more. + + Usage: + + .. code-block:: python + + for file in client.files.list(config={'page_size': 10}): + print(file.name) + """ + + list_request = self._list + return Pager( + 'files', + list_request, + self._list(config=config), + config, + ) + def upload( self, *, @@ -495,16 +506,6 @@ def upload( kwargs=config_model.model_dump() if config else {}, ) - def list( - self, *, config: Optional[types.ListFilesConfigOrDict] = None - ) -> Pager[types.File]: - return Pager( - 'files', - self._list, - self._list(config=config), - config, - ) - def download( self, *, @@ -592,23 +593,6 @@ class AsyncFiles(_api_module.BaseModule): async def _list( self, *, config: Optional[types.ListFilesConfigOrDict] = None ) -> types.ListFilesResponse: - """Lists all files from the service. - - Args: - config (ListFilesConfig): Optional, configuration for the list method. - - Returns: - ListFilesResponse: The response for the list method. - - Usage: - - .. code-block:: python - - pager = await client.aio.files.list(config={'page_size': 10}) - for file in pager.page: - print(file.name) - """ - parameter_model = types._ListFilesParameters( config=config, ) @@ -861,6 +845,34 @@ async def delete( self._api_client._verify_response(return_value) return return_value + async def list( + self, *, config: Optional[types.ListFilesConfigOrDict] = None + ) -> AsyncPager[types.File]: + """Lists all files from the service asynchronously. + + Args: + config (ListFilesConfig): Optional, configuration for the list method. + + Returns: + A Pager object that contains one page of files. When iterating over + the pager, it automatically fetches the next page if there are more. + + Usage: + + .. code-block:: python + + async for file in await client.aio.files.list(config={'page_size': 10}): + print(file.name) + """ + + list_request = self._list + return AsyncPager( + 'files', + list_request, + await self._list(config=config), + config, + ) + async def upload( self, *, @@ -942,16 +954,6 @@ async def upload( kwargs=config_model.model_dump() if config else {}, ) - async def list( - self, *, config: Optional[types.ListFilesConfigOrDict] = None - ) -> AsyncPager[types.File]: - return AsyncPager( - 'files', - self._list, - await self._list(config=config), - config, - ) - async def download( self, *, diff --git a/google/genai/tests/client/test_client_requests.py b/google/genai/tests/client/test_client_requests.py index f52d1bef1..89f8bc756 100644 --- a/google/genai/tests/client/test_client_requests.py +++ b/google/genai/tests/client/test_client_requests.py @@ -19,6 +19,8 @@ from ... import _api_client as api_client from ... import Client from ... import types +from unittest import mock +import pytest def build_test_client(monkeypatch): diff --git a/google/genai/tunings.py b/google/genai/tunings.py index 438da0467..ded288758 100644 --- a/google/genai/tunings.py +++ b/google/genai/tunings.py @@ -1246,15 +1246,6 @@ def _get( def _list( self, *, config: Optional[types.ListTuningJobsConfigOrDict] = None ) -> types.ListTuningJobsResponse: - """Lists `TuningJob` objects. - - Args: - config: The configuration for the list request. - - Returns: - A list of `TuningJob` objects. - """ - parameter_model = types._ListTuningJobsParameters( config=config, ) @@ -1522,9 +1513,26 @@ def _tune_mldev( def list( self, *, config: Optional[types.ListTuningJobsConfigOrDict] = None ) -> Pager[types.TuningJob]: + """Lists `TuningJob` objects. + + Args: + config: The configuration for the list request. + + Returns: + A Pager object that contains one page of tuning jobs. When iterating over + the pager, it automatically fetches the next page if there are more. + + Usage: + + .. code-block:: python + for tuning_job in client.tunings.list(): + print(tuning_job.name) + """ + + list_request = self._list return Pager( 'tuning_jobs', - self._list, + list_request, self._list(config=config), config, ) @@ -1713,15 +1721,6 @@ async def _get( async def _list( self, *, config: Optional[types.ListTuningJobsConfigOrDict] = None ) -> types.ListTuningJobsResponse: - """Lists `TuningJob` objects. - - Args: - config: The configuration for the list request. - - Returns: - A list of `TuningJob` objects. - """ - parameter_model = types._ListTuningJobsParameters( config=config, ) @@ -1991,9 +1990,26 @@ async def _tune_mldev( async def list( self, *, config: Optional[types.ListTuningJobsConfigOrDict] = None ) -> AsyncPager[types.TuningJob]: + """Lists `TuningJob` objects asynchronously. + + Args: + config: The configuration for the list request. + + Returns: + A Pager object that contains one page of tuning jobs. When iterating over + the pager, it automatically fetches the next page if there are more. + + Usage: + + .. code-block:: python + async for tuning_job in await client.aio.tunings.list(): + print(tuning_job.name) + """ + + list_request = self._list return AsyncPager( 'tuning_jobs', - self._list, + list_request, await self._list(config=config), config, ) diff --git a/pyproject.toml b/pyproject.toml index 718389d2f..3d90a056c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,15 +47,19 @@ Homepage = "https://github.com/googleapis/python-genai" [tool.setuptools.package-data] "google.genai" = ["py.typed"] +[tool.pytest.ini_options] +asyncio_mode = "auto" +asyncio_default_fixture_loop_scope = "function" + [tool.mypy] exclude = ["tests/", "_test_api_client\\.py"] plugins = ["pydantic.mypy"] # we are ignoring 'unused-ignore' because we run mypy on Python 3.9 - 3.13 and # some errors in _automatic_function_calling_util.py only apply in 3.10+ # 'import-not-found' and 'import-untyped' are environment specific -disable_error_code = ["import-not-found", "import-untyped", "unused-ignore"] +disable_error_code = [ + "import-not-found", + "import-untyped", + "unused-ignore", +] strict = true - -[tool.pytest.ini_options] -asyncio_mode = "auto" -asyncio_default_fixture_loop_scope = "function"