Skip to main content

A Python library for posting content, uploading media, and interacting with the WordPress REST API.

Project description

wordpress_poster

A modern Python library for posting content, uploading media, and interacting with the WordPress REST API. Supports any post type, media uploads, and is designed for easy integration and automation in your projects.

Features

  • Post creation for any post type (post, page, or custom types)
  • Media (image) upload
  • Environment variable-based configuration
  • Synchronous API
  • Raises exceptions on errors
  • Returns useful information (e.g., post URL, image URL)
  • Simple, Pythonic interface

Installation

For development (recommended):

pip install -e .

This will install the package in editable mode, so changes to the code are immediately reflected.

For users (from PyPI, if published):

pip install wordpress_poster

Environment Variables

The library requires the following environment variables to be set:

  • WP_URL — Your WordPress site URL (e.g., https://yourblog.com)
  • WP_USERNAME — Your WordPress username
  • WP_PASSWORD — Your WordPress application password (see WordPress Application Passwords)

You can set these in your shell, or use a .env file in your project root:

WP_URL=https://yourblog.com
WP_USERNAME=yourusername
WP_PASSWORD=yourapppassword

Basic Usage

Required Fields Only

from wordpress_poster.client import WordPressClient

wp = WordPressClient()

# Upload an image
success, image_url, image_id = wp.upload_image(
    'https://example.com/image.jpg',
    {'brand': 'Victor', 'name': 'Auraspeed'}
)

# Create a post (required fields only)
post_url = wp.create_post(
    post_type='post',
    title='My Title',
    content='<p>My content</p>'
)
print('Post created at:', post_url)

With Optional Fields

post_url = wp.create_post(
    post_type='post',
    title='My Title',
    content='<p>My content</p>',
    slug='my-title-slug',
    status='publish',
    categories=[2, 3],
    meta={'custom_field': 'value'},
    featured_media=image_id  # Set the featured image
)
print('Post created at:', post_url)

Running Tests

Install dev dependencies and run tests with:

pip install -r requirements.txt
pytest

Contributing

Pull requests and issues are welcome! Please open an issue if you find a bug or have a feature request.

License

MIT License. See LICENSE for details.

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_poster-0.1.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

wordpress_poster-0.1.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file wordpress_poster-0.1.1.tar.gz.

File metadata

  • Download URL: wordpress_poster-0.1.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for wordpress_poster-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9041d3745a62d0a5ea2f40becd2c63e0e01d5326e3814a487ff1f205623ff6c8
MD5 9efa3be3c6eaf26cc4dcb9a9a835aca2
BLAKE2b-256 78ac004a83389534cff950acf76decace72ef79262cf280bee1658bfe81c7b6e

See more details on using hashes here.

File details

Details for the file wordpress_poster-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for wordpress_poster-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f67cfeb8bcfdd8eb10a33c961eaba049effc130e3e2132cb332162ad077e4a3
MD5 65515fdc02d97b632d68f98b6335725c
BLAKE2b-256 e9bdca88c56674d8dfbed4f04cf3b252a8215b6b22239e76991d930f2551b3f8

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