WordPress REST API Client
Finally a simple and efficient API to work with your WordPress. A Python client for interacting with the WordPress REST API to manage content, media, and categories.
Features
- Create posts/pages
- Upload images from URLs
- Create categories
- Secure authentication handling
- Error handling for API requests
Installation
Requirements:
- Python 3.6+
- WordPress site with REST API enabled (v4.7+)
- Application password (WordPress > Users > Profile > Application Passwords)
Install dependencies:
pip install WordPRest
Initialize client
from wpAPI import WordPress
wp = WordPress(
domain='yourdomain.com',
username='admin',
password='your_application_password'
)
Create a category
new_category = wp.category("Tech News")
print(f"Created category ID: {new_category['id']}")
Upload an image
image_url = "https://example.com/image.jpg"
media = wp.upload_image(image_url)
print(f"Uploaded media ID: {media['id']}")
Create a post
post_data = {
"title": "My First API Post",
"content": "This post was created programmatically!",
"status": "publish",
"categories": [new_category['id']],
"featured_media": media['id']
}
post = wp.publish(post_data)
print(f"Published post at: {post['link']}")
API Methods
category(data) Purpose: Create a new category
Parameters: content_data (str): Category name
Returns: Category object or None on failure
upload_image(image_url)
Purpose: Upload image from URL to media library
Parameters:
image_url (str): Publicly accessible image URL
Returns: Media object or None on failure
publish(content_data, content_type="post")
Purpose: Create posts/pages
Parameters:
content_data (dict): Post/page content (see WP REST API docs)
content_type (str): "post" (default) or "page"
Returns: Post/Page object or None on failure
Content Data Structure
Typical post structure:
{
"title": "Post Title",
"content": "Post content",
"status": "publish", # or "draft"
"categories": [1, 2], # Array of category IDs
"featured_media": 123, # Media ID from upload_image()
"tags": [3, 4], # Array of tag IDs
"excerpt": "Summary text"
}
Error Handling
Methods return None on failure
Errors are printed to console with details
Common error sources:
-
Invalid credentials
-
Network issues
-
Invalid image URLs
-
Insufficient user permissions
Important Security Practices:
-
Always use application passwords (not regular user passwords)
-
Store credentials in environment variables (not in code)
-
Use HTTPS for your WordPress site
-
Restrict API access through permissions/plugins
Metadata
Release files for WordPResT 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wordprest-0.1.2.tar.gz | 4.7 kB | Without provenance | Details for wordprest-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wordprest-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for wordprest-0.1.2-py3-none-any.whl |
Total release size: 9.8 kB
Release files / wordprest-0.1.2.tar.gz
| Download URL | wordprest-0.1.2.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e3287343a7aedd92e535f19a6ffa43367ed496a7de77b8ac72282d27cf753e6
|
|
BLAKE2b-256 checksum How to use checksums |
1d5873be336968293b67cebf90fc5d9cd2f4d2644fa3191e449a2a5240f8ec69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / wordprest-0.1.2-py3-none-any.whl
| Download URL | wordprest-0.1.2-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c59bff54595141b6101d7a7e934d9723073ddacecaad1add90dafea7b28a7365
|
|
BLAKE2b-256 checksum How to use checksums |
8797717de308c89e396f61942fa4cb0572d6245b947bb8ee5b4bc9be2f93e65a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for WordPResT 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.