A Python client for interacting with the WordPress REST API.
Project description
WordPress REST API Python Client
A full-featured Python 3.12 interface to the WordPress REST API.
Overview
This library provides a comprehensive, type-safe Python client for interacting with WordPress sites via the REST API. It supports all major WordPress endpoints including posts, pages, media, users, comments, categories, tags, settings, plugins, themes, menus, and more.
Project Structure
src/wordpress_api/
├── __init__.py # Main exports
├── client.py # WordPressClient main class
├── auth.py # Authentication handlers
├── exceptions.py # Custom exceptions
├── models/ # Pydantic data models
│ ├── post.py
│ ├── page.py
│ ├── media.py
│ ├── user.py
│ ├── comment.py
│ ├── category.py
│ ├── tag.py
│ └── ...
└── endpoints/ # API endpoint classes
├── posts.py
├── pages.py
├── media.py
├── users.py
├── comments.py
└── ...
Quick Start
from wordpress_api import WordPressClient, ApplicationPasswordAuth
# Authenticate with WordPress Application Passwords
auth = ApplicationPasswordAuth("username", "xxxx xxxx xxxx xxxx")
client = WordPressClient("https://your-site.com", auth=auth)
# List posts
posts = client.posts.list()
# Create a post
from wordpress_api.models import PostCreate, PostStatus
post = client.posts.create(PostCreate(
title="Hello World",
content="<p>My first post!</p>",
status=PostStatus.PUBLISH
))
# Get current user
me = client.users.me()
Features
- Full CRUD Support: Posts, Pages, Media, Users, Comments, Categories, Tags
- Authentication: Application Passwords, Basic Auth, JWT
- Type Safety: Pydantic models for all WordPress objects
- Pagination: Automatic iteration through all results
- Media Upload: Upload files from path or file objects
- Custom Post Types: Access any registered custom post type
- Block Editor: Access block types and patterns
- Error Handling: Typed exceptions for all API errors
Dependencies
- httpx: Modern HTTP client
- pydantic: Data validation using Python type annotations
Authentication Setup
- Go to your WordPress site
- Navigate to Users → Your Profile
- Scroll to "Application Passwords"
- Create a new application password
- Use it with
ApplicationPasswordAuth
TODO:
- Add support for custom post types
- Add to models
- Add to endpoints
- Add to client
- Add to testing
- Add support for WP hooks
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file wp_python-0.1.4.tar.gz.
File metadata
- Download URL: wp_python-0.1.4.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.10","id":"questing","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
206d2d5f3252e2ec5a6764cd50089abf3868107cca362f78c241cc016fd7e47c
|
|
| MD5 |
1360fd9cba36d3fd715045b6cba53c52
|
|
| BLAKE2b-256 |
db17f783093da2c8c55141c8cd25ae954913c740b6bfe45b82f29fd2b6c365d6
|
File details
Details for the file wp_python-0.1.4-py3-none-any.whl.
File metadata
- Download URL: wp_python-0.1.4-py3-none-any.whl
- Upload date:
- Size: 2.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"25.10","id":"questing","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1e3200e66497cde84f4b2fc5d944e99414f6146888e0c087f95d7541c7619475
|
|
| MD5 |
182d0ffcb24dfade0ccfc153a29a453b
|
|
| BLAKE2b-256 |
f3daca34be3f07434428ccdfcedd20dc5653c6e1f5b8c2fb54fe9a59937e33ad
|