API: Connection and Base Classes¶
The Digikam Class¶
- class digikamdb.conn.Digikam(database, root_override=None, sql_echo=False)[source]¶
Connection to the Digikam database.
This object connects to the Digikam database using the SQLAlchemy ORM. It generates its own set of classes so that you can use multiple
Digikamobjects to connect to different databases.When initializing a
Digikamobject, you have to supply parameters to specify the database. This is usually done with thedatabaseparameter. It can be one of the following:- The string “digikamrc”:
Use the local Digikam application’s database configuration in
$HOME/.config/digikamrc.- Any other
str: Use the string as database URL in
create_engine().- A SQLAlchemy
Engineobject: Use this object as the database engine
Access to actual data is mostly done through the following properties:
images (class
Images)tags (class
Tags)albums (class
Albums)albumroots (class
AlbumRoots)settings (class
Settings)
- Parameters:
database (str | Engine) – Digikam database.
sql_echo (bool) – Sets the
echooption of SQLAlchemy.root_override (Mapping | None) – Can be used to override the location of album roots in the file system. See `Root Overrides`_ for more information.
- classmethod db_from_config(sql_echo=False)[source]¶
Creates the database connection from
digikamrc.- Returns:
Database connection object
- Raises:
DigikamConfigError – ~/.config/digikamrc cannot be read or interpreted.
- Return type:
- destroy()[source]¶
Clears the object.
This will call
close()anddispose()for the session and engine objects.
- property albumRoots: AlbumRoots¶
The
AlbumRootsobject
- property base: type¶
Base class for table-mapped classes
- property db_version: int¶
The Digikam database version
Added in version 0.2.2.
- property has_tags_nested_sets: bool¶
Indicates if the
Tagstable has nested setsAdded in version 0.2.2.
- property is_mysql: bool¶
Trueif database is MySQL
Base Class for Mapped Tables¶
- class _sqla.DigikamObject(**kwargs)¶
Abstract base class for objects stored in database. Derived from
DeferredReflectionanddeclarative_base().- Parameters:
kwargs (Any)
Digikam Table¶
- class digikamdb.table.DigikamTable(digikam, log_create=True)[source]¶
An abstract base class for table classes
Provides some low-level methods for accessing data:
Members can be accessed by id via
object[id].Class is iterable, returning all rows of the table.
Some internal functionality
- Parameters:
digikam (Digikam) – The “parent”
Digikamobjectlog_create (bool) – Used internally to control logging
- select(*args, **kwargs)[source]¶
Returns the result of a
SELECTon the table.Each positional argument must be a string containing a valid
WHEREclause (withoutWHERE). These clauses are combined withAND. Keyword arguments are used as additionalWHEREclauses checking for equality. For example,select('a > 2', b = 1)will result in aSELECT ... WHERE a>2 AND b=1SQL statement.The result is a
Queryobject that can be refined further. When adding additional conditions, the column names must be prefixed with_.The results can be accessed by iterating over the query or through methods like
all()orone_or_none().- Parameters:
args –
WHEREclauses as textkwargs – Columns to check for equality
- Returns:
The resulting
Queryobject.- Return type:
See also
SQLAlchemy Query
filter()methodSQLAlchemy Query
filter_by()method
Basic Properties¶
- class digikamdb.properties.BasicProperties(parent)[source]¶
Basic class for properties
Instances of this class belong to a Digikam object that has a property (e.g.
properties) that points to the BasicProperties instance. The individual properties can be accessed similarly todictvalues:obj.properties['myprop'] = 'myvalue' # set a property if 'myprop' in obj.properties: # check if a property exists opj.properties.remove('myprop') # remove a property
The class is iterable, yielding all property names, and has a method
items()similar to that ofdict.The number of properties can be found with
len(obj.properties)- Parameters:
parent (DigikamObject) – Object the properties belong to.
- get(prop, default=None)[source]¶
Works similar to
dict.get().- Parameters:
prop (str | int | Sequence)
default (Any | None)
- Return type:
str
- items()[source]¶
Returns the properties as an iterable yielding (key, value) tuples.
- Return type:
Iterable[Tuple]
- remove(prop)[source]¶
Removes the given property.
- Parameters:
prop (str | int | Iterable | None) – Property to remove.
- update(values=None, **kwargs)[source]¶
Updates multiple properties.
This method behaves like
dict.update().- Parameters:
values (Mapping | None) –
dictwith new valueskwargs – Mapping for new values
- property parent: DigikamObject¶
Returns the parent object.
Digikam Settings¶
- class digikamdb.settings.Settings(digikam)[source]¶
Digikam settings class
The Digikam settings can be accessed like a dict:
dk = digikamdb.Digikam() if 'DBVersion' in dk.settings: db_version = dk.settings['DBVersion'] # Get DB version dk.settings['databaseUserImageFormats'] = '-xcf' # Exclude GIMP files for k in dk.settings: # Iterate over settings print(k, '=', dk.settings[k]) for k, v in dk.settings.items(): # Iterate over settings print(k, '=', v)
- Parameters:
digikam (Digikam) – Digikam object
Exceptions¶
Digikam-DB defines several Exceptions for Digikam-specific errors.
- exception digikamdb.exceptions.DigikamError[source]¶
Bases:
ExceptionGeneral Digikam Exception.
All other Digikam-DB exceptions are derived from this class.
- exception digikamdb.exceptions.DigikamConfigError[source]¶
Bases:
DigikamErrorError in Digikam Digikam configuration.
- exception digikamdb.exceptions.DigikamFileError[source]¶
Bases:
DigikamErrorError accessing an image file or album directory.
- exception digikamdb.exceptions.DigikamAssignmentError[source]¶
Bases:
DigikamErrorA value cannot be assigned to a Digikam object.
- exception digikamdb.exceptions.DigikamQueryError[source]¶
Bases:
DigikamErrorError executing database query, or invalid result.
- exception digikamdb.exceptions.DigikamObjectNotFound[source]¶
Bases:
DigikamQueryErrorNo matching object was not found.
- exception digikamdb.exceptions.DigikamMultipleObjectsFound[source]¶
Bases:
DigikamQueryErrorMultiple objects were found when at most one was expected.
- exception digikamdb.exceptions.DigikamDataIntegrityError[source]¶
Bases:
DigikamErrorThe database is in an inconsistent state.