percol icon indicating copy to clipboard operation
percol copied to clipboard

Python API and documentation

Open tkf opened this issue 13 years ago • 3 comments

Hi, thanks for the nice Python app.

It will be nice if there is a documentation to use percol as a Python module. I am requesting this because I am using percol as a Python module for my advanced shell history app called RASH. I want to use percol as Python module as I want to issue request to SQLite DB as you type query in percol.

I have several suggestions:

  • Move most of the code in bin/percol to percol.cli or something like that. Ideally, bin/percol just contains from percol.cli import main; main() (not one-linear, of course ^^). Otherwise, people need to reimplement functions such as load_rc.
  • Some arguments for percol.Percol need to be set even if it is optional. For example, I needed to pass candidates=[].
  • Pass finder instance or add a way to pass arguments for the finder class. I am passing argument by dynamically modifying class attribute. Not cool.
  • Add a way to change appearance of candidates. For example, I want to show "score" for each candidate when searching. It's something like real-to-display / display-to-real in helm/anything. How about allowing any object that have __str__ for collection (so, you need to convert it to strings somewhere)? Module user can get that object by passing some custom actions.

Here is the related part in RASH: https://github.com/tkf/rash/blob/master/rash/interactive_search.py

tkf avatar Feb 09 '13 22:02 tkf

Thanks for the informative request. That's what I've been planning for a long time! (and your RASH seems hot!)

Pass finder instance or add a way to pass arguments for the finder class. I am passing argument by dynamically modifying class attribute. Not cool.

You can reference finder instances by percol.model_candidate.finder and percol.model_action.finder. Any suggestions are welcome If it's not enough.

Add a way to change appearance of candidates.

It would be great. Your suggestion, which permits arbitrary objects with __str__, is pythonic and reasonable. I'll implement it anytime soon.

mooz avatar Feb 10 '13 05:02 mooz

You can reference finder instances by percol.model_candidate.finder and percol.model_action.finder.

Ah, I didn't notice. I think this solves my problem.

tkf avatar Feb 10 '13 12:02 tkf

i am a python newbie and i got a maybe too much basic question, but its hard for me, if i have an array like this: arr = [1, 2, 3, 4] i want to use a direct call to a percol library from my python program, how do i list this array on percol from python?


from percol.finder import *
what.percol.function.list(arr) ?

thanks for your support, percol is my favorite command line interface.

el3ctron avatar Feb 27 '17 04:02 el3ctron