Skip to main content

Mirror a Zotero library into a SQL database

Project description

Karboni

Mirror a Zotero library into a SQL database.

Features

  • Fast one-way synchronization from Zotero to a SQL database.
  • Fetch library items, collections, tags, saved searches metadata.
  • Download file attachments.
  • Fetch formatted references in multiple bibliographic styles, for multiple locales.
  • Fetch multiple export formats.
  • Fetch the full text content of items.
  • Fetch the labels of item types, field names and creator types, for multiple locales.
  • Python API for managing synchronization.
  • Command line interface for managing synchronization.
  • Support for a wide range of database systems (through SQLAlchemy).

Python interface

The karboni Python module provides the main entry points, with functions such as initialize() and synchronize().

If you wish to use SQLAlchemy for querying the database, you might want to import models from karboni.database.schema.

Command line interface

To use the command line interface, you must first configure your Zotero credentials in environment variables, or in a .env file. You could copy the included template.env to .env and edit the values.

The required variables are:

  • ZOTERO_LIBRARY_PREFIX
  • ZOTERO_LIBRARY_ID
  • ZOTERO_API_KEY

Optional variables are:

  • KARBONI_DATABASE_URL (defaults to sqlite:///data/karboni/${ZOTERO_LIBRARY_PREFIX}-${ZOTERO_LIBRARY_ID}/library.sqlite)
  • KARBONI_DATA_PATH (defaults to ./data/karboni/${ZOTERO_LIBRARY_PREFIX}-${ZOTERO_LIBRARY_ID}/)

Once the required variables have been set, you may operate Karboni. Some examples below.

Initialize the mirror database (create the tables):

karboni init

Synchronize from Zotero:

karboni sync

List the available commands and general options:

karboni --help

List the options of a given command:

karboni COMMAND --help

Design choices

Here are some of the design choices that have guided the development of Karboni:

  • Perform Zotero API requests and file IO asynchronously to minimize idle time.
  • Use SQLite as the baseline database system, reducing the need for additional dependencies (it's included in the Python standard library), but interface it through SQLAlchemy in order to support other databases as well.
  • Since Karboni itself only needs a few simple database operations, encapsulate SQLAlchemy under a thin abstraction layer to decouple the synchronization process from the database toolkit.
  • Stay close to the Zotero schema. Store data in the JSON format provided by the Zotero API whenever possible, for consistency and better adaptability to future Zotero schema changes. Add SQL columns where they can be useful to the synchronization process or to allow basic queries.
  • Don't fuss too much with database-level referential integrity constraints. Leave that to Zotero. In particular, the keys of parent items and parent collections are not validated (this simplifies the synchronization process).
  • Don't worry about database schema migrations. The database is just a mirror, thus its tables can be wiped when necessary and re-synchronized from Zotero.
  • Synchronization of file attachments is not atomic. If library synchronization finishes but file downloads fail, we accept that and don't rollback the database changes.

Known limitations

  • Database operations are synchronous because SQLAlchemy cannot (at least not easily) share a session between concurrent tasks.
  • During transactions, SQLite locks database access from other threads or processes. When synchronizing from Zotero, Karboni applies all changes in a single transaction (to allow rollback in case of failure), which means the database can remain locked for some time. To ensure availability during synchronization, use a database system that has more advanced locking mechanisms (such as PostgreSQL or MySQL).
  • Python 3.11+ is required (it facilitates exception handling with asynchronous tasks).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

karboni-0.1.0a0.tar.gz (43.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

karboni-0.1.0a0-py3-none-any.whl (48.6 kB view details)

Uploaded Python 3

File details

Details for the file karboni-0.1.0a0.tar.gz.

File metadata

  • Download URL: karboni-0.1.0a0.tar.gz
  • Upload date:
  • Size: 43.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.1 cpython/3.13.8 HTTPX/0.28.1

File hashes

Hashes for karboni-0.1.0a0.tar.gz
Algorithm Hash digest
SHA256 37b7d1ed9f1c25ea7c63e9fc38fe090a08cee7d1bfc54f712c3958a09c77376a
MD5 e0d16d27e4a0b08ad01ad7989dd619ea
BLAKE2b-256 c7daa5418b5bfd80e8be0f68f0608b1bcb067e187dcdea39e14829e1b97c572a

See more details on using hashes here.

File details

Details for the file karboni-0.1.0a0-py3-none-any.whl.

File metadata

  • Download URL: karboni-0.1.0a0-py3-none-any.whl
  • Upload date:
  • Size: 48.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.1 cpython/3.13.8 HTTPX/0.28.1

File hashes

Hashes for karboni-0.1.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 194b161b52d38e5674f19be459d8de0612118d2263ac9964a697de0a330c1b0d
MD5 d21f48bb9dca87e301e70e377c1d550f
BLAKE2b-256 06b1c38fdd7e0e72ea504b4463305f97d69c52ca51eb01bbc9b2ef447437d2c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page