An interface to the Ecwid shopping platform API
Project description
pyecwid
Python wrapper for Ecwid REST API
Requirements
Installation
$ python -m pip install pyecwid
ChangeLog
BREAKING: Major changes (when 0.1.x released)
- Broke up the different endpoints (Customers, Orders, Products, etc) into different classes that accept the EcwidAPI (or EcwidAPIMock) object.
- Added Mixins that can be used to quickly implement new Endpoints without duplicating code.
- Added an Ecwid class that contains properties with each endpoint initialised.
- Some methods have changed names.
Todo
- Reimplement product_variations and other mixins for subobjects of items.
Implemented Features
- Standard possible commands for endpoints:
-
add({item}) - add item (dict)
-
delete(id) - remove item
-
get_by_id(id) - get item details (returns a single {item})
-
update(id, {values}) - update item with values (dict)
-
Getting multiple items: Will deal with pagination and return a list of "items" node.
Optional: pass "collate_items=False" to any of these commands and full results will be returned. Note - pagination will not be handled automatically. Useful to find total counts etc.- get() - get all items
- get_by_keyword('keyword') - search for items by keyword
- get_by_params({params}) - search for items by paramaters (dict)
-
Endpoint | Status | Standard commands | Extra commands |
---|---|---|---|
Coupons | alpha - currently unable to test | add, delete, get, get_by_id, get_by_params, update | |
Customers | alpha - currently unable to test | add, delete, get, get_by_id, get_by_keyword, update | get_by_email, get_by_name |
Orders | alpha - currently unable to test | add, delete, get, get_by_id, get_by_params, update | |
Products | working | add, delete, get, get_by_id, get_by_keyword, get_by_params, update | |
ProductTypes (classes) | working | add, delete, get, get_by_id, update |
Simple Initialisation
from pyecwid import Ecwid
ecwid = Ecwid(api_token, store_id)
EcwidAPI Arguments
Argument | Required | Description | Default Value |
---|---|---|---|
api_token | Yes | The secret_ or public_ token for your store. | |
store_id | Yes | The ID of your store. | |
skip_test | No | True/False. Skips test call to API during initiaization (used in tests) | False |
base_url | No | Replace the hard coded URL Note: format includes {0} for store_id |
'https://app.ecwid.com/api/v3/{0}/' |
Sample: Search products and pprint
from pprint import pprint
from pyecwid import Ecwid
ecwid = Ecwid('public_ASDF', '1234567')
# Search by Keyword
items = ecwid.products.get_by_keyword('sunglasses')
pprint(items)
# Search by Paramaters
params = { 'createdFrom': '2016-04-25', 'createdTo': '2020-12-25' }
items = ecwid.products.get_by_params(params)
pprint(items)
# Get all products and use lambda function to search results
items = ecwid.products.get()
usb_list = list(filter(lambda items: 'USB' in items.get('name'), items))
pprint(usb_list)
Sample: Add item (remove first if it exists) then modify details.
from pyecwid import Ecwid
import json, time
ecwid = Ecwid('public_ASDF', '1234567')
# Import an item from JSON file
with open('./samplejson/product.json') as json_file:
new_product = json.load(json_file)
# Check if item already exists. If so remove.
product_search = ecwid.products.get_by_keyword(new_product['sku'])
if len(product_search) > 0:
exisiting_item_id = product_search[0]['id']
result = ecwid.products.delete(exisiting_item_id)
if result == 1:
print("Existing item removed")
time.sleep(2)
new_item_id = ecwid.products.add(new_product)
updated_data = {'name': 'My New Product'}
result = ecwid.products.update(new_item_id, updated_data)
print(result.text)
Sample: Just importing required endpoints
from pyecwid import EcwidAPI
from pyecwid.endpoints import Products
API_TOKEN = 'secret_ASDF'
API_STORE = '1234567'
ecwid = EcwidAPI(API_TOKEN, API_STORE)
products = Products(ecwid)
results = products.get()
Debugging: Use EcwidAPIMock for console logging calls.
from pyecwid import EcwidMock
ecwid = EcwidMock(API_TOKEN, API_STORE)
result = ecwid.products.get()
OR
from pyecwid import EcwidAPIMock
from pyecwid.endpoints import Products
ecwid = EcwidAPIMock(API_TOKEN, API_STORE)
products = Products(ecwid)
results = products.get()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pyecwid-0.1.1.tar.gz
.
File metadata
- Download URL: pyecwid-0.1.1.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2948e8653ca84331bda21e5e12a7fec30a7f2602f9c1b278b072b9244d077dea |
|
MD5 | 7a7faab450d494611cdf5c415b99d4c7 |
|
BLAKE2b-256 | eb99ff206fad8e58273529d7ef7137964b35d8f6544a7bb5636eedc41bd77ad8 |
File details
Details for the file pyecwid-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: pyecwid-0.1.1-py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b227b216700881531a44acc07c768fee82db92aa1ff0ac71bad9dbb05e0b4ed |
|
MD5 | 00c554f07b6e25b5ab777fbaeed50646 |
|
BLAKE2b-256 | 40845f428fb104febd7354c862dad29b9daedf04f4d9cbf711ba8f3f765835e0 |