Devtantra Blog

Tutorials about Android, Angular, ReactJS, PHP, MySQL and Web Development

Python WordPress xmlrpc’s

As we know python is very easy languages and by the help of that you can easily create cloud application. But are you know that by the help of python you can control WordPress. Yes By the help of python you can control WordPress, which is written in php (hypertext preprocessor) Languages. From Few days i was trying to collapse these both things and finally i found that yes we can do this by the uses of XML-RPC interface and this is python library which help us to interface with WordPress blog.

Python WordPress

WordPress has its own implementation for WordPress-specific functionality in an API called the WordPress API. This should be used when possible, and your client should use the API variants beginning with the wp prefix.

WordPress also supports the Blogger API, metaWeblog API.

Note

In WordPress 3.5+, the XML-RPC API is enabled by default and cannot be disabled.
In WordPress 0.70-3.42, the XML-RPC API is disabled by default. To enable it, go to Settings->Writing->Remote Publishing and check the box for XML-RPC.

Getting Started

    • Installation
    • Working For Post

Installation

  • Check your WordPress Version, If your WordPress Version is 3.4 and less than this so please enable your XML-RPC by upper note second point method.
  • When you complete first part of this installation then use this command or process according to your system(OS)

Windows

For best results, uninstall previous versions FIRST (see Uninstalling).

Using Windows 8 (which includes PowerShell 3) or earlier versions of Windows with PowerShell 3 installed, it’s possible to install with one simple Powershell command. Start up Powershell and paste this command:

> (Invoke-WebRequest https://bootstrap.pypa.io/ez_setup.py).Content | python -

You must start the Powershell with Administrative privileges or you may choose to install a user-local installation:

> (Invoke-WebRequest https://bootstrap.pypa.io/ez_setup.py).Content | python - --user

If you have Python 3.3 or later, you can use the py command to install to different Python versions. For example, to install to Python 3.3 if you have Python 2.7 installed:

> (Invoke-WebRequest https://bootstrap.pypa.io/ez_setup.py).Content | py -3 -

The recommended way to install setuptools on Windows is to download ez_setup.py and run it. The script will download the appropriate distribution file and install it for you.

Once installation is complete, you will find an easy_install program in your Python Scripts subdirectory. For simple invocation and best results, add this directory to your PATH environment variable, if it is not already present. If you did a user-local install, the Scripts subdirectory is$env:APPDATA\Python\Scripts.

Windows 7 and lower version

For Windows without PowerShell 3 or for installation without a command-line, download ez_setup.py using your preferred web browser or other technique and “run” that file.

Linux/Unix

Install from PyPI using

easy_install python-wordpress-xmlrpc

or

pip install python-wordpress-xmlrpc.

Working

Create an instance of the Client class with the URL of the WordPress XML-RPC . Then pass an XmlrpcMethod object into its call method to execute the remote call and return the result.

>>> from wordpress_xmlrpc import Client, WordPressPost
>>> from wordpress_xmlrpc.methods.posts import GetPosts, NewPost
>>> from wordpress_xmlrpc.methods.users import GetUserInfo

>>> wp = Client('http://mysite.wordpress.com/xmlrpc.php', 'username', 'password')
>>> wp.call(GetPosts())
[]

>>> wp.call(GetUserInfo())


>>> post = WordPressPost()
>>> post.title = 'My new title'
>>> post.content = 'This is the body of my new post.'
>>> post.terms_names = {
>>>   'post_tag': ['test', 'firstpost'],
>>>   'category': ['Introductions', 'Tests']
>>> }
>>> wp.call(NewPost(post))

There are lot’s of other methods by which you can manipulate the WordPress by using python XML-RPC library. 🙂

Conclusion

As you see that this very easy process by which you can control your WordPress as a remote server without any difficulties. Here i explain a single method but there are lots of other method like post, pages, Category etc.. 🙂

0
0

1 thought on “Python WordPress xmlrpc’s

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: