Skip to main content

mercari api-like wrapper

Project description

Mercari Wrapper

A simple api wrapper around the Mercari jp site.

This package does not use scraping of the underlying HTML, it simulates API requests by generating tokens according to how Mercari.JP expects it. This should result in quicker response times, less breaking changes (due to layout swaps), and overall better experience.

Searching

Simple usage can be something like

import mercari

for item in mercari.search("東方 ふもふも"):
    print("{}, {}".format(item.productName, item.productURL))

The search call will take a long time because it goes through all the pages to find every item. It does not return parts where you paginate yourself.

the item object contains the following properties:

  • id
  • productURL
  • imageURL
  • productName
  • price
  • status
  • soldOut
  • created
  • updated
  • auction (can be None) with following properties
    • bid_deadline (can be different types depending on search vs item info)
    • total_bid
    • highest_bid

If you want to do more specific searching, you can use something like the following

from mercari import search, MercariSearchStatus, MercariSort, MercariOrder

for item in search(
        "",
        sort=MercariSort.SORT_PRICE,
        order=MercariOrder.ORDER_DESC,
        status=MercariSearchStatus.SOLD_OUT
    ):
    print("{}, {}".format(item.productName, item.productURL))

The defaults are currently:

  • sort=MercariSort.SORT_CREATED_TIME
  • order=MercariOrder.ORDER_DESC
  • status=MercariSearchStatus.ON_SALE

Which will sort by most recent to oldest, and only show on sale item.

MercariSort

  • STATUS_DEFAULT
  • STATUS_ON_SALE
  • STATUS_SOLD_OUT

MercariOrder

  • SORT_DEFAULT
  • SORT_CREATED_TIME
  • SORT_NUM_LIKES
  • SORT_SCORE
  • SORT_PRICE

MercariSearchStatus

  • ORDER_DESC
  • ORDER_ASC

You can also pass excluded_keywords="something to exclude" if you want to remove certain pieces from your search

Item Info

from mercari import getItemInfo

itemId = 'm48957867611' # get it using a search or some other way
# default country code is US, so don't need to pass if you're fine with US
item = getItemInfo(itemId, country_code="US")
print(item.id, item.price, item.name)

The item returned is properly typed so you can explore it using intellisense in your IDE. I don't do any safe checks or conversions on parameters but some gotchas:

  • status is just a string which can be on_sale
  • price is the JPY price, but converted_price contains the currency according to the country_code you pass in (USD by default)
  • any timestamp field (created, updated) come back as int with the unix timestamp in seconds
  • pretty much 90% of fields, I'm unsure if they're useful (wtf is a pager id? additional_service??)
  • some properties I didn't get samples that contained property so they're blank
    • comments - empty array always
    • application_attributes - empty dict always
    • hash_tags - empty array always
    • additional_services - empty array always

Another big gotcha is that I didn't bother adding great error handling, so if an item is expired, it'll throw a request error with like 403 if it used to be an item, or 404 is the itemId doesn't exist. If people are still using this, I'll add that in but I'm not consuming this lib myself any more.

Development

Clone this repo, install the dependencies in requirement.txt and off you go.

Deploying / Publishing

  • python setup.py sdist

  • twine upload dist/mercari-<version>.tar.gz

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

mercari-2.2.1.tar.gz (11.0 kB view details)

Uploaded Source

File details

Details for the file mercari-2.2.1.tar.gz.

File metadata

  • Download URL: mercari-2.2.1.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.10

File hashes

Hashes for mercari-2.2.1.tar.gz
Algorithm Hash digest
SHA256 79963bab859b9dca77c52101e4e57df80b2b2942a323db089f6661a9ab16320a
MD5 a121a817b5f4621ce6140021690bf6d8
BLAKE2b-256 4d25503abb5f53d8ca18aca6eb5c6c009812088c90f57c621369d9920161ce7d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page