Last modified: May 02, 2025 By Alexander Williams

Create First Plone Add-on with Python

Plone is a powerful Python-based CMS. Extending it with add-ons is easy. This guide walks you through creating your first Plone add-on.

Prerequisites

Before starting, ensure you have:

If you get No module named 'plone', check our troubleshooting guide.

Setting Up the Development Environment

First, create a virtual environment:


python -m venv plone-addon-env
source plone-addon-env/bin/activate

Install Plone and dependencies:


pip install Plone

Creating the Add-on Package

Use mr.bob to scaffold your add-on. Install it first:


pip install mr.bob

Run the Plone add-on template:


mrbob -O my.addon bobtemplates.plone:addon

Answer the prompts. This creates a basic add-on structure.

Understanding the Add-on Structure

Your add-on will have these key files:

  • setup.py - Package metadata
  • src/my/addon/configure.zcml - Zope configuration
  • src/my/addon/profiles - Installation profiles

Learn more in Plone Fundamentals.

Adding Custom Content Type

Let's create a simple content type. Edit content.py:


from plone.dexterity.content import Item
from plone.supermodel import model

class IMyContent(model.Schema):
    """Interface for my custom content type."""

class MyContent(Item):
    """My custom content type implementation."""

Register it in configure.zcml:


<configure
    xmlns="http://namespaces.zope.org/zope"
    xmlns:plone="http://namespaces.plone.org/plone">

    <plone:behavior
        title="My Content"
        provides=".content.IMyContent"
        factory=".content.MyContent"
        />
</configure>

Testing Your Add-on

Install your add-on in a Plone instance:


./bin/develop add my.addon
./bin/buildout

Start Plone and verify your content type appears.

Adding Browser Views

Create a simple view. Add views.py:


from Products.Five.browser import BrowserView

class MyView(BrowserView):
    """Simple browser view."""

    def __call__(self):
        return "Hello from my add-on!"

Register it in ZCML:


<browser:page
    name="my-view"
    for="*"
    class=".views.MyView"
    permission="zope2.View"
    />

Package Your Add-on

Create a distributable package:


python setup.py sdist

This creates a .tar.gz file in dist/ directory.

Conclusion

You've created your first Plone add-on. You learned to scaffold, add content types, and create views. For more, see Plone for Python Developers.

Keep exploring Plone's powerful features. The community is welcoming to new developers.