Skip to main content

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

  1. Go to your WordPress site
  2. Navigate to Users → Your Profile
  3. Scroll to "Application Passwords"
  4. Create a new application password
  5. Use it with ApplicationPasswordAuth

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

wp_python-0.1.3.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wp_python-0.1.3-py3-none-any.whl (40.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wp_python-0.1.3.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for wp_python-0.1.3.tar.gz
Algorithm Hash digest
SHA256 7e4fefee9f363f5021bc2ae016705eceb83dd5c2137dce8120a236dcc94c78b7
MD5 069bf9f1ff792d1bb45f0dc4478079f3
BLAKE2b-256 f516d1340665fe84ad55bf48f07c0878f228fd20be953d204d89f882bacc24d0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wp_python-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 40.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for wp_python-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 290026792650b9c463d3ccb106b3f24202d9510a6ced2d9d72dd36d7ec2beaed
MD5 e4673e4e6382a49711708e8d5b932f9e
BLAKE2b-256 1e94296557a2eb71c4046a617b0d8851a47f61502f960362a81ab544c60c2b59

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