Skip to main content

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, tags, 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 list of WordPressPost instances, each containing detailed information about the posts, such as title, content, date, URL, categories, tags, and more.

Retrieving Categories

To fetch all categories from the WordPress site:

categories = client.get_categories()

This returns a list of WordPressCategory instances, each containing detailed information about the categories, such as name, slug, description, and ID.

Retrieving Tags

To fetch all tags from the WordPress site:

tags = client.get_tags()

This returns a list of WordPressTag instances, each containing detailed information about the tags, such as name, slug, description, and ID.

Retrieving Posts by Category

To fetch posts within a specific category:

category_posts = client.get_posts_by_category(category_id=1, post_count=5, post_order='desc')

This returns a list of WordPressPost instances in the specified category.

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 returns a list of WordPressPost instances 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 list of WordPressComment instances for the specified post, each containing details like author, content, and date.

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 list of WordPressPost instances authored by the specified author.

Retrieving Posts with Advanced Filtering

To fetch posts with advanced filtering options, such as multiple categories and custom sorting:

filtered_posts = client.get_posts_from_wordpress(website_categories="1,2", post_count=5, post_order='asc')

This returns a list of WordPressPost instances, filtered by the specified categories and ordered as requested.


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()
for post in recent_posts:
    print(f"Title: {post.post_title}, Date: {post.post_date}, URL: {post.post_url}")

# Fetch categories
categories = client.get_categories()
for category in categories:
    print(f"Category: {category.name}, ID: {category.id}")

# Fetch tags
tags = client.get_tags()
for tag in tags:
    print(f"Tag: {tag.name}, ID: {tag.id}")

# Fetch comments for a specific post
comments = client.get_comments_by_post(post_id=5)
for comment in comments:
    print(f"Comment by {comment.author_name}: {comment.content[:50]}")

# Fetch posts by a specific author
author_posts = client.get_posts_by_author(author_id=3)
for post in author_posts:
    print(f"Title: {post.post_title}, Date: {post.post_date}")

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.

Metadata

Release files for wordpress-client 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wordpress-client 0.1.6
File Size Uploaded
wordpress_client-0.1.6.tar.gz 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wordpress-client 0.1.6
File Interpreter ABI Platform
wordpress_client-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 15.3 kB

Release files / wordpress_client-0.1.6.tar.gz

Download URL wordpress_client-0.1.6.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e2e0c742dc513ab40b6f5cf2a763fee7de000886b41f1a75387d21b62b2d996c
BLAKE2b-256 checksum
How to use checksums
d3d92410aeb6df692bc3f94e347abb678fffa2c84393e5d711c3767861dd804c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / wordpress_client-0.1.6-py3-none-any.whl

Download URL wordpress_client-0.1.6-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9f6fb217d39082fb5057e29915fb1cf6d0225a2928eb3e838164fe2848dab1d3
BLAKE2b-256 checksum
How to use checksums
a91e1d641f28b75218897928ff786dfb5a3c5f15ab0019dc50bfc88bd2f64790
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page