{ "info": { "author": "Claudio Sanches @ Automattic, forked by Derwent @ Laserphile", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.6", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Wordpress API - Python Client\n===============================\n\n.. image:: https://travis-ci.org/derwentx/wp-api-python.svg?branch=master\n :target: https://travis-ci.org/derwentx/wp-api-python\n \n.. image:: https://api.codeclimate.com/v1/badges/4df627621037b2df7e5d/maintainability\n :target: https://codeclimate.com/github/derwentx/wp-api-python/maintainability\n :alt: Maintainability\n \n.. image:: https://api.codeclimate.com/v1/badges/4df627621037b2df7e5d/test_coverage\n :target: https://codeclimate.com/github/derwentx/wp-api-python/test_coverage\n :alt: Test Coverage\n\n.. image:: https://snyk.io/test/github/derwentx/wp-api-python/badge.svg?targetFile=requirements.txt\n :target: https://snyk.io/test/github/derwentx/wp-api-python?targetFile=requirements.txt\n\nA Python wrapper for the Wordpress and WooCommerce REST APIs with oAuth1a 3leg support.\n\nSupports the Wordpress REST API v1-2, WooCommerce REST API v1-3 and WooCommerce WP-API v1-2 (with automatic OAuth3a handling).\nForked from the excellent WooCommerce API written by Claudio Sanches and modified to work with Wordpress: https://github.com/woocommerce/wc-api-python\n\nI created this fork because I prefer the way that the wc-api-python client interfaces with\nthe Wordpress API compared to the existing python client, https://pypi.python.org/pypi/wordpress_json\nwhich does not support OAuth authentication, only Basic Authentication (very unsecure)\n\nAny comments about how you're using the API and suggestions about how this repository could be improved are welcome :).\nYou can find my contact info in my GitHub profile.\n\nRoadmap\n-------\n\n- [x] Create initial fork\n- [x] Implement 3-legged OAuth on Wordpress client\n- [x] Better local storage of OAuth credentials to stop unnecessary API keys being generated\n- [x] Support image upload to WC Api\n- [ ] Better handling of timeouts with a back-off\n- [ ] Implement iterator for convenient access to API items\n\nRequirements\n------------\n\nWordpress version 4.7+ comes pre-installed with REST API v2, so you don't need to have the WP REST API plugin if you have the latest Wordpress.\n\nYou should have the following plugins installed on your wordpress site:\n\n- **WP REST API** (only required for WP < v4.7, recommended version: 2.0+)\n- **WP REST API - OAuth 1.0a Server** (optional, if you want oauth within the wordpress API. https://github.com/WP-API/OAuth1)\n- **WP REST API - Meta Endpoints** (optional)\n- **WooCommerce** (optional, if you want to use the WooCommerce API)\n\nThe following python packages are also used by the package\n\n- **requests**\n- **beautifulsoup**\n\nInstallation\n------------\n\nInstall with pip\n\n.. code-block:: bash\n\n pip install wordpress-api\n\nDownload this repo and use setuptools to install the package\n\n.. code-block:: bash\n\n pip install setuptools\n git clone https://github.com/derwentx/wp-api-python\n python setup.py install\n\nTesting\n-------\n\nSome of the tests make API calls to a dockerized woocommerce container. Don't\nworry! It's really simple to set up. You just need to install docker and run\n\n.. code-block:: bash\n\n docker-compose up -d\n # this just waits until the docker container is set up and exits\n docker exec -it wpapipython_woocommerce_1 bash -c 'until [ -f .done ]; do sleep 1; done; echo \"complete\"'\n\nThen you can test with:\n\n.. code-block:: bash\n\n pip install -r requirements-test.txt\n python setup.py test\n\nPublishing\n----------\n\nNote to self because I keep forgetting how to use Twine >_<\n\n.. code-block:: bash\n\n python setup.py sdist bdist_wheel\n # Check that you've updated changelog\n twine upload dist/wordpress-api-$(python setup.py --version) -r pypitest\n twine upload dist/wordpress-api-$(python setup.py --version) -r pypi\n\n\nGetting started\n---------------\n\nGenerate API credentials (Consumer Key & Consumer Secret) following these instructions: http://v2.wp-api.org/guide/authentication/\n\nSimply go to Users -> Applications and create an Application, e.g. \"REST API\".\nEnter a callback URL that you will be able to remember later such as \"http://example.com/oauth1_callback\" (not really important for this client).\nStore the resulting Key and Secret somewhere safe.\n\nCheck out the Wordpress API endpoints and data that can be manipulated in http://v2.wp-api.org/reference/.\n\nSetup\n-----\n\nWordpress API with Basic authentication:\n----\n(Note: requires Basic Authentication plugin)\n\n.. code-block:: python\n\n from wordpress import API\n\n wpapi = API(\n url=\"http://example.com\",\n api=\"wp-json\",\n version='wp/v2',\n wp_user=\"XXXX\",\n wp_pass=\"XXXX\",\n basic_auth = True,\n user_auth = True,\n )\n\nWP REST API v2:\n----\n(Note: the username and password are required so that it can fill out the oauth request token form automatically for you.\nRequires OAuth 1.0a plugin. )\n\n.. code-block:: python\n\n #...\n\n wpapi = API(\n url=\"http://example.com\",\n consumer_key=\"XXXXXXXXXXXX\",\n consumer_secret=\"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\n api=\"wp-json\",\n version=\"wp/v2\",\n wp_user=\"XXXX\",\n wp_pass=\"XXXX\",\n oauth1a_3leg=True,\n creds_store=\"~/.wc-api-creds.json\"\n )\n\nLegacy WooCommerce API v3:\n----\n\n.. code-block:: python\n\n #...\n\n wcapi = API(\n url=\"http://example.com\",\n consumer_key=\"ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\n consumer_secret=\"cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\n api=\"wc-api\",\n version=\"v3\"\n )\n\nNew WC REST API:\n----\nNote: oauth1a 3legged works with Wordpress but not with WooCommerce. However oauth1a signing still works.\nIf you try to do oauth1a_3leg with WooCommerce it just says \"consumer_key not valid\", even if it is valid.\n\n.. code-block:: python\n\n #...\n\n wcapi = API(\n url=\"http://example.com\",\n consumer_key=\"ck_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\n consumer_secret=\"cs_XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\",\n api=\"wp-json\",\n version=\"wc/v2\",\n callback='http://127.0.0.1/oauth1_callback'\n )\n\n\nOptions\n~~~~~~~\n\n+-----------------------+-------------+----------+------------------------------------------------------------------------------------------------------------------+\n| Option | Type | Required | Description |\n+=======================+=============+==========+==================================================================================================================+\n| ``url`` | ``string`` | yes | Your Store URL, example: http://wp.dev/ |\n+-----------------------+-------------+----------+------------------------------------------------------------------------------------------------------------------+\n| ``consumerKey`` | ``string`` | yes | Your API consumer key |\n+-----------------------+-------------+----------+------------------------------------------------------------------------------------------------------------------+\n| ``consumerSecret`` | ``string`` | yes | Your API consumer secret |\n+-----------------------+-------------+----------+------------------------------------------------------------------------------------------------------------------+\n| ``api`` | ``string`` | no | Determines which api to use, defaults to ``wp-json``, can be arbitrary: ``wc-api``, ``oembed`` |\n+-----------------------+-------------+----------+------------------------------------------------------------------------------------------------------------------+\n| ``version`` | ``string`` | no | API version, default is ``wp/v2``, can be ``v3`` or ``wc/v1`` if using ``wc-api`` |\n+-----------------------+-------------+----------+------------------------------------------------------------------------------------------------------------------+\n| ``timeout`` | ``integer`` | no | Connection timeout, default is ``5`` |\n+-----------------------+-------------+----------+------------------------------------------------------------------------------------------------------------------+\n| ``verify_ssl`` | ``bool`` | no | Verify SSL when connect, use this option as ``False`` when need to test with self-signed certificates |\n+-----------------------+-------------+----------+------------------------------------------------------------------------------------------------------------------+\n| ``basic_auth`` | ``bool`` | no | Force Basic Authentication, can be through query string or headers (default) |\n+-----------------------+-------------+----------+------------------------------------------------------------------------------------------------------------------+\n| ``query_string_auth`` | ``bool`` | no | Use query string for Basic Authentication when ``True`` and using HTTPS, default is ``False`` which uses header |\n+-----------------------+-------------+----------+------------------------------------------------------------------------------------------------------------------+\n| ``oauth1a_3leg`` | ``string`` | no | use oauth1a 3-legged authentication |\n+-----------------------+-------------+----------+------------------------------------------------------------------------------------------------------------------+\n| ``creds_store`` | ``string`` | no | JSON file where oauth verifier is stored (only used with OAuth_3Leg) |\n+-----------------------+-------------+----------+------------------------------------------------------------------------------------------------------------------+\n\nMethods\n-------\n\n+--------------+----------------+------------------------------------------------------------------+\n| Params | Type | Description |\n+==============+================+==================================================================+\n| ``endpoint`` | ``string`` | API endpoint, example: ``posts`` or ``user/12`` |\n+--------------+----------------+------------------------------------------------------------------+\n| ``data`` | ``dictionary`` | Data that will be converted to JSON |\n+--------------+----------------+------------------------------------------------------------------+\n\nGET\n~~~\n\n- ``.get(endpoint)``\n\nPOST\n~~~~\n\n- ``.post(endpoint, data)``\n\nPUT\n~~~\n\n- ``.put(endpoint, data)``\n\nDELETE\n~~~~~~\n\n- ``.delete(endpoint)``\n\nOPTIONS\n~~~~~~~\n\n- ``.options(endpoint)``\n\nUpload an image\n-----\n\n(Note: this only works on WP API with basic auth)\n\n.. code-block:: python\n\n assert os.path.exists(img_path), \"img should exist\"\n data = open(img_path, 'rb').read()\n filename = os.path.basename(img_path)\n _, extension = os.path.splitext(filename)\n headers = {\n 'cache-control': 'no-cache',\n 'content-disposition': 'attachment; filename=%s' % filename,\n 'content-type': 'image/%s' % extension\n }\n endpoint = \"/media\"\n return wpapi.post(endpoint, data, headers=headers)\n\nResponse\n--------\n\nAll methods will return `Response `_ object.\n\nExample of returned data:\n\n.. code-block:: bash\n\n >>> from wordpress import api as wpapi\n >>> r = wpapi.get(\"posts\")\n >>> r.status_code\n 200\n >>> r.headers['content-type']\n 'application/json; charset=UTF-8'\n >>> r.encoding\n 'UTF-8'\n >>> r.text\n u'{\"posts\":[{\"title\":\"Flying Ninja\",\"id\":70,...' // Json text\n >>> r.json()\n {u'posts': [{u'sold_individually': False,... // Dictionary data\n\nA note on DELETE requests.\n=====\n\nThe extra keyword arguments passed to the function of a `__request` call (such as `.delete()`) to a `wordpress.API` object are used to modify a `Requests.request` call, this is to allow you to specify custom parameters to modify how the request is made such as `headers`. At the moment it only passes the `headers` parameter to requests, but if I see a use case for it, I can forward more of the parameters to `Requests`.\nThe `delete` function doesn\u2019t accept a data object because a HTTP DELETE request does not typically have a payload, and some implementations of a HTTP server would reject a DELETE request that has a payload.\nYou can still pass api request parameters in the query string of the URL. I would suggest using a library like `urlparse` / `urllib.parse` to modify the query string if you are automatically deleting users.\nAccording the the [documentation](https://developer.wordpress.org/rest-api/reference/users/#delete-a-user) for deleting a user, you need to pass the `force` and `reassign` parameters to the API, which can be done by appending them to the endpoint URL.\n.. code-block:: python\n >>> response = wpapi.delete(\u2018/users/?reassign=&force=true\u2019)\n >>> response.json()\n {\u201cdeleted\u201d:true, ... }\n\nA Note on Encoding\n====\n\nIn Python2, make sure to only `POST` unicode string objects or strings that\nhave been correctly encoded as utf-8. Serializing objects containing non-utf8\nbyte strings in Python2 is broken by importing `unicode_literals` from\n`__future__` because of a bug in `json.dumps`. You may be able to get around\nthis problem by serializing the data yourself.\n\n\nChangelog\n---------\n\n1.2.8 - 2018/10/13\n~~~~~~~~~~~~~~~~~~\n- Much better python3 support\n- really good tests\n- added NoAuth option for adding custom headers (like JWT)\n\n1.2.7 - 2018/06/18\n~~~~~~~~~~~~~~~~~~\n- Don't crash on \"-1\" response from API.\n- Fix windows encoding error\n\n1.2.6 - 2018/01/29\n~~~~~~~~~~~~~~~~~~\n- Better Python3 support\n- Tested on Python v3.6.2 and v2.7.13\n\n1.2.5 - 2017/12/07\n~~~~~~~~~~~~~~~~~~\n- Better UTF-8 support\n\n1.2.4 - 2017/10/01\n~~~~~~~~~~~~~~~~~~\n- Support for image upload\n- More accurate documentation of WP authentication methods\n\n1.2.3 - 2017/09/07\n~~~~~~~~~~~~~~~~~~\n- Better local storage of OAuth creds to stop unnecessary API keys being generated\n- Improve parsing of API errors to display much more useful error information\n\n1.2.2 - 2017/06/16\n~~~~~~~~~~~~~~~~~~\n- support basic auth without https\n- rename oauth module to auth (since auth covers oauth and basic auth)\n- tested with latest versions of WP and WC\n\n1.2.1 - 2016/12/13\n~~~~~~~~~~~~~~~~~~\n- tested to handle complex queries like filter[limit]\n- fix: Some edge cases where queries were out of order causing signature mismatch\n- hardened helper and api classes and added corresponding test cases\n\n1.2.0 - 2016/09/28\n~~~~~~~~~~~~~~~~~~\n\n- Initial fork\n- Implemented 3-legged OAuth\n- Tested with pagination", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/derwentx/wp-api-python", "keywords": "python wordpress woocommerce api development", "license": "MIT License", "maintainer": "", "maintainer_email": "", "name": "wordpress-api", "package_url": "https://pypi.org/project/wordpress-api/", "platform": "any", "project_url": "https://pypi.org/project/wordpress-api/", "project_urls": { "Homepage": "https://github.com/derwentx/wp-api-python" }, "release_url": "https://pypi.org/project/wordpress-api/1.2.9/", "requires_dist": null, "requires_python": "", "summary": "A Python wrapper for the Wordpress and WooCommerce REST APIs with oAuth1a 3leg support", "version": "1.2.9" }, "last_serial": 5227455, "releases": { "1.2.0": [], "1.2.1": [], "1.2.2": [ { "comment_text": "", "digests": { "md5": "4932234a93d9a20734c6de5966f86bc8", "sha256": "a58e7656ad728a106dce6e255302bd021baae43c9fc9acfa453f0580cb3affcd" }, "downloads": -1, "filename": "wordpress-api-1.2.2.tar.gz", "has_sig": false, "md5_digest": "4932234a93d9a20734c6de5966f86bc8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 14845, "upload_time": "2017-06-20T05:13:31", "url": "https://files.pythonhosted.org/packages/85/92/540ec552bfe97bb070d12c58d99625455270dbd44329ce0f0044fbd0faac/wordpress-api-1.2.2.tar.gz" } ], "1.2.3": [ { "comment_text": "", "digests": { "md5": "d366373ac02ac3fd71817a5dda6f5480", "sha256": "0034dccf30642096e02b94986fe44616075f96988c9bf0d8ce9a520b8417a28c" }, "downloads": -1, "filename": "wordpress-api-1.2.3.tar.gz", "has_sig": false, "md5_digest": "d366373ac02ac3fd71817a5dda6f5480", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16114, "upload_time": "2017-09-06T23:33:43", "url": "https://files.pythonhosted.org/packages/26/b6/544f1978f6605fb4e2df899c727f4418b8ec6481dfeb696f0cff5ec3a217/wordpress-api-1.2.3.tar.gz" } ], "1.2.4": [ { "comment_text": "", "digests": { "md5": "2fdf9171b48bf4691356d099309be5d7", "sha256": "4d6d970da6e9dfcadc3ebbdab87de832e641e75d9ab66e4be8bebab7e071fc99" }, "downloads": -1, "filename": "wordpress-api-1.2.4.tar.gz", "has_sig": false, "md5_digest": "2fdf9171b48bf4691356d099309be5d7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18925, "upload_time": "2017-11-01T11:49:41", "url": "https://files.pythonhosted.org/packages/04/65/dc024249efb7a1d268efd6403b8f6c9232dee1d5cb132d78880acb2c37af/wordpress-api-1.2.4.tar.gz" } ], "1.2.5": [ { "comment_text": "", "digests": { "md5": "a8de308d5762ee7cc29c4e28963d83ad", "sha256": "5f5cb478cd5dd2fc9560b7110e2d2ccf82314483d3c6d6614c0e4a1a25559c58" }, "downloads": -1, "filename": "wordpress-api-1.2.5.tar.gz", "has_sig": false, "md5_digest": "a8de308d5762ee7cc29c4e28963d83ad", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 19060, "upload_time": "2017-12-07T05:27:52", "url": "https://files.pythonhosted.org/packages/2e/1c/38eea187d0da1f0caf5670083f039d16bd856ccffd2635c530ed61565846/wordpress-api-1.2.5.tar.gz" } ], "1.2.6": [ { "comment_text": "", "digests": { "md5": "97ec33546b1679782dd47d190e8a0c2c", "sha256": "787357c7c8bdfc9d0a165ba1a27ea92fe0b7f3c7e8860dc199a3a2b2ec50e985" }, "downloads": -1, "filename": "wordpress-api-1.2.6.tar.gz", "has_sig": false, "md5_digest": "97ec33546b1679782dd47d190e8a0c2c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20661, "upload_time": "2018-01-29T08:03:24", "url": "https://files.pythonhosted.org/packages/0f/c3/97928fc638de7b0738962457e3137ec413c03b75ceb7d222d44266baa33d/wordpress-api-1.2.6.tar.gz" } ], "1.2.7": [ { "comment_text": "", "digests": { "md5": "84947fae34ec1b2eead6e6d56d47ee72", "sha256": "e95fc5e6b27cc08c7d0256b7c964e48603e0b350ac260948b3832247a6645a58" }, "downloads": -1, "filename": "wordpress-api-1.2.7.tar.gz", "has_sig": false, "md5_digest": "84947fae34ec1b2eead6e6d56d47ee72", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20707, "upload_time": "2018-06-18T01:19:40", "url": "https://files.pythonhosted.org/packages/a5/93/29f0364cee49837cb5f1504fec744b3660cc63b7d86a5c1f557b98b69326/wordpress-api-1.2.7.tar.gz" } ], "1.2.8": [ { "comment_text": "", "digests": { "md5": "860c8d1c78d667b991ffb6001dd56101", "sha256": "b9ce50e69ccd7093a512b1a78d500dbb6f9a351b25271104dfdd476b1241c331" }, "downloads": -1, "filename": "wordpress_api-1.2.8-py3-none-any.whl", "has_sig": false, "md5_digest": "860c8d1c78d667b991ffb6001dd56101", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 24437, "upload_time": "2018-10-13T04:51:41", "url": "https://files.pythonhosted.org/packages/e2/43/277f341a22572f36c5af638dbd83c8cd131e3d8718cba61706540586943e/wordpress_api-1.2.8-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9277f632f23811126e3ab89c56ef696b", "sha256": "61c3a996a870b35d9b17428a0e53e1e02b1e849e4860fd7d8685602cc36fefe2" }, "downloads": -1, "filename": "wordpress-api-1.2.8.tar.gz", "has_sig": false, "md5_digest": "9277f632f23811126e3ab89c56ef696b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18554, "upload_time": "2019-05-05T04:49:19", "url": "https://files.pythonhosted.org/packages/4b/52/6910807d17b7a3acd6c65ac1c5762a3345ceb6c3f6570bc8e4cbff5595db/wordpress-api-1.2.8.tar.gz" } ], "1.2.9": [ { "comment_text": "", "digests": { "md5": "3f9909bed4cb90c7d4a80282aaa632ec", "sha256": "f6bbaa8c54896549dcdd7f547160fe2eae5e3b1ee0cc1321da08e122db428f84" }, "downloads": -1, "filename": "wordpress-api-1.2.9.tar.gz", "has_sig": false, "md5_digest": "3f9909bed4cb90c7d4a80282aaa632ec", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18554, "upload_time": "2019-05-05T04:58:05", "url": "https://files.pythonhosted.org/packages/25/08/88f930e30c9a5cefa84142b00161601e7433116a89e3038affcacaf4e641/wordpress-api-1.2.9.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "3f9909bed4cb90c7d4a80282aaa632ec", "sha256": "f6bbaa8c54896549dcdd7f547160fe2eae5e3b1ee0cc1321da08e122db428f84" }, "downloads": -1, "filename": "wordpress-api-1.2.9.tar.gz", "has_sig": false, "md5_digest": "3f9909bed4cb90c7d4a80282aaa632ec", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18554, "upload_time": "2019-05-05T04:58:05", "url": "https://files.pythonhosted.org/packages/25/08/88f930e30c9a5cefa84142b00161601e7433116a89e3038affcacaf4e641/wordpress-api-1.2.9.tar.gz" } ] }