Skip to content

Commit 18fdc23

Browse files
authored
Merge pull request #2476 from feliperuhland/add-search-images-limit
Add limit parameter to image search endpoint
2 parents 8813c3d + 7d31664 commit 18fdc23

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

docker/api/image.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,13 +509,14 @@ def remove_image(self, image, force=False, noprune=False):
509509
res = self._delete(self._url("/images/{0}", image), params=params)
510510
return self._result(res, True)
511511

512-
def search(self, term):
512+
def search(self, term, limit=None):
513513
"""
514514
Search for images on Docker Hub. Similar to the ``docker search``
515515
command.
516516
517517
Args:
518518
term (str): A term to search for.
519+
limit (int): The maximum number of results to return.
519520
520521
Returns:
521522
(list of dicts): The response of the search.
@@ -524,8 +525,12 @@ def search(self, term):
524525
:py:class:`docker.errors.APIError`
525526
If the server returns an error.
526527
"""
528+
params = {'term': term}
529+
if limit is not None:
530+
params['limit'] = limit
531+
527532
return self._result(
528-
self._get(self._url("/images/search"), params={'term': term}),
533+
self._get(self._url("/images/search"), params=params),
529534
True
530535
)
531536

tests/unit/models_images_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ def test_search(self):
112112
client.images.search('test')
113113
client.api.search.assert_called_with('test')
114114

115+
def test_search_limit(self):
116+
client = make_fake_client()
117+
client.images.search('test', limit=5)
118+
client.api.search.assert_called_with('test', limit=5)
119+
115120

116121
class ImageTest(unittest.TestCase):
117122
def test_short_id(self):

0 commit comments

Comments
 (0)