LastGenre - Python Program


Very new to beets, I have a question, hopfully someone can point me in the right direction.
Im trying to run beets lastgenre plugin from a third party python application so I can sort my music by genre’s I can run the plugin just fine on a terminal IE (beet lastgenre) if correct. Although Im trying from a python program something like these two examples.


Ive even tried subcommand
Tried a number of ways in python doing config[‘plugins’][‘lastgenre’] = True
things like that…
so if theres a simple way to run the plugin (lastgenre) from a python program, to get genres. Id be happy to hear… Thank you very much !



Sounds interesting! Since this is not a common thing to do, it would be helpful to see the code you’ve written so far (or a small test program that reflects the important part). Is it available somewhere?


Hey no its not anywhere, but definitely here some of the code ! :slight_smile:

from beets import config
from beets import importer
from beets import plugins
from beets.ui import Subcommand
from beets.plugins import BeetsPlugin
import beets.plugins
from beets.ui import _open_library

class Beets(object):
class AutoImportSession(importer.ImportSession):
def should_resume(self, path):
return True

    def choose_match(self, task):
        return importer.action.ASIS

    def resolve_duplicate(self, task, found_duplicates):

    def choose_item(self, task):
        return importer.action.ASIS

def __init__(self, OUTPUT_DIR):
    config["import"]["autotag"] = True
    config['plugins']['lastgenre'] = True
    config['lastgenre']['auto'] = True
    config["import"]["lastgenre"] = True
    config["import"]["copy"] = False
    config["import"]["move"] = False
    config["import"]["write"] = True
    config["library"] = OUTPUT_DIR
    config["threaded"] = True
    config['lastgenre']['auto'] = True
    self.lib = _open_library(config)

def import_files(self, list_of_paths):

    query = None
    loghandler = None
    self.session = Beets.AutoImportSession(self.lib, loghandler, list_of_paths, query)

def query(self, query=None):
    return self.lib.items(query)

                LIBARY_FILE_NAME = os.path.join(file_music_path, "music.db")
                demo = Beets(LIBARY_FILE_NAME)
                demo.import_files([MUSIC_DIR, inputdir])


See im trying to get it to do (beet lastgenre) in a seperate program… I can worry about calling the files I just dont know how to call the command from beets to it’s plugin lastgenre…

Very little documentation about a third party app, and even less about calling a plugin from it !
Any help at all would be very much appreciated :slight_smile: !!!



Hmm. If what you want is just genre tagging, I wouldn’t set up a whole import pipeline. Instead, just construct an Album or Item object directly and then invoke the plugin.

You could see the tests for the lastgenre plugin, for example, which should also invoke the plugin directly.


Hi, Thanks for your reply
That sounds good where are the tests for lastrgenre plugin, could you link me please?



Thank you for your reply, still working on it, not sure if Im doing this correctly or not.
But from my understanding
How would I invoke the plugin exactly from last genre plugin into what I have shown as code?

Ssssooorry very new to this, and Python as well.

Thank you,
With regards,



Sorry, I don’t know if I can help more—I don’t quite have the bandwidth to write the code. Please update the thread if there are more specific questions we can answer.


I have a question Ill try to be as specific as possible.
Is there a way to auto tag genres with the config file, from
inside python it’ self?

> config[‘lastgenre’][‘auto’] = True

I’ve been reading the documentation, and it seems to go
over really well the plugin system, although it doesnt
have import plugin use plugin or even auto use
plugins. It may just be me, and Ill keep trying and keep
this posted.

I don’t want to run your bandwidth out, however possible.
I do appreciate your help and like your work.

So thank you,



If I were you, I’d start from scratch with an import beetsplug.lastgenre. From there, you can construct a new LastGenrePlugin object. You can use the plugin’s functionality by calling the methods on that object.


Hi Hi!
Its me again having a bit of a problem right now with this line of code, hoping you could help me with it.

for tag in LastGenrePlugin._tags_for(last_obj, config[‘min_weight’].get(int))[:3]:
AttributeError: ‘Album’ object has no attribute ‘_log’

Any ideas, and thank you for your previous help its been great insight!



You’re calling an instance method on a class instead of an instance. You’ll want to construct an object first and call methods on that.


Thank you very much, ill see what I can do !


Hi again,
Ive got a question,
return importer.action.ASIS where could I find more information about this or could you tell me please?
What the ASIS means and what other options are there for it?
Thank you,



It implements the “as is” option I’m the importer prompts, which you can read about in detail in the importer documentation.