← Projects

marktplaats.py

An open-source Python library for searching Marktplaats, the biggest second-hand marketplace in the Netherlands. Around 1,800 downloads a month on PyPI.

Marktplaats has no public API for searching listings. If you want to watch for a cheap bike or track prices, you end up scraping pages by hand. I wanted that to be one pip install away, so in 2023 I built marktplaats.py.

from marktplaats import SearchQuery, category_from_name

search = SearchQuery(
    query="gazelle",
    zip_code="1016LV",
    distance_km=100,
    price_to=100,
    category=category_from_name("Fietsen en Brommers"),
)

for listing in search.get_listings():
    print(listing.title, listing.price_as_string(lang="nl"), listing.link)

How it works

The library talks to the same JSON search endpoint the Marktplaats website uses, and turns the responses into typed Python objects: listings, prices, locations, sellers and images. On top of search it can look up a seller and all their listings, and filter on every Marktplaats category.

Keeping up with a site that keeps changing

The hard part of a library like this isn’t the first version. It’s staying working when the site changes underneath it. So the repository looks after itself:

  • Live tests run against the real Marktplaats every day, so a breaking change shows up before users report it.
  • A weekly job scrapes the full category tree and opens a pull request when it changes.
  • Releases are tagged and published to PyPI automatically, and dependencies update themselves.

Growing past me

It started as a small side project and became something other people build on. It now has 75 stars, 19 forks, around 1,800 downloads a month and 21 releases. Eight people have contributed code, and one of them became a co-maintainer who now writes about as many commits as I do.