Script Plone from Python#

At the end of this path, you will have a Python script that keeps content on a Plone site in step with a data file, previews its changes, and handles errors.

Try it now#

This script reads demo.plone.org, a public site that resets every night, without logging in.

from plone_client import PloneClient

with PloneClient("https://demo.plone.org") as site:
    for item in site.search.iter(portal_type="Document", limit=3):
        print(item["title"])
uv run --with plone-client demo.py

You need#

  • Python 3.11 or later, and uv.

  • Docker, from the second step on.

  • No Plone knowledge: Get started has what you need.

Follow these steps#

  1. Install plone-client adds plone-client to your project, because the rest of the path needs it.

  2. Your first script is the core of the path: you read a site, change it, and end with a sync from a JSON file.

  3. Content model shows what your script reads and writes, so that your fields and blocks land where you expect.

  4. Handle errors turns the failures of a real site into code paths.

  5. Sync content from an external source takes the tutorial’s script to production.

  6. Migrate content between two sites applies the same ideas to two sites.

Going further#

If something breaks#

Troubleshoot goes from the symptom to the fix.

Before you connect a real site#

  • Log in as a dedicated Plone user with only the permissions the script needs, not admin.

  • Start with read_only=True, which refuses every change before sending it.

  • Pass dry_run=True on the first run that writes, and read client.dry_run_log; see Preview changes and protect a site.

  • Keep the password out of the script: use a profile, or an environment variable with from_env(); see Use the command line in scripts and CI.

  • Catch the exceptions of Exceptions, so that a refused change stops the script instead of half-applying it.