A Python tool to search Wallapop items
Project description
WallaPy 🐍
WallaPy is a Python library designed to interact with Wallapop's (unofficial) API to search for items based on various criteria. It allows automating product searches, applying filters, and retrieving detailed information about listings. The core of the library is asynchronous for efficiency, but a simple synchronous wrapper is provided for ease of use in synchronous code.
Developed by duccioo ✨
Features 🚀
- Advanced Search: Search for items on Wallapop by product name and additional keywords.
- Multiple Filters:
- Filter by price range (minimum and maximum). 💰
- Filter by publication period (
today,lastWeek,lastMonth) 📅 - Exclude listings containing specific keywords (supports fuzzy matching). 🚫
- Sorting: Sort results by newest (
newest), price ascending (price_low_to_high), or price descending (price_high_to_low). 📊 - Pagination Handling: Automatically retrieves multiple pages of results up to a specified limit. 📄
- Robustness: Handles HTTP errors, implements retry mechanisms, and rotates User-Agents for API requests. 💪
- Flexible Matching: Uses fuzzy matching (via
fuzzywuzzy) to identify relevant keywords in titles and descriptions, even with slight variations. 🔍 - Data Processing: Cleans and formats data retrieved from the API into a structured format. 🧹
- Deep Search: Optionally fetches detailed item information (like user details, characteristics, views) concurrently for matched items. 🕵️
- Error Handling: Uses custom exceptions for better handling of library-specific errors.
Installation 🛠️
Using pip (Recommended):
The easiest way to install WallaPy is directly from PyPI:
pip install wallapy
From Source (for development):
If you want to contribute or install the latest development version, you can install from source. Using a virtual environment is recommended.
- Clone the repository:
git clone https://github.com/duccioo/WallaPy.git cd WallaPy
- Create and activate a virtual environment (recommended):
python -m venv venv # On macOS/Linux: source venv/bin/activate # On Windows: # venv\Scripts\activate
- Install the library:
The
pyproject.tomlfile defines the dependencies. Use pip to install the library and its dependencies:pip install .
Or, to install in editable mode:pip install -e .
(Note:python-Levenshteinis included in the dependencies and improvesfuzzywuzzyperformance)
Usage Example 💡
WallaPy provides a simple synchronous function check_wallapop for basic usage. This function handles the asynchronous operations internally.
from wallapy import check_wallapop # Import the synchronous wrapper
# Execute the search
results = check_wallapop(
product_name="iPhone 15",
keywords=["iphone", "15", "pro", "128gb", "unlocked"],
min_price=500,
max_price=800, # Set the maximum price
excluded_keywords=["broken", "repair", "cracked screen", "rotto", "riparare"],
max_total_items=50, # Limit the number of listings to retrieve
order_by="price_low_to_high", # Sort by price
)
# Print the found results
if results:
print(f"\nFound {len(results)} matching listings:")
for ad in results:
print("-" * 20)
print(f"Title: {ad['title']}")
print(f"Price: {ad['price']} {ad.get('currency', '')}")
print(f"Location: {ad.get('location', 'N/A')}")
print(f"Link: {ad['link']}")
else:
print("\nNo listings found matching the specified criteria.")
Note: For integration into existing asyncio applications, it's recommended to instantiate WallaPyClient directly and use its async check_wallapop(...) method to avoid potential issues with asyncio.run() within a running event loop. See the example in src/test/test.py for asynchronous usage.
Project Structure (src/wallapy) 📁
pyproject.toml: (In the root) Main configuration file for the package build and dependencies.__init__.py: Makes thewallapydirectory a Python package and exposes the public interface (theWallaPyClientclass, the synchronouscheck_wallapopwrapper, and exceptions).check.py: Contains theWallaPyClientclass with the main async logic (check_wallapop) for orchestrating the search and processing (_process_wallapop_item,_get_details).fetch_api.py: Handles URL construction (setup_url), synchronous API data retrieval (fetch_wallapop_items), and asynchronous user info fetching (fetch_user_info_async).request_handler.py: Providessafe_request(sync) andsafe_request_async(async) functions for robust HTTP requests with retries and error handling.utils.py: Contains utility functions for text cleaning (clean_text), checking excluded terms (contains_excluded_terms), link generation (make_link), price validation (validate_prices), etc.config.py: Stores configuration constants like the base API URL, fuzzy matching thresholds, and default HTTP headers.exceptions.py: Defines custom exceptions used by the library (e.g.,WallaPyRequestError).
TODO
- Aggiungere altri esempi di utilizzo con il client
- Inserire lo scraping via web in caso di errore API
- Migliorare il matching delle parole
- Prendere N elementi che rispettano le richieste no matter what invece di fare il fetching di N elementi e poi controllare se rispettano o meno le richieste.
License 📜
This project is released under the Apache License 2.0. See the LICENSE file for more details.
Disclaimer ⚠️
This tool uses unofficial Wallapop APIs. Use it at your own risk. Changes to the API by Wallapop may break the tool without notice. Respect Wallapop's terms of service. This tool is intended for personal, non-commercial use.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wallapy-0.6.6.tar.gz.
File metadata
- Download URL: wallapy-0.6.6.tar.gz
- Upload date:
- Size: 23.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3efecbc783c67a7426f8c0ff7558ac68d58c02ec57c4761954370b9524fe9cf3
|
|
| MD5 |
f948532085b700db1fe215d0785c8576
|
|
| BLAKE2b-256 |
6590d7ff386baf2b72b9236c8f2e000fe2aeb5e260bd5e85d65b58af9886e373
|
File details
Details for the file wallapy-0.6.6-py3-none-any.whl.
File metadata
- Download URL: wallapy-0.6.6-py3-none-any.whl
- Upload date:
- Size: 25.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0273bbb27a859131e989f42f7b0522a6fb290f5fec85bf24f5904ebc803a0c4
|
|
| MD5 |
78472e301c4e87c3f1e1b8c45d8d4649
|
|
| BLAKE2b-256 |
bb20945874c70a16028aaea5832c96886f918c824b33f743b3b4b66f2e4f321e
|