Skip to main content

A Python client for interacting with the WordPress REST API.

Project description

Wordpress API Client

A Python client for interacting with the WordPress REST API (Posts). This library simplifies common operations such as creating, updating, retrieving, deleting, and listing posts. It is built on top of the requests library and integrates logging with trackrace (or falls back to Python’s built-in logging).

Overview

The Wordpress API Client provides an easy-to-use interface for working with WordPress posts via the REST API. It supports all the fields and parameters defined in the WordPress REST API Documentation for Posts, making it a robust solution for developers who need to integrate WordPress functionalities into their Python applications.

Key Features

  • Create, Update, Delete, and Retrieve Posts: Manage posts with a simple API.
  • Filtering and Querying: Use various parameters (e.g., date, author, categories, tags) to filter and search posts.
  • Authentication: Supports basic authentication using Base64 encoding.
  • Logging: Integrated logging via trackrace (or standard logging as a fallback) for debugging and monitoring API calls.
  • Comprehensive Field Support: Explicitly supports all fields outlined in the official WordPress REST API documentation.

Installation

Install the package using pip:

pip install wordpress-api-client

Usage

Below is a quick example demonstrating how to use the client:

from wordpress_api_client import WordpressClient

# Initialize the client with your WordPress site URL, username, and password.
wp = WordpressClient("https://example.com", "your_username", "your_password")

# Create a new post.
new_post = wp.create_post(
    title="My First Post",
    content="Hello, WordPress!",
    status="publish"
)
print("Created Post ID:", new_post.get("id"))

# Retrieve the created post.
post = wp.get_post(new_post.get("id"))
print("Post Title:", post.get("title", {}).get("rendered"))

# Update the post.
updated_post = wp.update_post(new_post.get("id"), title="Updated Post Title")
print("Updated Post Title:", updated_post.get("title", {}).get("rendered"))

# Delete the post.
deleted_response = wp.delete_post(new_post.get("id"))
print("Deleted Post Response:", deleted_response)

# List posts with filtering (e.g., only 5 posts sorted by date in descending order).
posts_list = wp.list_posts(per_page=5, order="desc", orderby="date")
print("Posts List:", posts_list)

API Reference

For a complete list of parameters and details on how to use each endpoint, please refer to the WordPress REST API Documentation for Posts.

Testing

The library includes a set of tests using Python's unittest framework. To run the tests, execute:

python -m unittest discover tests

PyPi

Url to PyPi Link.

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contact

For questions or support, please open an issue on the GitHub repository or contact nick.evdokimovv@gmail.com.

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_api_client-0.1.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wordpress_api_client-0.1.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file wordpress_api_client-0.1.1.tar.gz.

File metadata

  • Download URL: wordpress_api_client-0.1.1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.0

File hashes

Hashes for wordpress_api_client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 490e377d1dfe2554300b2c877643abcb2b3d1c45c48945698887de89308883a6
MD5 e77bf89f8e4da71299f52c16409360a3
BLAKE2b-256 d5da26da7e3cd310bc366a770864a46b58cc2955b1d0d34e45b41cec4f2eefda

See more details on using hashes here.

File details

Details for the file wordpress_api_client-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for wordpress_api_client-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 88a5c0712f5d1c3e9c65bbe23f40fc85d8fd3dba12574c4db96e1f960e70a386
MD5 9f44f592c57ee2040f8addcfbfab473c
BLAKE2b-256 553c46a48e3d112f7b76676898e31f6a42350ae4ee013d786f5966809bc0295e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page