Skip to content
Merged
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion src/scrapebadger/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ async def main():
ZestimateHistoryPoint as ZillowZestimateHistoryPoint,
)

__version__ = "0.82.1"
__version__ = "0.83.0"

__all__ = [
# TikTok core models
Expand Down
2 changes: 1 addition & 1 deletion src/scrapebadger/_internal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"


Expand Down
56 changes: 49 additions & 7 deletions src/scrapebadger/wallapop/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -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.

Expand Down Expand Up @@ -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,
Expand All @@ -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".
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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".

Expand All @@ -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)

Expand All @@ -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).

Expand All @@ -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.
Expand All @@ -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)

Expand Down
20 changes: 20 additions & 0 deletions tests/test_wallapop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading