Under calibre-debug, what is the right way to access the group of fields that I have defined in the GUI under "Look & Feel" --> "Tag Browser -->" "Categories with hierarchical items"? I have tried gprefs and similar fields in various modules, but I don't appear to be hitting it. Thanks!

Thanks for the prompt reply. I am self-taught re Python/sqlite/etc., which means I am great in some areas and woefully deficient in others - which explains why I ask the below:

I read your response to mean accessing attributes of an object "db", but how should I go about accessing/creating this object? I know from the api documentation how to establish a cache object (i.e. from calibre.library import db; db=db('Path to calibre library folder').new_api), but am gathering that this is not what you mean since this db object has no attribute "prefs".

My revised question: is this the best/most efficient way to get this info? I don't have a good feel for how this object is different than the cache object "from calibre.library import db; db=db('Path to calibre library folder').new_api", so would be interested in your thoughts here as well. Thanks for you time once again.

Without the .new_api you get an instance of calibre.db.legacy.LibraryDatabase. Occasionally legacy methods are easier to use, but in my experience not very often.

A "new_api" object is an instance of calibre.db.cache.Cache. Look there for "public" methods, properties, and attributes. For example db.prefs is a method (line 609):

Code:

@read_api
def pref(self, name, default=None):
' Return the value for the specified preference or the value specified as ``default`` if the preference is not set. '
return self.backend.prefs.get(name, default)

Finally, and offered as a hint, in most cases you should specify a default when using .get(). In calibre, preferences can be and often are None. For example,

Code:

db.prefs.get('categories_using_hierarchy')

will return None or a list, meaning you must test it. If you instead use

Very helpful! Understand your point on always using "new_api". I saw the pref method here before, but until today didn't know the specific preference name I should enter to get what I wanted (i.e. 'categories_using_hierarchy'). Appreciate the hint as well - makes sense.

At the risk of overstaying my welcome in this thread, one final clarification: what's the right way to get a list of all possible preference names that I could pass to "db.pref()" such that, in the future, I could determine the calibre name for the specific preference I want? The initial answer above mentions looking at a preferences table - is this something that I would/should do using my new_api db object somehow?

At the risk of overstaying my welcome in this thread, one final clarification: what's the right way to get a list of all possible preference names that I could pass to "db.pref()" such that, in the future, I could determine the calibre name for the specific preference I want? The initial answer above mentions looking at a preferences table - is this something that I would/should do using my new_api db object somehow?

I think you are going down a rat hole with this. There is no way to get a list of "all possible preference names" because the existence of a preference in calibre does not mean that the preference has a value -- is entered into the prefs dict. Looking at the defined preferences only tells you which of them has been set, not which of them could be set. In addition, simply knowing the name does not tell you what it actually means. I think you would be better served by determining if a preference is of interest by examining the GUI and the source code related to what you are interested in.

That said, this snippet will give you the names of all the library-specific preferences. Personally I think it is easier to look at the db using some db explorer (I use SQLiteSpy) because that lets you explore the values of the preferences in addition to the names. And yes, this snippet uses the old API.

Got it! I didn't get that when you initially mentioned looking at the preferences table, you meant using a tool outside of the Calibre api. Understand your point - I agree with looking at source code as the first step. Also appreciate you providing the old API code snippet.

I looked at metadata.db with Sqliteman and found the preferences table just as you mentioned, so I see how I could preference names next time if/as needed. Thanks very much for your helpful replies!