Skip to main content

TiddlyParse allows Python to interact with TiddlyWiki files.

Project description

TiddlyParse allows Python to interact with TiddlyWiki files.

At the moment it handles standalone HTML files, with the two tiddler formats. The first one was used in version up to and including 5.1.23, the second one uses JSON snippets and is in use since 5.2.0.

Points that are currently open but can be added upon interest:

  • Seamlessly interact with a server-side TiddlyWiki and use the REST API in that context
  • Handle encrypted files

Usage

Use the parse method to get a wiki instance returned:

from tiddlyparse import parse
from pathlib import Path

wiki_file = Path('wiki.html')
wiki = parse(file=wiki_file)

This will automatically detect the format and transparently handle this also for saving back.

The number of tiddlers are returned with the len function:

>>> len(wiki)
7

Note that only the root tiddlers are returned. The individual tiddlers contained therein are not currently handled, though that may change.

You can access individual tiddlers using dictionary notation or get:

>>> wiki['$:/isEncrypted']
<tiddlyparse.parser.JsonTiddler object at 0x105a85130>
>>> wiki.get('no such tiddler')

It is also possible to execute simple searches. Any keyword argument to the search function is converted into a query component. If the argument value is True, then all tiddlers that have this attribute defined are returned:

>>> tiddlers = wiki.search(author=True)
>>> tiddlers
[<tiddlyparse.parser.JsonTiddler object at 0x101827e80>, <tiddlyparse.parser.JsonTiddler object at 0x101832130>, <tiddlyparse.parser.JsonTiddler object at 0x101832190>]
>>> [t.title for t in tiddlers]
['$:/core', '$:/themes/tiddlywiki/snowwhite', '$:/themes/tiddlywiki/vanilla']

If it's any string value, then all tiddlers that have this attribute set to exactly this value are returned:

>>> tiddlers = wiki.search(name='Snow White')
>>> [t.title for t in tiddlers]
['$:/themes/tiddlywiki/snowwhite']

The tiddlers are all represented using the Tiddler class (JsonTiddler or DivTiddler more specifically). The tiddler attributes are available as properties are available on those objects:

>>> tiddler = wiki['$:/isEncrypted']
>>> tiddler.text
'no'
>>> tiddler = wiki.get('$:/core')
>>> tiddler.author
'JeremyRuston'

To create or modify a tiddler, use the get_or_create method to first get the tiddler. Then add it to the wiki with add:

>>> tiddler = wiki.get_or_create('Testing TiddlyParse')
>>> tiddler.text = "This is the first ''test'' with TiddlyParse."
>>> tiddler.tags = 'Test TiddlyParse'
>>> wiki.add(tiddler)

To persist the changes, use save:

>>> wiki.save()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tiddlyparse-0.2.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tiddlyparse-0.2.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file tiddlyparse-0.2.0.tar.gz.

File metadata

  • Download URL: tiddlyparse-0.2.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.6 Darwin/22.6.0

File hashes

Hashes for tiddlyparse-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ba351ab3acfce2edb83127104c0d79fb007717cabe2c4897f9958e918be95a21
MD5 5a5ea4b65d2fd0bebfa440fded19c081
BLAKE2b-256 69ba429e769845f2ea29a81f8a5587883247129ef6f8ee4e7e985abb730ad065

See more details on using hashes here.

File details

Details for the file tiddlyparse-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: tiddlyparse-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.6 Darwin/22.6.0

File hashes

Hashes for tiddlyparse-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0752ce0f62d3c6a3d7f9901028294517ca9183bb1a0ee7ac3ff3ef476a0db4a
MD5 516d3c745ff2b55b78f8ba740be49d65
BLAKE2b-256 d3dee31dc93b53c09b0e9907c5fab1ee29319a24f3d1e6d98ddc3440fbe56328

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page