Best way to query DB from a python script

Hi there!
What’s the best way to query DB from a python script in terms of speed and simplicity?
As fas as I understand there is interface provided by classes mentioned in docs but it’s seems to me like overkill for a simple query.
I used to use this snippet but it seems like it’s not working anymore for some reason:

libpath = os.path.expanduser('~/.beet/musiclibrary.db')
lib = beets.library.Library(libpath)
lib.albums(query)

I’ve figured it out. The correct import string is

from beets import library