Skip to main content

Prestashop Webservice Python API Client

Project description

The Python API for prestashop

Running the test against an existing server:

This file is also a test written in the doctest format. To run the example in this file against your installation of prestashop, replace the api key in the below example and run this file from the doctest module

$ python -m doctest -v README.rst

Example Usage:

Connecting to your store:

>>> from pystashop import PrestaShopWebservice
>>> from datetime import datetime, timedelta
>>> client = PrestaShopWebservice(
...     'http://prestashop.openlabs.co.in',
...     'X76XVCPE71843TIY5CPJVV3NX56Z4MVD')

Getting a list of customers:

>>> customers = client.customers.get_list(as_ids=True)
>>> type(customers)
<type 'list'>
>>> customers_count = len(customers)

Creating customers:

>>> new_customer = client.customers.get_schema()
>>> new_customer.firstname = 'Sharoon'
>>> new_customer.lastname = 'Thomas'
>>> new_customer.email = 'st@openlabs.co.in'
>>> customer = client.customers.create(new_customer)
>>> customer.firstname
'Sharoon'
>>> customer.lastname
'Thomas'
>>> new_customer2 = client.customers.get_schema()
>>> new_customer2.firstname = 'Test'
>>> new_customer2.lastname = 'Customer'
>>> new_customer2.email = 'test@openlabs.co.in'
>>> customer2 = client.customers.create(new_customer2)
>>> customers_list = client.customers.get_list(as_ids=True)
>>> len(customers_list) == customers_count + 2
True
>>> customer.id in customers_list
True

Getting a single customer record:

>>> customer = client.customers.get(customer.id)
>>> customer.firstname
'Sharoon'
>>> customer.lastname
'Thomas'

Editing the customer details:

>>> customer.email = 'info@openlabs.co.in'
>>> result = client.customers.update(customer.id, customer)
>>> updated_data = client.customers.get(customer.id)
>>> updated_data.email
'info@openlabs.co.in'

Choosing fields to display:

>>> customers = client.customers.get_list(
...     display=['id', 'firstname', 'lastname']
... )
>>> isinstance(customers[0].firstname.pyval, basestring)
True
>>> isinstance(customers[0].lastname.pyval, basestring)
True
>>> isinstance(customers[0].id.pyval, int)
True

Filtering Records to Display:

>>> customers = client.customers.get_list(
...     filters={'firstname': 'Sharoon'},
...     display=['firstname']
... )
>>> customers[0].firstname.pyval
'Sharoon'

Filtering Records on basis of date:

>>> customers = client.customers.get_list(
...     filters={
...         'date_add': '{0},{1}'.format(
...             '2012-01-01 00:00:00',
...             datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
...         ),
...         'firstname': 'Sharoon',
...     },
...     display=['firstname'], date=True,
... )
>>> customers[0].firstname.pyval
'Sharoon'
>>> time_diff = timedelta(hours=5)
>>> time_now = datetime.utcnow()
>>> customers = client.customers.get_list(
...     filters={
...         'date_add': '{0},{1}'.format(
...             time_now.strftime('%Y-%m-%d %H:%M:%S'),
...             (time_now + time_diff).strftime(
...                 '%Y-%m-%d %H:%M:%S')
...         ),
...         'firstname': 'Sharoon',
...     },
...     display=['firstname'], date=True,
... )
>>> len(customers)
0

Sorting Records to be displayed:

>>> customers = client.customers.get_list(
...     display=['firstname'],
...     sort=[('firstname', 'DESC')]
... )
>>> customers[0].firstname.pyval
'Test'
>>> customers = client.customers.get_list(
...     display=['lastname'],
...     sort=[('lastname', 'DESC')]
... )
>>> customers[0].lastname.pyval
'Thomas'

Limiting and offsetting records to be displayed:

>>> customer_list1 = client.customers.get_list(
...     as_ids=True, limit=1
... )
>>> len(customer_list1)
1
>>> customer_list2 = client.customers.get_list(
...     as_ids=True, offset=2, limit=1
... )
>>> len(customer_list2)
1
>>> customer_list1 == customer_list2
False

Deleting a customer:

>>> client.customers.delete(customer.id)
True
>>> customers_list = client.customers.get_list(as_ids=True)
>>> len(customers_list) == customers_count + 1
True
>>> customer.id in customers_list
False

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

pystashop-0.4.tar.gz (27.1 kB view details)

Uploaded Source

File details

Details for the file pystashop-0.4.tar.gz.

File metadata

  • Download URL: pystashop-0.4.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pystashop-0.4.tar.gz
Algorithm Hash digest
SHA256 490eec441574b2293b99e3431abbdd3bc001ebc61fdace44d17a9e4c1af41d1f
MD5 3cb2377000f8c4f68eb713dbdf13711d
BLAKE2b-256 89d9e37be064f33c64e8b4078e20123a85d314beebce2a38916dd3d7b3fdb3da

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 Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page