From 8f3ce437dbdb459c16f88f44b1aad874cb533602 Mon Sep 17 00:00:00 2001 From: kasparasizi1 <132673909+kasparasizi1@users.noreply.github.com> Date: Thu, 26 Nov 2026 11:12:05 +0200 Subject: [PATCH] Wallapop: search and filters take subcategory_ids (0.83.0) wallapop.search(), list_filters() and list_filter_options() take subcategory_ids: the nested ids of list_categories(), as a list or a comma-separated string, sent to the API comma-joined. Keyword-only with a None default, so existing calls are unchanged. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 7 ++++ pyproject.toml | 2 +- src/scrapebadger/__init__.py | 2 +- src/scrapebadger/_internal/client.py | 2 +- src/scrapebadger/wallapop/client.py | 56 ++++++++++++++++++++++++---- tests/test_wallapop.py | 20 ++++++++++ uv.lock | 2 +- 7 files changed, 80 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ea1437..d7d0e39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## [0.83.0] - 2026-11-26 + +### Added +- `wallapop.search(..., subcategory_ids=...)` narrows a search to Wallapop subcategories: the `subcategories` ids of `wallapop.list_categories()`, at any depth (e.g. `24200` Technology & electronics → `24201` Phones → `9447` Smartphones). Pass a list (`[9447, 10310]`) or a comma-separated string (`"9447,10310"`); several ids match any of them. Works with or without `category_id`, and on its own is enough to search (no `query` needed). A `next_page` cursor keeps the subcategories. +- `wallapop.list_filters()` and `wallapop.list_filter_options()` take the same `subcategory_ids`, so filters and option lists match the subcategory (e.g. `list_filter_options("brand", subcategory_ids=[9447])` returns phone brands only). +- New keyword-only arguments with a `None` default, so existing calls are unchanged. + ## [0.82.1] - 2026-11-25 ### Changed diff --git a/pyproject.toml b/pyproject.toml index 9fb201a..294c3cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "scrapebadger" -version = "0.82.1" +version = "0.83.0" description = "Official Python SDK for ScrapeBadger - Async web scraping APIs for Twitter and more" readme = "README.md" license = { text = "MIT" } diff --git a/src/scrapebadger/__init__.py b/src/scrapebadger/__init__.py index e96b1d2..d32a688 100644 --- a/src/scrapebadger/__init__.py +++ b/src/scrapebadger/__init__.py @@ -1356,7 +1356,7 @@ async def main(): ZestimateHistoryPoint as ZillowZestimateHistoryPoint, ) -__version__ = "0.82.1" +__version__ = "0.83.0" __all__ = [ # TikTok core models diff --git a/src/scrapebadger/_internal/client.py b/src/scrapebadger/_internal/client.py index e228618..bc8512a 100644 --- a/src/scrapebadger/_internal/client.py +++ b/src/scrapebadger/_internal/client.py @@ -56,7 +56,7 @@ T = TypeVar("T") # User agent for SDK requests -SDK_VERSION = "0.82.1" +SDK_VERSION = "0.83.0" USER_AGENT = f"scrapebadger-python/{SDK_VERSION}" diff --git a/src/scrapebadger/wallapop/client.py b/src/scrapebadger/wallapop/client.py index 038f505..3860280 100644 --- a/src/scrapebadger/wallapop/client.py +++ b/src/scrapebadger/wallapop/client.py @@ -26,6 +26,8 @@ ) if TYPE_CHECKING: + from collections.abc import Sequence + from scrapebadger._internal.client import BaseClient OrderBy = Literal["most_relevance", "newest", "closest", "price_low_to_high", "price_high_to_low"] @@ -38,6 +40,13 @@ def _set(params: dict[str, Any]) -> dict[str, Any]: return {k: v for k, v in params.items() if v is not None and v is not False} +def _ids(ids: Sequence[int | str] | str | None) -> str | None: + """``subcategory_ids`` as the API takes it: comma-separated, or None.""" + if ids is None or isinstance(ids, str): + return ids + return ",".join(str(i) for i in ids) or None + + class WallapopClient: """Client for all Wallapop API operations. @@ -91,6 +100,7 @@ async def search( longitude: float | None = None, distance_km: int | None = None, category_id: int | None = None, + subcategory_ids: Sequence[int | str] | str | None = None, min_price: float | None = None, max_price: float | None = None, condition: str | None = None, @@ -113,8 +123,9 @@ async def search( ) -> SearchResponse: """Search Wallapop listings (40 per page). - Provide a ``query``, a ``category_id``, or both — or a ``next_page`` - cursor, in which case the other filters are ignored. + Provide a ``query``, a ``category_id``, ``subcategory_ids``, or any + combination — or a ``next_page`` cursor, in which case the other + filters are ignored (the cursor already carries them). Args: query: Search text, e.g. "iphone 14". @@ -123,6 +134,10 @@ async def search( longitude: Search centre longitude. distance_km: Radius around the centre, 1-500 km. category_id: Category id (see `list_categories`). + subcategory_ids: Subcategory ids from `list_categories` (the + ``subcategories`` of a category, at any depth), as a list such + as ``[9447, 10310]`` or a comma-separated string. Works with or + without ``category_id``. min_price: Minimum price. max_price: Maximum price. condition: Comma-separated: un_opened, in_box, new, as_good_as_new, @@ -150,8 +165,8 @@ async def search( Raises: AuthenticationError: If the API key is invalid. - ValidationError: If neither query, category_id nor next_page is - given, or a parameter is out of range. + ValidationError: If none of query, category_id, subcategory_ids or + next_page is given, or a parameter is out of range. Example: ```python @@ -164,6 +179,11 @@ async def search( order_by="price_low_to_high", ) print(cars.total_results) + + # Smartphones (9447) under Technology & electronics (24200) + phones = await client.wallapop.search( + "iphone", category_id=24200, subcategory_ids=[9447] + ) ``` """ params = _set( @@ -174,6 +194,7 @@ async def search( "longitude": longitude, "distance_km": distance_km, "category_id": category_id, + "subcategory_ids": _ids(subcategory_ids), "min_price": min_price, "max_price": max_price, "condition": condition, @@ -347,7 +368,8 @@ async def list_categories(self, *, market: str = "es") -> CategoriesResponse: Defaults to "es". Returns: - Category tree; ids are usable as the search ``category_id``. + Category tree; top-level ids are usable as the search + ``category_id``, nested ``subcategories`` ids as ``subcategory_ids``. Example: ```python @@ -365,11 +387,14 @@ async def list_filters( category_id: int | None = None, query: str | None = None, market: str = "es", + subcategory_ids: Sequence[int | str] | str | None = None, ) -> FiltersResponse: """Get the search filters Wallapop offers for a category/query. Args: category_id: Category the filters apply to. + subcategory_ids: Subcategory ids the filters apply to (a list or + a comma-separated string). query: Search text the filters apply to. market: Market code (es, it, pt). Defaults to "es". @@ -387,7 +412,14 @@ async def list_filters( """ response = await self._client.get( "/v1/wallapop/filters", - params=_set({"category_id": category_id, "query": query, "market": market}), + params=_set( + { + "category_id": category_id, + "subcategory_ids": _ids(subcategory_ids), + "query": query, + "market": market, + } + ), ) return FiltersResponse.model_validate(response) @@ -398,6 +430,7 @@ async def list_filter_options( category_id: int | None = None, query: str | None = None, market: str = "es", + subcategory_ids: Sequence[int | str] | str | None = None, ) -> FilterOptionsResponse: """Get a filter's long option list (e.g. brands, models). @@ -407,6 +440,8 @@ async def list_filter_options( category_id: Category the options apply to. query: Search text the options apply to. market: Market code (es, it, pt). Defaults to "es". + subcategory_ids: Subcategory ids the options apply to (a list or + a comma-separated string), e.g. ``[9447]`` for phone brands. Returns: The filter's options. @@ -424,7 +459,14 @@ async def list_filter_options( """ response = await self._client.get( f"/v1/wallapop/filters/{filter_id}/options", - params=_set({"category_id": category_id, "query": query, "market": market}), + params=_set( + { + "category_id": category_id, + "subcategory_ids": _ids(subcategory_ids), + "query": query, + "market": market, + } + ), ) return FilterOptionsResponse.model_validate(response) diff --git a/tests/test_wallapop.py b/tests/test_wallapop.py index a369090..e791d94 100644 --- a/tests/test_wallapop.py +++ b/tests/test_wallapop.py @@ -682,6 +682,20 @@ async def test_search_false_booleans_not_sent( _, params = _call(mock_base_client) assert params == {"market": "es", "category_id": 100} + async def test_search_subcategory_ids( + self, wallapop_client: WallapopClient, mock_base_client: MagicMock + ) -> None: + mock_base_client.get.return_value = SEARCH_RESPONSE + await wallapop_client.search(category_id=24200, subcategory_ids=[9447, 10310]) + _, params = _call(mock_base_client) + assert params == {"market": "es", "category_id": 24200, "subcategory_ids": "9447,10310"} + await wallapop_client.search(subcategory_ids="9447") + _, params = _call(mock_base_client) + assert params == {"market": "es", "subcategory_ids": "9447"} + await wallapop_client.search("iphone", subcategory_ids=[]) + _, params = _call(mock_base_client) + assert params == {"query": "iphone", "market": "es"} + async def test_search_next_page( self, wallapop_client: WallapopClient, mock_base_client: MagicMock ) -> None: @@ -760,6 +774,9 @@ async def test_list_filters( await wallapop_client.list_filters(category_id=24200, query="iphone") _, params = _call(mock_base_client) assert params == {"category_id": 24200, "query": "iphone", "market": "es"} + await wallapop_client.list_filters(category_id=24200, subcategory_ids=(9447,)) + _, params = _call(mock_base_client) + assert params == {"category_id": 24200, "subcategory_ids": "9447", "market": "es"} async def test_list_filter_options( self, wallapop_client: WallapopClient, mock_base_client: MagicMock @@ -771,6 +788,9 @@ async def test_list_filter_options( "/v1/wallapop/filters/brand/options", {"query": "iphone", "market": "es"}, ) + await wallapop_client.list_filter_options("brand", subcategory_ids=[9447, "10310"]) + _, params = _call(mock_base_client) + assert params == {"subcategory_ids": "9447,10310", "market": "es"} async def test_list_markets( self, wallapop_client: WallapopClient, mock_base_client: MagicMock diff --git a/uv.lock b/uv.lock index 84946d6..a53afc8 100644 --- a/uv.lock +++ b/uv.lock @@ -930,7 +930,7 @@ wheels = [ [[package]] name = "scrapebadger" -version = "0.82.1" +version = "0.83.0" source = { editable = "." } dependencies = [ { name = "httpx" },