Skip to main content

A thin wrapper for the Wordpress JSON API

Project description

https://travis-ci.org/stylight/python-wordpress-json.svg?branch=master

Super thin Python wrapper for the Wordpress REST API developed by Stylight. Supports the documented read and write endpoints. Extensions and pull requests are encouraged and welcome.

Limitations:

  • doesn’t check input parameters

  • returns a single dictionary or a list of dictionaries, depending on the API endpoint

  • only supports basic auth, and it currently cannot be used without authentication

Dependencies:

  • requests

Installation

pip install wordpress-json

Official PyPI wordpress-json page

Usage

from wordpress-json import WordpressJsonWrapper

# construct a wrapper

wp = WordpressJsonWrapper("http://example.com/wp-json", "wp_user", "wp_password")

# optional headers
headers = {
    "User-Agent": "curl",
    "Content-Type": "text/json",
    # ...
}

# make requests, e.g. list posts
posts = wp.get_posts()
# or with headers
posts = wp.get_posts(headers=headers)

# list posts with filter
posts = wp.get_posts(filter={"status": "draft"})

# create post
data = {
    "title": "My first pony",
    "content": "He's wild!",
    "exerpt": ""
    # ...
}

# only one of title, content and excerpt is required to create a post
wp.create_post(data=data)

# get metadata for a post
meta = wp.get_meta(post_id=4)
# or
meta = wp.get_meta(post_id=4, meta_id=5)

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

wordpress_json-0.1.2.tar.gz (3.9 kB view hashes)

Uploaded Source

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