Skip to main content

orgparse - Emacs org-mode parser in Python

Project description

Install

pip install orgparse

Usage

There are pretty extensive doctests if you’re interested in some specific method. Otherwise here are some example snippets:

Load org node

from orgparse import load, loads

load('PATH/TO/FILE.org')
load(file_like_object)

loads('''
* This is org-mode contents
  You can load org object from string.
** Second header
''')

Traverse org tree

>>> root = loads('''
... * Heading 1
... ** Heading 2
... *** Heading 3
... ''')
>>> for node in root[1:]:  # [1:] for skipping root itself
...     print(node)
* Heading 1
** Heading 2
*** Heading 3
>>> h1 = root.children[0]
>>> h2 = h1.children[0]
>>> h3 = h2.children[0]
>>> print(h1)
* Heading 1
>>> print(h2)
** Heading 2
>>> print(h3)
*** Heading 3
>>> print(h2.get_parent())
* Heading 1
>>> print(h3.get_parent(max_level=1))
* Heading 1

Accessing node attributes

>>> root = loads('''
... * DONE Heading          :TAG:
...   CLOSED: [2012-02-26 Sun 21:15] SCHEDULED: <2012-02-26 Sun>
...   CLOCK: [2012-02-26 Sun 21:10]--[2012-02-26 Sun 21:15] =>  0:05
...   :PROPERTIES:
...   :Effort:   1:00
...   :OtherProperty:   some text
...   :END:
...   Body texts...
... ''')
>>> node = root.children[0]
>>> node.heading
'Heading'
>>> node.scheduled
OrgDateScheduled((2012, 2, 26))
>>> node.closed
OrgDateClosed((2012, 2, 26, 21, 15, 0))
>>> node.clock
[OrgDateClock((2012, 2, 26, 21, 10, 0), (2012, 2, 26, 21, 15, 0))]
>>> bool(node.deadline)   # it is not specified
False
>>> node.tags == set(['TAG'])
True
>>> node.get_property('Effort')
60
>>> node.get_property('UndefinedProperty')  # returns None
>>> node.get_property('OtherProperty')
'some text'
>>> node.body
'  Body texts...'

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

orgparse-0.3.1.tar.gz (36.3 kB view details)

Uploaded Source

Built Distribution

orgparse-0.3.1-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file orgparse-0.3.1.tar.gz.

File metadata

  • Download URL: orgparse-0.3.1.tar.gz
  • Upload date:
  • Size: 36.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for orgparse-0.3.1.tar.gz
Algorithm Hash digest
SHA256 860e6fbb9a67b742baa792e60f8cc18522e9789c065d26821c02285d5fc104af
MD5 6ba5bee0621b140f3063400e3045355b
BLAKE2b-256 7facb38fb9a3f559fbc06ffe7f1ce4c418de5ae3eb5333eda554bfb8bb017592

See more details on using hashes here.

File details

Details for the file orgparse-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: orgparse-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 34.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.12

File hashes

Hashes for orgparse-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 41a8327958d2293e42b1e96c2e935d413693bf9619026f6a941a1e33befaafd4
MD5 c8f4e7b3bb97dc30587a69750bbd55df
BLAKE2b-256 00cbc7586d644a672b2f3dff996b0567c1fea98aa93041f9e2000ba38f63dab6

See more details on using hashes here.

Supported by

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