Skip to main content

A library to access Prestashop Web Service from Python.

Project description

# Prestapyt

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

Learn more about the PrestaShop Web Service from the [Official Prestashop Documentation].

prestapyt is a direct port of the PrestaShop PHP API Client, PSWebServiceLibrary.php

Similar to PSWebServiceLibrary.php, prestapyt is a thin wrapper around the PrestaShop Web Service:
it takes care of making the call to your PrestaShop instance's Web Service,
supports the Web Service's HTTP-based CRUD operations (handling any errors)
and then returns the XML ready for you to work with in Python
(as well as prestasac if you work with scala).


## Installation

The easiest way to install prestapyt (needs setuptools):

easy_install prestapyt

Or, better, using pip:

pip install prestapyt

If you do not have setuptools, download prestapyt as a .tar.gz or .zip from
[Prestapyt Source Archives], untar it and run:

python setup.py install


## Usage


### Message as xml
```python
from prestapyt import PrestaShopWebService
prestashop = PrestaShopWebService('http://localhost:8080/api', WEBSERVICE_KEY)
```

### Message as dictionary
```python
from prestapyt import PrestaShopWebServiceDict
prestashop = PrestaShopWebServiceDict('http://localhost:8080/api', WEBSERVICE_KEY)
```

### Search

#### Get all addresses
```python
prestashop.get('addresses') # will return the same xml message than
prestashop.search('addresses')
```
Note: when using PrestaShopWebServiceDict ``prestashop.search('addresses')`` will return a list of ids.


#### Search with filters
```python
prestashop.search('addresses', options={'limit': 10})
prestashop.search('addresses', options={'display': '[firstname,lastname]', 'filter[id]': '[1|5]'})
```
For additional info [check reference for the options](http://doc.prestashop.com/display/PS14/Cheat+Sheet_+Concepts+Outlined+in+this+Tutorial).

#### Get single address
```python
prestashop.get('addresses', resource_id=1) or prestashop.get('addresses/1')
```
returns ElementTree (PrestaShopWebService) or dict (PrestaShopWebServiceDict).

You can use the full api URL

```python
prestashop.get('http://localhost:8080/api/addresses/1')
```

#### Head request

```python
prestashop.head('addresses')
```

### Manipulate records

#### Delete
```python
prestashop.delete('addresses', resource_ids=4)
```

#### Delete many records at once
```python
prestashop.delete('addresses', resource_ids=[5,6])
```

#### Add record
```python
prestashop.add('addresses', xml)
```

#### Edit record
```python
prestashop.edit('addresses', xml)
```

#### Get model blank xml schema
```python
prestashop.get('addresses', options={'schema': 'blank'})
```

#### Add product image

```python
file_name = 'sample.jpg'
fd = io.open(file_name, "rb")
content = fd.read()
fd.close()

prestashop.add('/images/products/123', files=[('image', file_name, content)])
```

## API Documentation

Documentation for the PrestaShop Web Service can be found on the
PrestaShop wiki: [Using the REST webservice]


## Credits:

Thanks to Prestashop SA for their PHP API Client PSWebServiceLibrary.php

Thanks to Alex Dean for his port of PSWebServiceLibrary.php
to the Scala language, [prestasac] from which I also inspired my library.


## Copyright and License

prestapyt is copyright (c) 2012 Guewen Baconnier

prestapyt is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.

prestapyt is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public
License along with prestapyt. If not, see [GNU licenses](http://www.gnu.org/licenses/).



[Official Prestashop Documentation]: http://doc.prestashop.com/display/PS14/Using+the+REST+webservice
[Using the REST webservice]: http://doc.prestashop.com/display/PS14/Using+the+REST+webservice
[Prestapyt Source Archives]: https://github.com/guewen/prestapyt/downloads
[prestasac]: https://github.com/orderly/prestashop-scala-client

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

prestapyt-0.8.0.tar.gz (12.4 kB view details)

Uploaded Source

Built Distributions

prestapyt-0.8.0-py2.7.egg (28.3 kB view details)

Uploaded Source

prestapyt-0.8.0-py2-none-any.whl (16.8 kB view details)

Uploaded Python 2

File details

Details for the file prestapyt-0.8.0.tar.gz.

File metadata

  • Download URL: prestapyt-0.8.0.tar.gz
  • Upload date:
  • Size: 12.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for prestapyt-0.8.0.tar.gz
Algorithm Hash digest
SHA256 9af8cc0a8c64ec4315e82ca0bf4b80fbb37440e8e0ed41323feac992822074dc
MD5 09c867d1edd58fb318c7c93159ad2dea
BLAKE2b-256 741362c2074443eaaa0e57cd4ebab8cf07eb29ff2985f1e7e65c19d032861ca4

See more details on using hashes here.

File details

Details for the file prestapyt-0.8.0-py2.7.egg.

File metadata

File hashes

Hashes for prestapyt-0.8.0-py2.7.egg
Algorithm Hash digest
SHA256 ad204386d8425f917f83931c08bf9c0e1afa49acd152f342cbf4cade3dc0ca91
MD5 9af0cb72890239dbddf6b70fce83292f
BLAKE2b-256 bf83acbcecd399d25b43e0869754f46699a4c775e6ada90f238b31e05f6f7dc6

See more details on using hashes here.

File details

Details for the file prestapyt-0.8.0-py2-none-any.whl.

File metadata

File hashes

Hashes for prestapyt-0.8.0-py2-none-any.whl
Algorithm Hash digest
SHA256 02f7086f737a96d652c697ca9d76eccb1bb21a0bfb92a24654487cc52b685b27
MD5 8a5ac0b197967e17eeb4df0e72abc3a2
BLAKE2b-256 b2043f3e0358498e592df3d7ba091ef35d6a5b15e51bb176e941636b0c9fe4c2

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