Skip to main content

A versatile Python library for seamless interaction with the WordPress REST API, including built-in SEO features and more.

Project description

wpypress

wpypress is a Python library designed for interacting with the WordPress REST API. It simplifies the process of managing posts, pages, media, categories, tags, and SEO settings on WordPress sites.

Features

  • Post Management: Create, update, delete, and list posts.
  • Page Management: Create, update, delete, and list pages.
  • Media Management: Upload, update, delete, and list media items.
  • Category & Tag Management: Create, update, delete, and list categories and tags.
  • SEO Management: Manage SEO settings using the Yoast SEO plugin.

Installation

To install wpypress, simply use pip:

pip install wpypress

Usage

Initialization

To start using the library, first, initialize the WPClient with your WordPress site credentials:

from wpypress import WPClient

wp = WPClient(
    base_url="https://your-wordpress-site.com",
    username="admin",
    password="your-password"
)

Posts

Fetch Posts

Retrieve the first page of posts:

posts, pagination = wp.posts.list(params={'per_page': 10, 'page': 1})
print(f"Total posts: {pagination['total']}")
print(f"Total pages: {pagination['total_pages']}")
print(f"Current page: {pagination['page']}\n")

Create a Post

Create a new post with categories and tags:

post = wp.posts.create(
    title="My New Post",
    content="This is the content.",
    status="publish",
    categories=[2],
    tags=[5, 6],
    featured_media=15
)

Delete a Post

To delete a post, use:

wp.posts.delete(123, force=True)

Pages

Create a New Page

To create a new page:

page = wp.pages.create(
    title="About Us",
    content="This is our about page.",
    excerpt="About page",
    status="publish"
)

Media

Upload an Image

To upload a media item, execute:

media = wp.media.upload(
    file_path='./images/photo.jpg',
    title='My Photo',
    alt_text='A beautiful photo',
    description='Uploaded via REST APIs'
)

Categories

Create a Category

new_category = wp.categories.create(
    name="Tech News",
    slug="tech-news",
    description="Technology related articles"
)

Tags

Create a Tag

new_tag = wp.tags.create(
    name="Python",
    slug="python",
    description="All posts about Python"
)

SEO

Update Post SEO (Yoast SEO)

Ensure your site has the Yoast SEO plugin activated to manage SEO settings easily:

if wp.seo.is_yoast():
    wp.seo.update(
        post_id=456,
        title="Page SEO Title",
        description="Meta description for the page.",
        og_title="OpenGraph Title for Page",
        og_description="OpenGraph Description for Page",
        type="page"
    )

License

This project is licensed under the MIT License - see the LICENSE file 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

wpypress-0.1.2.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

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

wpypress-0.1.2-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file wpypress-0.1.2.tar.gz.

File metadata

  • Download URL: wpypress-0.1.2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for wpypress-0.1.2.tar.gz
Algorithm Hash digest
SHA256 538313c3e1c002efbb1e5df9cb1179a89d25017f072c61f960b7dbfddde83c18
MD5 b5a1e5b81dbb8759d817d3873b3cd03e
BLAKE2b-256 787f53876d2c2515e8ae4d5b1bfc9cb8447f98204085d22c7f7687b61d4f0218

See more details on using hashes here.

File details

Details for the file wpypress-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: wpypress-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for wpypress-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 75402774fae79a53a262a677fbf75a490b87ad99607588ed70d2aeca52191df8
MD5 c491e26cd1e4ff75370fa384808a1fe6
BLAKE2b-256 12b2ca7d5577e02fd324f375bab6f81cc4c505cf674428e38761bac1089ded22

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