|
| 1 | +WooCommerce API - Python Client |
| 2 | +=============================== |
| 3 | + |
| 4 | +A Python wrapper for the WooCommerce REST API. Easily interact with the WooCommerce REST API using this library. |
| 5 | + |
| 6 | +.. image:: https://secure.travis-ci.org/woothemes/wc-api-python.svg |
| 7 | + :target: http://travis-ci.org/woothemes/wc-api-python |
| 8 | + |
| 9 | + |
| 10 | +Installation |
| 11 | +------------ |
| 12 | + |
| 13 | +.. code-block:: bash |
| 14 | +
|
| 15 | + pip install woocommerce |
| 16 | +
|
| 17 | +Getting started |
| 18 | +--------------- |
| 19 | + |
| 20 | +Generate API credentials (Consumer Key & Consumer Secret) following this instructions http://docs.woothemes.com/document/woocommerce-rest-api/. |
| 21 | + |
| 22 | +Check out the WooCommerce API endpoints and data that can be manipulated in http://woothemes.github.io/woocommerce-rest-api-docs/. |
| 23 | + |
| 24 | +Setup |
| 25 | +----- |
| 26 | + |
| 27 | +.. code-block:: python |
| 28 | +
|
| 29 | + from woocommerce import WooCommerce |
| 30 | +
|
| 31 | + wcapi = woocommerce.api( |
| 32 | + url="http://example.com", |
| 33 | + consumer_key="ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", |
| 34 | + consumer_secret="cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" |
| 35 | + ) |
| 36 | +
|
| 37 | +
|
| 38 | +Options |
| 39 | +~~~~~~~ |
| 40 | + |
| 41 | ++--------------------+------------+----------+-------------------------------------------------------------------------------------------------------+ |
| 42 | +| Option | Type | Required | Description | |
| 43 | ++====================+============+==========+=======================================================================================================+ |
| 44 | +| ``url`` | ``string`` | yes | Your Store URL, example: http://woo.dev/ | |
| 45 | ++--------------------+------------+----------+-------------------------------------------------------------------------------------------------------+ |
| 46 | +| ``consumerKey`` | ``string`` | yes | Your API consumer key | |
| 47 | ++--------------------+------------+----------+-------------------------------------------------------------------------------------------------------+ |
| 48 | +| ``consumerSecret`` | ``string`` | yes | Your API consumer secret | |
| 49 | ++--------------------+------------+----------+-------------------------------------------------------------------------------------------------------+ |
| 50 | +| ``version`` | ``string`` | no | API version, default is ``v3`` | |
| 51 | ++--------------------+------------+----------+-------------------------------------------------------------------------------------------------------+ |
| 52 | +| ``verify_ssl`` | ``bool`` | no | Verify SSL when connect, use this option as ``false`` when need to test with self-signed certificates | |
| 53 | ++--------------------+------------+----------+-------------------------------------------------------------------------------------------------------+ |
| 54 | + |
| 55 | +Methods |
| 56 | +------- |
| 57 | + |
| 58 | ++--------------+----------------+------------------------------------------------------------------+ |
| 59 | +| Params | Type | Description | |
| 60 | ++==============+================+==================================================================+ |
| 61 | +| ``endpoint`` | ``string`` | WooCommerce API endpoint, example: ``customers`` or ``order/12`` | |
| 62 | ++--------------+----------------+------------------------------------------------------------------+ |
| 63 | +| ``data`` | ``dictionary`` | Data that will be converted to JSON | |
| 64 | ++--------------+----------------+------------------------------------------------------------------+ |
| 65 | + |
| 66 | +GET |
| 67 | +~~~ |
| 68 | + |
| 69 | +- ``.get(endpoint)`` |
| 70 | + |
| 71 | +POST |
| 72 | +~~~~ |
| 73 | + |
| 74 | +- ``.post(endpoint, data)`` |
| 75 | + |
| 76 | +PUT |
| 77 | +~~~ |
| 78 | + |
| 79 | +- ``.put(endpoint, data)`` |
| 80 | + |
| 81 | +DELETE |
| 82 | +~~~~~~ |
| 83 | + |
| 84 | +- ``.delete(endpoint)`` |
| 85 | + |
| 86 | +Response |
| 87 | +-------- |
| 88 | + |
| 89 | +All methods will return `Requests <http://docs.python-requests.org/en/latest/>`_ object. |
| 90 | + |
| 91 | +Example of returned data: |
| 92 | + |
| 93 | +.. code-block:: bash |
| 94 | +
|
| 95 | + >>> woocommerce.get("products") |
| 96 | + >>> woocommerce.status_code |
| 97 | + 200 |
| 98 | + >>> woocommerce.headers['content-type'] |
| 99 | + 'application/json; charset=UTF-8' |
| 100 | + >>> woocommerce.encoding |
| 101 | + 'UTF-8' |
| 102 | + >>> woocommerce.text |
| 103 | + u'{"products":[{"title":"Flying Ninja","id":70,...' // Json text |
| 104 | + >>> woocommerce.json() |
| 105 | + {u'products': [{u'sold_individually': False,... // Dictionary data |
0 commit comments