Skip to content

prestashop is a library for Python to interact with the PrestaShop's Web Service API.

License

Notifications You must be signed in to change notification settings

AISYSNEXT-Ltd/prestashop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prestashop

Prestashop is a library for Python to interact with the PrestaShop's Web Service API.

Learn more about the Prestashop Web Service from the Official Documentation

Installation

using pip :

pip install prestashop

the git repo:

git clone https://github.com/AiSyS-Next/prestashop 
cd prestashop
pip install . 

Usage

init api

for json data format

from prestashop import Prestashop, Format

api = Prestashop(
    url = "https://myprestashop.com",
    api_key="4MV3E41MFR7E3N9VNJE2W5EHS83E2EMI",
    default_lang=1,
    debug=True,
    data_format=Format.JSON,
)

for xml data format

from prestashop import Prestashop, Format

api = Prestashop(
    url = "https://myprestashop.com",
    api_key="4MV3E41MFR7E3N9VNJE2W5EHS83E2EMI",
    default_lang=1,
    debug=True,
    data_format=Format.XML,
)

Test API

test if you webservice run

api.ping()

Create Record

data = {
        'tax':{
            'rate' : 3.000,
            'active': '1',
            'name' : {
                'language' : {
                    'attrs' : {'id' : '1'},
                    'value' : '3% tax'
                }
            }
        }
    }

rec = api.create('taxes',data)

Add product image

file_name = 'sample.jpg'

api.create_binary('images/products/30',file=file_name , _type='image')

Update record

update_data = {
        'tax':{
            'id' : str(rec['id']),
            'rate' : 3.000,
            'active': '1',
            'name' : {
                'language' : {
                    'attrs' : {'id' : '1'},
                    'value' : '3% tax'
                }
            }
        }
    }

update_rec = api.write('taxes',update_data)

Remove record

api.unlink('taxes',str(rec['id']))

remove many records at once

api.unlink('taxes',[2,4,5])

Read

import pprint
result = api.read('taxes','2',display='[id,name]')

pprint(result)

Search

 # search the first 3 taxes with 5 in the name 
import pprint
recs = api.search('taxes',_filter='[name]=%[5]%',limit='3')

for rec in recs:
    pprint(rec)


# search with id = 3 or id = 5

recs = api.search('taxes' ,_filter='[id]=[3 | 5]')

Copyright and License

prestashop is copyright (c) 2023 Aymen Jemi (AISYSNEXT)

prestashop is free software: you can redistribute it and/or modify it under the terms of the GPLv3 General Public License as published by the Free Software Foundation, version 3 of the License .

About

prestashop is a library for Python to interact with the PrestaShop's Web Service API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages