This package provides session support.
Zope3 Session Implementation
Overview
Sessions allow us to fake state over a stateless protocol - HTTP. We do this by having a unique identifier stored across multiple HTTP requests, be it a cookie or some id mangled into the URL.
The IClientIdManager Utility provides this unique id. It is responsible for propagating this id so that future requests from the client get the same id (eg. by setting an HTTP cookie). (Note that this, and all interfaces, are imported from this package for demonstration purposes only. They have been moved to zope.session.interfaces) This utility is used when we adapt the request to the unique client id:
>>> from zope.app.session.interfaces import IClientId >>> IClientId <InterfaceClass zope.session.interfaces.IClientId> >>> client_id = IClientId(request)
The ISession adapter gives us a mapping that can be used to store and retrieve session data. A unique key (the package id) is used to avoid namespace clashes:
>>> from zope.app.session.interfaces import ISession >>> pkg_id = 'products.foo' >>> session = ISession(request)[pkg_id] >>> session['color'] = 'red'>>> session2 = ISession(request)['products.bar'] >>> session2['color'] = 'blue'>>> session['color'] 'red' >>> session2['color'] 'blue'
Data Storage
The actual data is stored in an ISessionDataContainer utility. ISession chooses which ISessionDataContainer should be used by looking up as a named utility using the package id. This allows the site administrator to configure where the session data is actually stored by adding a registration for desired ISessionDataContainer with the correct name.
>>> from zope.app.session.interfaces import ISessionDataContainer >>> from zope.component import getUtility >>> sdc = getUtility(ISessionDataContainer, pkg_id) >>> sdc[client_id][pkg_id] is session True >>> sdc[client_id][pkg_id]['color'] 'red'
If no ISessionDataContainer utility can be located by name using the package id, then the unnamed ISessionDataContainer utility is used as a fallback. An unnamed ISessionDataContainer is automatically created for you, which may replaced with a different implementation if desired.
>>> ISession(request)['unknown'] \ ... is getUtility(ISessionDataContainer)[client_id]['unknown'] True
The ISessionDataContainer contains ISessionData objects, and ISessionData objects in turn contain ISessionPkgData objects. You should never need to know this unless you are writing administrative views for the session machinery.
>>> from zope.app.session.interfaces import ISessionData, ISessionPkgData >>> ISessionData.providedBy(sdc[client_id]) True >>> ISessionPkgData.providedBy(sdc[client_id][pkg_id]) True
The ISessionDataContainer is responsible for expiring session data. The expiry time can be configured by settings its timeout attribute.
>>> sdc.timeout = 1200 # 1200 seconds or 20 minutes
Restrictions
Data stored in the session must be persistent or picklable.
>>> class NoPickle(object):
... def __getstate__(self):
... raise TypeError("Cannot serialize")
>>> session['oops'] = NoPickle()
>>> import transaction
>>> transaction.commit()
Traceback (most recent call last):
...
TypeError: Cannot serialize
Page Templates
Session data may be accessed in page template documents using TALES:
<span tal:content="request/session:products.foo/color | default"> green </span>or:
<div tal:define="session request/session:products.foo"> <script type="text/server-python"> try: session['count'] += 1 except KeyError: session['count'] = 1 </script> <span tal:content="session/count" /> </div>
CHANGES
6.0 (2025-09-12)
Replace pkg_resources namespace with PEP 420 native namespace.
5.1 (2025-09-04)
Add support for Python 3.12, 3.13.
Drop support for Python 3.7, 3.8.
5.0 (2023-02-10)
Drop support for Python 2.7, 3.5, 3.6.
Add support for Python 3.8, 3.9, 3.10, 3.11.
4.1.0 (2018-10-22)
Add support for Python 3.7.
4.0.0 (2017-05-29)
Add support for Python 3.4, 3.5, 3.6 and PyPy.
Remove dependency on ZODB3 and other packages that are not used by this package, leaving behind only zope.session. Packages that are used during testing are now test dependencies.
3.6.2 (2010-09-01)
Remove undeclared dependency on zope.deferredimport.
3.6.1 (2010-02-06)
Include meta.zcml from zope.securitypolicy
3.6.0 (2009-02-01)
Use zope.site instead of zope.app.folder in tests.
3.5.2 (2009-01-27)
Fixed tearDown-Error in tests.
3.5.1 (2007-10-31)
Resolve ZopeSecurityPolicy deprecation warning.
3.5.0 (2007-09-27)
A release to override an untagged, unreasoned dev release in download.zope.org/distribution.
3.4.3 (2007-09-27)
Fix package meta-data.
3.4.2 (2007-09-24)
rebumped to replace faulty egg
added missing dependecy to zope.session
3.4.1 (2007-09-24)
Added missing files to egg distribution
3.4.0 (2007-09-24)
Initial documented release
Release files for zope.app.session 6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| zope_app_session-6.0.tar.gz | 14.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| zope_app_session-6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.1 kB
Release files / zope_app_session-6.0.tar.gz
| Download URL | zope_app_session-6.0.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
615887264619af3a4db1487346690cd55c568f490d2fa17b33de4d110a14a5b4
|
|
BLAKE2b-256 checksum How to use checksums |
d039e49bce594672d7fe0a30802298835b12409e0a2f33e816fc5717086ed0ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|
Release files / zope_app_session-6.0-py3-none-any.whl
| Download URL | zope_app_session-6.0-py3-none-any.whl |
|---|---|
| Size | 14.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52adc6d9e5632837956c54bc8bde19c63166fd1127f9c2e13571fd80baa57d76
|
|
BLAKE2b-256 checksum How to use checksums |
cb9e9aca7430764da93573302c1821f4ab21250af952ce8518c5f0b86bb2cb4e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|