Python analogous for the CLI command

Justus Winter 4winter at informatik.uni-hamburg.de
Thu Apr 18 03:27:21 PDT 2013


Hi Flavius :)

welcome to notmuch :)

Quoting Flavius Aspra (2013-04-18 10:11:37)
> Can you give me some pointers on how to use the python module to get the JSON
> data with notmuch effort, equivalent to the command:
            ^^^^^^^ hehe :)

Ok, here it is:

teythoon at thinkbox ~/tmp % cat flavius.py
import notmuch

db = notmuch.Database()
q = db.create_query('from:Flavius')

for m in q.search_messages():
    print(m)

for t in q.search_threads():
    for m in t.get_toplevel_messages():
        print(m)
teythoon at thinkbox ~/tmp % python3 flavius.py
Flavius Aspra <flavius.as at gmail.com> (inbox lists notmuch signed) (2013-04-18)
Flavius Aspra <flavius.as at gmail.com> (inbox lists notmuch signed) (2013-04-18)

There once was a json encoder that produced something similar to
notmuch show --format=json, but that was there only to be used by a
python version of the notmuch cli binary. That was unmaintained and
apparently unused, I removed it and the json encoder some time ago.

If you absolutely need json, put the result in some suitable data
structure and use pythons json module to encode it.

> Some key classes and methods would be helpful. From the documentation of the
> python code, I couldn't find indications about any of the parameters like
> --entire-thread and --format.

Have you seen http://notmuch.readthedocs.org ?

Also, if you want to see some code that uses the python bindings, go
to github.com/pazz/alot (nice MUA written in python, but it's huge) or
github.com/teythoon/afew (tagging solution, tiny codebase compared to
alot).

Good luck :)
Justus

btw: cool name ;)


More information about the notmuch mailing list