Skip to main content

A Python client for interacting with WordPress REST API

Project description

WordPressClient Python Package Documentation


Overview

WordPressClient is a Python client library designed to interact with the WordPress REST API. This package allows you to easily retrieve posts, categories, comments, and perform various operations by integrating seamlessly with any WordPress site. It's built with simplicity and flexibility in mind, allowing developers to easily manage WordPress content programmatically.


Installation

To install the WordPressClient package, you can use pip:

pip install wordpress-client

Usage

Initializing the Client

The WordPressClient class requires a WordPress site URL to initialize. It also accepts an optional proxy parameter if you need to route requests through a proxy.

from wordpress_client.client import WordPressClient

client = WordPressClient('https://criptoexperto.com')

Supported URL Formats

The WordPressClient supports various URL formats:

  • https://criptoexperto.com
  • http://criptoexperto.com
  • criptoexperto.com (defaults to HTTPS)

Retrieving Recent Posts

To fetch the most recent posts from the WordPress site:

recent_posts = client.get_recent_posts()

This returns a JSON array of recent posts.

Retrieving Categories

To fetch all categories from the WordPress site:

categories = client.get_categories()

This returns a JSON array of categories available on the site.

Retrieving Posts by Category

To fetch posts within a specific category, optionally filtered by a date range:

category_posts = client.get_posts_by_category(category_id=1, start_date='2020-01-01', end_date='2021-01-01')

This will return posts in the specified category that were published within the given date range.

Retrieving Posts by Date Range

To fetch posts within a specific date range, optionally filtered by category:

date_range_posts = client.get_posts_by_date_range(start_date='2020-01-01', end_date='2021-01-01', category_id=1)

This will return posts published between the specified dates, optionally filtered by the given category.

Retrieving Comments by Post

To fetch comments associated with a specific post:

post_comments = client.get_comments_by_post(post_id=1)

This returns a JSON array of comments for the specified post.

Retrieving Posts by Author

To fetch posts written by a specific author:

author_posts = client.get_posts_by_author(author_id=1)

This returns a JSON array of posts by the specified author.


Examples

Here is a simple example to demonstrate the usage:

from wordpress_client.client import WordPressClient

client = WordPressClient('https://criptoexperto.com')

# Fetch recent posts
recent_posts = client.get_recent_posts()
print(recent_posts)

# Fetch categories
categories = client.get_categories()
print(categories)

# Fetch posts by category within a date range
category_posts = client.get_posts_by_category(category_id=2, start_date='2024-01-01', end_date='2024-12-31')
print(category_posts)

# Fetch comments for a specific post
comments = client.get_comments_by_post(post_id=5)
print(comments)

# Fetch posts by a specific author
author_posts = client.get_posts_by_author(author_id=3)
print(author_posts)

Error Handling

The library handles HTTP errors gracefully. If a request fails due to an HTTP error (e.g., 404 or 500), it prints the error and the server response. You can further customize error handling as needed.

try:
    posts = client.get_recent_posts()
except Exception as e:
    print("An error occurred:", e)

License

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


Contributing

Contributions are welcome! Please see the CONTRIBUTING file for more information on how to contribute to this project.


Contact

For any inquiries or issues, please open an issue on GitHub or contact the maintainer directly.


This documentation is designed to be clear and easy to follow, ensuring that users of all skill levels can utilize the WordPressClient package effectively. It can be displayed on both the GitHub repository and the PyPI page, providing consistent and accessible information across platforms.

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_client-0.1.3.tar.gz (4.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_client-0.1.3-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wordpress_client-0.1.3.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for wordpress_client-0.1.3.tar.gz
Algorithm Hash digest
SHA256 ff8b475df2cc0b84c110779bb61028fc1f0fc01b5ad09f0203d0b852ffd68ed5
MD5 ae36da6e1d62250135a3ab58f6b117af
BLAKE2b-256 4278fce568d51ffb1f68fc0ee1bff1338e68167d56633a8d6ccc774e7fd72864

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for wordpress_client-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f4d6e4817acec2a1daeda7e5f6a6572ce6c86c12ae2714361de006f8d4b3f2eb
MD5 28e55e635366343c69202031abe5b815
BLAKE2b-256 4aa18ed0ae2a7ce6fb692b2517f1fb5b2bbd7a8583276fc2a148e500e90c48dc

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