A note from the author: I no longer do Wordpress work, so I won't have the time to adequately maintain this repo. If you would like to maintain a fork of this repo, and want me to link to your fork here, please let me know.
One such fork is https://github.com/Synoptik-Labs/wp-api-python
thanks!
A Python wrapper for the Wordpress and WooCommerce REST APIs with oAuth1a 3leg support.
Supports the Wordpress REST API v1-2, WooCommerce REST API v1-3 and WooCommerce WP-API v1-2 (with automatic OAuth3a handling). Forked from the excellent WooCommerce API written by Claudio Sanches and modified to work with Wordpress: https://github.com/woocommerce/wc-api-python
I created this fork because I prefer the way that the wc-api-python client interfaces with the Wordpress API compared to the existing python client, https://pypi.python.org/pypi/wordpress_json which does not support OAuth authentication, only Basic Authentication (very unsecure)
Any comments about how you're using the API and suggestions about how this repository could be improved are welcome :). You can find my contact info in my GitHub profile.
- [x] Create initial fork
- [x] Implement 3-legged OAuth on Wordpress client
- [x] Better local storage of OAuth credentials to stop unnecessary API keys being generated
- [x] Support image upload to WC Api
- [ ] Better handling of timeouts with a back-off
- [ ] Implement iterator for convenient access to API items
Wordpress 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.
You should have the following plugins installed on your wordpress site:
- WP REST API (only required for WP < v4.7, recommended version: 2.0+)
- WP REST API - OAuth 1.0a Server (optional, if you want oauth within the wordpress API. https://github.com/WP-API/OAuth1)
- WP REST API - Meta Endpoints (optional)
- WP API Basic Auth https://github.com/WP-API/Basic-Auth (for image uploading)
- WooCommerce (optional, if you want to use the WooCommerce API)
The following python packages are also used by the package
- requests
- beautifulsoup
Install with pip
pip install wordpress-apiDownload this repo and use setuptools to install the package
pip install setuptools
git clone https://github.com/derwentx/wp-api-python
python setup.py installSome of the tests make API calls to a dockerized woocommerce container. Don't worry! It's really simple to set up. You just need to install docker and run
docker-compose up -d
# this just waits until the docker container is set up and exits
docker exec -it wpapipython_woocommerce_1 bash -c 'until [ -f .done ]; do sleep 1; done; echo "complete"'Then you can test with:
pip install -r requirements-test.txt
python setup.py testNote to self because I keep forgetting how to use Twine >_<
python setup.py sdist bdist_wheel
# Check that you've updated changelog
twine upload dist/wordpress-api-$(python setup.py --version) -r pypitest
twine upload dist/wordpress-api-$(python setup.py --version) -r pypiGenerate API credentials (Consumer Key & Consumer Secret) following these instructions: http://v2.wp-api.org/guide/authentication/
Simply go to Users -> Applications and create an Application, e.g. "REST API". Enter a callback URL that you will be able to remember later such as "http://example.com/oauth1_callback" (not really important for this client). Store the resulting Key and Secret somewhere safe.
Check out the Wordpress API endpoints and data that can be manipulated in http://v2.wp-api.org/reference/.
< F616 div class="markdown-heading" dir="auto">