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

Uploaded Python 3

File details

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

File metadata

  • Download URL: wordpress_api_client-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 a8f4251637e8bd5668f61e7f403a593ec5bbd75f55de1ce746ba07e9f69edfc9
MD5 ae026cd29c795fdd2e29cd4b88030aa9
BLAKE2b-256 c487de243d72982a4848a61f223a066543af58c744b6aac8f319e9589319d7e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for wordpress_api_client-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 152622c9cb0ba9fa25fcd1428b984dd365e5fea66e7fefcd8ffdf5d8aeca4b0a
MD5 b5d29bf99b621ba69f1b4868070d10df
BLAKE2b-256 6da0ebbbab8b23cfaeaaab64b3205fc2e4b1cb2a78fdea884c770ebcb4560c88

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