interact
is a command added to twanager with the 1.3.0
release of TiddlyWeb. When run, as twanager interact
, a Python shell is started with basic TiddlyWeb code loaded. This allows access to the local store and exploration of the Python API.
If your Python includes support for the readline library, then history handling and tab completion is available.
Local variables include:
store
- A reference to the current store object.
Bag
,Recipe
,Tiddler
,Policy
,User
- The classes of the main entities.
Serializer
- The serializer class, making it possible to create a serializer (see example below).
config
- The config dictionary.
environ
- The current
WSGI
environ (mostly empty since there is no web request) control
- A reference to the
tiddlyweb.control
module. web
- A reference to the
tiddlyweb.web.util
module. util
- A reference to the
tiddlyweb.util
module.
The module references allow access to utility methods.
Some examples follow.
Create a Tiddler and serialize it to JSON:
>>> sj = Serializer('json', environ)
>>> x = Tiddler('foobar', 'cow')
>>> x.text = 'hello'
>>> x.tags = ['foo', 'cow']
>>> sj.object = x
>>> '%s' % sj
'{"created": "", "fields": {}, "creator": null, "recipe": null,
"modified": "20121210232622",
"uri": "http://0.0.0.0:8080/bags/cow/tiddlers/foobar",
"bag": "cow", "text": "hello", "title": "foobar", "permissions": [],
"modifier": null, "type": null, "tags": ["foo", "cow"], "revision": 0}'
List all the bags in the store:
>>> bags = store.list_bags()
>>> for bag in bags:
... print bag.name
...
bag0
bag1