Zoviz

Zoviz is an unaffiliated library for accessing and visualizing Zotero data.

Gitlab project: https://gitlab.com/jlogan03/zoviz (includes example.ipynb notebook)

Examples

Visualizing a graph of collaboration

with zoviz.DB() as db:  # Zotero database is discovered automatically
   g = db.build_creator_graph(collection="example")
   zoviz.draw_community_graph(g, edge_color='k')
_images/community_graph.png

Querying the database

with zoviz.DB() as db:
   example_query = \
   """
   SELECT value FROM itemDataValues WHERE valueID IN (
   SELECT valueID FROM itemData WHERE itemID IN (
   SELECT itemID FROM items WHERE itemTypeID IN (
   SELECT itemTypeID FROM itemTypes WHERE typeName IN
   ( 'journalArticle' ) ) ) )
   """

   df = db.query_df(example_query)
   print(df["value"][0])

returns

Cooling topologies for superconducting power systems: II. Long-distance electric transmission

Accessing tables

Because Zotero databases can be assumed to be “small” in computational terms, it’s usually safe to access tables directly. Whenever a table is accessed directly, if it isn’t in memory, it will be queried at that time.

# Three ways to get the itemData table as a pandas DataFrame
with zoviz.DB() as db:
   # The shortest way
   itemData = db.itemData
   # The short way
   itemData = db["itemData"]
   # The long way
   itemData = db.query_df("SELECT * FROM itemData")

Contents

Autodocs

zoviz package

An unaffiliated utility for visualizing Zotero data

Submodules
zoviz.database module

Class for handling zotero.sqlite database connection, queries, and visualization

class zoviz.database.Creator(name, creator_id)[source]

Bases: object

Content-creator data for use as a graph node

class zoviz.database.DB(db_path=None)[source]

Bases: object

Interface layer for zotero.sqlite database. Relies on the assumption that the entire database is small enough to load into memory without issue.

Tables are loaded from disk the first time they are accessed.

build_creator_graph(collection: str) → networkx.classes.multigraph.MultiGraph[source]

Build a graph data structure of collaborative work

Parameters:collection (str) – Zotero Collection name
Returns:MultiGraph with Creator objects as nodes and 1 edge per collaboration
Return type:nx.MultiGraph
close()[source]

Close database connection

load_table(name: str) → pandas.core.frame.DataFrame[source]

Load a whole table from disk

Parameters:name (str) – Name of table
Returns:Table contents
Return type:pd.DataFrame
query_df(query: str) → pandas.core.frame.DataFrame[source]

Return the result of a query as a DataFrame

Parameters:query (str) – String containing SQL query
Returns:DataFrame of result
Return type:pd.DataFrame
query_table_columns(name: str) → list[source]

Get list of column names for a table

Parameters:name (str) – Name of table
Returns:List of columns
Return type:list
zoviz.database.guess_db_path()[source]

Guess location of zotero.sqlite based on operating system

zoviz.database.validate_db_path(db_path: str)[source]

Check if the database file exists

Parameters:db_path (str) – Path to zotero.sqlite
Raises:FileNotFoundError – Raised if database does not exist
zoviz.metadata module

Package metadata

zoviz.visualization module

Visualization functions specialized for Zotero data

zoviz.visualization.draw_community_graph(g: networkx.classes.multigraph.MultiGraph, fig=None, **kwargs) → matplotlib.figure.Figure[source]

A quick, deterministic embedding for the creator graph

Parameters:collection (str) – Zotero Collection name
Returns:figure handle
Return type:plt.Figure
zoviz.visualization.draw_multigraph(g: networkx.classes.multigraph.MultiGraph, pos: dict, radius_mult=0.1, directed=False, **kwargs) → matplotlib.axes._axes.Axes[source]

A way to draw multiple edges per node pair

Parameters:
  • g (nx.MultiGraph) – A multigraph, probably returned by zoviz.DB.build_creator_graph()
  • pos (dict) – networkx layout
  • directed (bool, optional) – Draw arrows?, defaults to False
Returns:

return axis handle

Return type:

plt.Axes