.. image:: https://img.shields.io/travis/stylight/python-wordpress-json.svg :target: https://travis-ci.org/stylight/python-wordpress-json
.. image:: https://img.shields.io/pypi/v/wordpress_json.svg :target: https://pypi.python.org/pypi/wordpress_json
Super thin Python wrapper for the Wordpress REST API V2 <http://v2.wp-api.org/>
developed by
Stylight <http://www.stylight.com/>
. Supports the documented read and write endpoints. Extensions and pull requests are encouraged and welcome.
Limitations:
Dependencies:
::
pip install wordpress-json
Before being able to use this package make sure you configure Wordpress properly.
You need to install the WP-API Plugin. To do so:
You need to install and activate the WP REST API Meta Endpoints plugin for the WP-API :
You need to install and activate the Basic-Auth plugin for the WP-API :
Change permalink configuration to 'Post name' in Permalink Settings.
.. code-block:: python
>>> from wordpress_json import WordpressJsonWrapper
>>> wp = WordpressJsonWrapper('http://example.com/wp-json/wp/v2', 'wp_user', 'wp_password')
>>> posts = wp.get_posts()
>>> posts[0].keys()
dict_keys(['format', 'featured_media', 'author', ...])
>>> posts[0].get('title')
{'rendered': 'Tweetle Beetles'}
>>> posts[0].get('content')
{'rendered': '<p>What do you know about tweetle beetles? ...'}
>>> posts[0].get('id')
42
>>> wp.create_meta(post_id=42, data=dict(key='genre', value='fanciful'))
>>> meta = wp.get_meta(post_id=42)
>>> meta[0].get('key')
'genre'
>>> meta[0].get('value')
'fanciful'