unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Justus Winter <4winter@informatik.uni-hamburg.de>
To: Flavius Aspra <flavius.as@gmail.com>,  notmuch@notmuchmail.org
Subject: Re: Python analogous for the CLI command
Date: Thu, 18 Apr 2013 12:27:21 +0200	[thread overview]
Message-ID: <20130418102721.10489.1439@thinkbox.jade-hamburg.de> (raw)
In-Reply-To: <20130418081137.GA598@evolution>

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@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@thinkbox ~/tmp % python3 flavius.py
Flavius Aspra <flavius.as@gmail.com> (inbox lists notmuch signed) (2013-04-18)
Flavius Aspra <flavius.as@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 ;)

      parent reply	other threads:[~2013-04-18 10:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-18  8:11 Python analogous for the CLI command Flavius Aspra
2013-04-18 10:26 ` David Bremner
2013-04-18 10:27 ` Justus Winter [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130418102721.10489.1439@thinkbox.jade-hamburg.de \
    --to=4winter@informatik.uni-hamburg.de \
    --cc=flavius.as@gmail.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).