A Python 3 pip package that wraps eBay’s REST APIs.
Use the package manager pip to install ebay_rest.
pip install ebay_rest # Use pip3 if your computer also has Python 2 installed.
If you are one of the few people who want ebay_rest to get user tokens, do the following.
Install Chrome.
pip install selenium # Use pip3 if your computer also has Python 2 installed.
Install Webdriver, aka Chromedriver, for your version of Chrome .
Here is a method for installing Webdriver/Chromedriver on macOS and tweaking security to permit it.
Install HomeBrew
brew install chromedriver
cd /usr/local/Caskroom/chromedriver
cd to the subdirectory that matches your Chrome version, e.g., 91.0.4472.101
xattr -d com.apple.quarantine chromedriver
Follow the instructions here.
from ebay_rest import API, DateTime, Error, Reference
print(f"eBay's official date and time is {DateTime.to_string(DateTime.now())}.\n")
print("All valid eBay global id values, also known as site ids.")
print(Reference.get_global_id_values(), '\n')
try:
api = API(application='production_1', user='production_1', header='US')
except Error as error:
print(f'Error {error.number} is {error.reason} {error.detail}.\n')
else:
try:
print("The five least expensive iPhone things now for sale on-eBay:")
for record in api.buy_browse_search(q='iPhone', sort='price', limit=5):
if 'record' not in record:
pass # TODO Refer to non-records, they contain optimization information.
else:
item = record['record']
print(f"item id: {item['item_id']} {item['item_web_url']}")
except Error as error:
print(f'Error {error.number} is {error.reason} {error.detail}.\n')
else:
pass
print("\nClass documentation:")
print(help(API)) # Over a hundred methods are available!
print(help(DateTime))
print(help(Error))
print(help(Reference))
Question: How are API results organized?
Answer:
- Elemental information is stored in dates, integers, strings and other basic built-in types.
- Dictionaries contain related elements.
- Lists contain information organized repetitively; expect zero or more contents.
- Dicts and Lists may be nested.
- eBay classifies data as optional or mandatory. Optional elements, dicts or lists are omitted. Manditories have a None value.
Q: How are paged calls/results handled?
A: A simple generator is implemented.
- To be clear, "Paging" is eBay's term for repeating a call while advancing a record offset to get all records.
- eBay documentation has the word "Page" in the return type of paging calls.
- Do NOT supply a record "offset" parameter when making a paging call.
- The "limit" parameter is repurposed to control how many records from the entire set you want.
- To get all possible records, don't supply a limit.
- eBay imposes a hard limit on some calls, typically 10,000 records. Use filters to help keep below the limit. Use try-except to handle going over.
- Avoid exhausting memory by making the call within a "for" loop.
Q: Why is eBay giving an "Internal Error" or "Internal Server Error"?
A: Rapidly repeating an API call with the same parameter values can trigger this.
Q: Parallelism, is it safe to do treading or multiprocessing?
A: Yes, for treading. Multiprocessing is unknown, help wanted.
Q: How to optimize API calls?
A: Prioritized, do the first things first.
- Cache results to avoid repeating calls with identical parameter values.
- Some calls have filtering options; omit unneeded data.
- When the call returns a list, make the call in a "for" loop.
- Use threading to make calls in parallel but don't exhaust RAM.
- Use multiprocessing. -- Multiprocessing support is a goal. -- A safe workaround is to concurrently run copies of your program and divide the work among each.
- Reuse the API object.
- Switch to a faster internet connection.
- Switch to computer with faster cores.
- Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
- Follow Uncle Bob's SOLID principles; see a text description & video tutorial.
- Note the error number guide documented in the Error class definition.
- Please make sure to update unit tests as appropriate.
- MIT licence.
- "Python" is a trademark of the Python Software Foundation.
- "eBay" is a trademark of eBay Inc.
- Official endorsement by eBay Inc is not claimed or implied.
- The origin of the oath code is eBay Oauth Python Client.