Skip to main content

Port of https://github.com/eBay/FeedSDK-Python and https://github.com/eBay/ebay-oauth-python-client to python3

Project description

Feed SDK

Python SDK for downloading and filtering item feed files including oauth authentication.

Forked and merged from https://github.com/eBay/FeedSDK-Python and https://github.com/eBay/ebay-oauth-python-client and ported to python3

Nothing serious changed, made it barely working.

Code is not improved yet and would need some maintenance.

Automatic Tests not working due to the nature the tests were original programmed (you need to provide actual token etc.)

Available as PyPI package under https://pypi.org/project/ebay-feedsdk/

Example code to retrieve oauth token and download file (you need working ebay-config.yaml)

import logging

from errors.custom_exceptions import DownloadError
from feed import Feed
from filter.feed_filter import GetFeedResponse
from oauthclient.credentialutil import Credentialutil
from oauthclient.model.model import Environment, OauthToken, EnvType
from oauthclient.oauth2api import Oauth2api


class EbayDownloadExample:
    app_scopes = ["https://api.ebay.com/oauth/api_scope", "https://api.ebay.com/oauth/api_scope/buy.item.feed"]
    config_file = 'ebay-config.yaml'

    def __init__(self, market_place: str, env: EnvType, feed_scope, download_location: str):
        self.env = env
        self.feed_scope = feed_scope
        self.market_place = market_place
        self.download_location = download_location

    def download(self, category_id: str):
        logging.info(
            f'Downloading category {category_id} for {self.market_place} with scope {self.feed_scope}'
            f'to {self.download_location}')

        token = self.get_token()

        feed_obj = Feed(feed_type='item', feed_scope=self.feed_scope, category_id=category_id,
                        marketplace_id=self.market_place,
                        token=token.access_token, environment=self.env.name, download_location=self.download_location)

        feed_response: GetFeedResponse = feed_obj.get()

        if feed_response.status_code != 0:
            raise DownloadError(f'Download failed see: {feed_response.message}')

        logging.info(f'File was downloaded under {feed_response.file_path}')

        return feed_response.file_path

    def get_token(self) -> OauthToken:
        Credentialutil.load(self.config_file)
        oauth2api = Oauth2api()

        token = oauth2api.get_application_token(self.env, self.app_scopes)
        if not token.access_token:
            raise DownloadError(f'Got no token, check: {token.error}')

        return token


if __name__ == "__main__":
    market_place = 'EBAY_DE'
    feed_scope = 'ALL_ACTIVE'
    download_location = '/tmp/feed'
    category_id = '2984'  # string ..
    ebay_download = EbayDownloadExample(market_place, Environment.PRODUCTION, feed_scope, download_location)
    file_path = ebay_download.download(category_id)

See also for details:

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

ebay-feedsdk-0.2.1.tar.gz (29.5 kB view hashes)

Uploaded Source

Built Distribution

ebay_feedsdk-0.2.1-py3-none-any.whl (53.8 kB view hashes)

Uploaded Python 3

Supported by

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