eBay SDK for Python
The eBay SDK for Python provides a comprehensive interface for interacting with various eBay APIs, including Trading, Finding, Shopping, and Merchandising. It simplifies API calls and response parsing by converting XML to Python dictionaries. The current version is 2.2.0, with the last release in April 2020, indicating a maintenance-only cadence.
Common errors
-
No module named 'ebaysdk'
cause The `ebaysdk` package has not been installed in your Python environment.fixRun `pip install ebaysdk` to install the library. -
FileNotFoundError: [Errno 2] No such file or directory: 'ebay.yaml'
cause The `ebaysdk` library attempts to load an `ebay.yaml` configuration file by default, but it could not be found at the expected path.fixEither create an `ebay.yaml` file with your credentials and settings in your working directory, or pass credentials directly to the `Connection` constructor (e.g., `appid='YOUR_APP_ID', config_file=None`). -
ebaysdk.exception.ConnectionError: (10007) Invalid request: The request is missing required parameters or is improperly formatted.
cause This generic error indicates an issue with your API request, often due to missing or incorrect credentials (App ID, Dev ID, Cert ID), an invalid API endpoint, or malformed request parameters.fixDouble-check your `appid`, `devid`, and `certid` for the correct API. Verify the `domain` parameter (e.g., `svcs.ebay.com` for production, `svcs.sandbox.ebay.com` for sandbox) and the structure of your API call arguments.
Warnings
- breaking Versions prior to v1.0.0 (specifically v0.1.11 and older) used PyCurl as the HTTP backend. All versions from v1.0.0 onwards switched to the 'requests' library, requiring code changes for direct HTTP client interactions.
- breaking As of v2.2.0, HTTPS is forced by default for Finding, Shopping, and Trading API calls. Explicitly setting HTTP or not having proper SSL certificate chains might lead to connection errors if you relied on insecure connections.
- gotcha The library relies heavily on a `ebay.yaml` configuration file for API credentials and settings. Incorrect path, missing file, or malformed YAML can lead to authentication failures or `FileNotFoundError`.
- gotcha The library has not been updated since April 2020. Newer eBay API features, changes, or deprecations introduced after this date might not be supported or could lead to unexpected behavior/errors.
Install
-
pip install ebaysdk
Imports
- Connection (Finding API)
from ebaysdk.finding import Connection as FindingConnection
- Connection (Trading API)
from ebaysdk.trading import Connection as TradingConnection
- Connection (Shopping API)
from ebaysdk.shopping import Connection as ShoppingConnection
- Connection (Merchandising API)
from ebaysdk.merchandising import Connection as MerchandisingConnection
- ConnectionError
from ebaysdk.exception import ConnectionError
Quickstart
import os
from ebaysdk.finding import Connection as FindingConnection
from ebaysdk.exception import ConnectionError
try:
api = FindingConnection(
domain='svcs.ebay.com', # Use 'svcs.sandbox.ebay.com' for sandbox environment
config_file=None, # Explicitly disable config file for this example
appid=os.environ.get('EBAY_APPID', 'YOUR_EBAY_APPID') # Replace 'YOUR_EBAY_APPID' with your actual App ID or set EBAY_APPID env var
)
# Make a call to find items by keywords
response = api.execute('findItemsByKeywords', {'keywords': 'star wars lego'})
if response.reply and response.reply.searchResult and response.reply.searchResult.item:
print(f"Found {response.reply.searchResult['@count']} items:")
for item in response.reply.searchResult.item[:3]: # print first 3 items
print(f"- {item.title} (Current Price: {item.sellingStatus.currentPrice.value} {item.sellingStatus.currentPrice['currencyId']})")
else:
print("No items found or response malformed.")
except ConnectionError as e:
print(f"API Connection Error: {e.response.dict()}")
except Exception as e:
print(f"An unexpected error occurred: {e}")