Registry / web-framework / zope-publisher

zope-publisher

JSON →
library8.0pypypi✓ verified 85d ago

The Zope publisher publishes Python objects on the web. It is a core component of the Zope application server and related frameworks, responsible for dispatching HTTP requests to Python objects and generating responses. As of version 8.0, it supports Python 3.9+ and maintains its role in the Zope ecosystem as a low-level building block for web applications.

pip install zope.publisher
INSTALL
IMPORT
SIG · ZOPE-PUBLISHER
Z
zope-publisher
web-frameworkpythonv8.0
Install
3.7s avg
Import
293ms
Disk
36MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.305s · 33.1MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.7s · import 0.281s · 34MB
36MB installed
● package 36MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

HTTPRequest
from zope.publisher.http import HTTPRequest
from zope.publisher import HTTPRequest
HTTPRequest and HTTPResponse are located in the `http` submodule.
HTTPResponse
from zope.publisher.http import HTTPResponse
from zope.publisher import HTTPResponse
HTTPRequest and HTTPResponse are located in the `http` submodule.
IPublisher
from zope.publisher.interfaces import IPublisher
Zope components are heavily interface-driven, often found in the `interfaces` submodule.

This quickstart demonstrates how to create and interact with `HTTPRequest` and `HTTPResponse` objects, which are the fundamental data structures `zope.publisher` operates on. It shows how to simulate a WSGI environment, access request properties like URL, method, and headers, and set response status, headers, and body. This is crucial for understanding how data flows through the Zope publishing process.

from io import BytesIO from zope.publisher.http import HTTPRequest, HTTPResponse # Simulate a WSGI-like environment for the request request_environ = { 'REQUEST_METHOD': 'GET', 'PATH_INFO': '/my/path', 'QUERY_STRING': 'param1=value1&param2=value2', 'SERVER_NAME': 'localhost', 'SERVER_PORT': '8080', 'wsgi.input': BytesIO(b''), # For GET, body is usually empty 'wsgi.url_scheme': 'http', 'HTTP_HOST': 'localhost:8080', 'CONTENT_TYPE': 'text/plain; charset=utf-8', } # Create a request object # The first argument (input_stream) can be a BytesIO or similar for POST bodies request = HTTPRequest(BytesIO(b''), request_environ) # Create a response object response = HTTPResponse() # --- Interact with the Request --- print(f"Request URL: {request.getURL()}") print(f"Request Method: {request.method}") print(f"Path Info: {request.getURL('PATH_INFO')}") print(f"Query parameters (combined form): {request.form}") print(f"Request header 'Host': {request.get('HTTP_HOST')}") # --- Interact with the Response --- response.setStatus(200) response.setHeader('Content-Type', 'text/html; charset=utf-8') response.setBody('<h1>Hello from Zope Publisher!</h1>') print(f"\nResponse Status: {response.getStatus()}") print(f"Response Header 'Content-Type': {response.getHeader('Content-Type')}") print(f"Response Body: {response.consumeBody().decode('utf-8')}")
Debug
Known issues
breakingPython 2 support was dropped as of `zope.publisher` 5.0. All subsequent versions, including 8.0, are Python 3.x only. Code written for Python 2 will not run on recent versions.
fix
Migrate your application to Python 3.9+ and ensure all dependencies are Python 3 compatible. Review `__unicode__`, `str`, `bytes` usage, and update import paths if necessary.
affects: >=5.0
gotcha`zope.publisher` is a low-level component designed for the Zope Component Architecture (ZCA). It is not a standalone web framework like Flask or FastAPI. Direct usage for simple web apps is often overly complex and requires manual setup of interfaces, adapters, and traversers.
fix
If you are building a full web application, consider using a higher-level framework built on Zope (e.g., Zope, Grok, Plone) or a different Python web framework. Use `zope.publisher` directly only if you understand ZCA and need to customize the core publishing mechanics.
affects: All versions
gotchaZope packages are tightly coupled. Incorrect versions of other `zope.*` dependencies can lead to runtime errors or unexpected behavior. This is especially true for `zope.interface`, `zope.traversing`, and `zope.security`.
fix
Always install `zope.publisher` and other `zope.*` packages from a consistent source (e.g., PyPI with a `requirements.txt`) and ensure compatible versions. Check the `install_requires` in `setup.cfg` or `pyproject.toml` on GitHub for explicit dependency version ranges.
affects: All versions
Errors
Common errors & fixes
TypeError: Can't adapt <your_object> to zope.publisher.interfaces.IRequest
The object you are passing as a request to a Zope publisher function (or related component) does not implement the `IRequest` interface, or no suitable adapter is registered for it.
fix
Ensure your request object is an instance of `zope.publisher.http.HTTPRequest` or `zope.publisher.browser.BrowserRequest` (for browser contexts), or explicitly implements `zope.publisher.interfaces.IRequest` and its sub-interfaces via `zope.interface.implementer`.
ImportError: cannot import name 'HTTPRequest' from 'zope.publisher'
You are trying to import `HTTPRequest` (or `HTTPResponse`) directly from the top-level `zope.publisher` package.
fix
The `HTTPRequest` and `HTTPResponse` classes are located in the `zope.publisher.http` submodule. Correct your import statement to `from zope.publisher.http import HTTPRequest`.
AttributeError: 'HTTPRequest' object has no attribute 'form' or 'POST' data is missing.
When handling POST requests, `request.form` combines query string parameters and POST body data. If `wsgi.input` (the stream for the request body) was not correctly provided or the `CONTENT_TYPE` was incorrect, POST data might not be parsed.
fix
For POST requests, ensure the `request_environ['wsgi.input']` is a file-like object containing the raw request body bytes, and `request_environ['CONTENT_TYPE']` is set appropriately (e.g., `application/x-www-form-urlencoded` or `multipart/form-data`) so `HTTPRequest` can parse it.
Upgrade
Version history
8.0latest on PyPI · released Sep 12, 2025
Audit
Dependencies
zope.interfacerequiredCore Zope component, widely used for defining interfaces and adapting objects.
zope.traversingrequiredUsed for hierarchical object traversal, a fundamental aspect of Zope's URL dispatch.
zope.securityrequiredProvides security concepts for Zope, often integrated with publishing decisions.
Agent activity
49 hits · last 30 days
node
42
OpenAI (training)
1
Resources
zope-publisher — pip install zope-publisher · libregistry