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.3.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.3-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wordpress_api_client-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 c80f9ab6e22586d743a014a50ac96a6b7726871199d0638f369cdbdf8880f763
MD5 72997c8f130e16e61362966775859e97
BLAKE2b-256 dbd116f49a4915c6f375854669692e3877182eda40d75c7b6d65debf53d3f37e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for wordpress_api_client-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 38dc22153556353087175496d1dcb3f3269249ae7994ff03d78f9f1cc2999e50
MD5 0c336acc5727a7c3f70a701d4195f1ea
BLAKE2b-256 744f4952f1b83bbc28d4e7881ecdb3b3e93b86a1d9c6ec5bba11791eda41c4b9

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