timelink.notebooks package
Utilities for acessing timelink from Jupyter notebooks.
Submodules
timelink.notebooks.timelink_notebook module
- class timelink.notebooks.timelink_notebook.TimelinkNotebook(project_name=None, project_home=None, db_type=None, db_name=None, drop_if_exists=False, kleio_image=None, kleio_version=None, kleio_token=None, kleio_update=False, postgres_image=None, postgres_version=None, sqlite_dir=None, stop_duplicates=True, **extra_args)[source]
A class to interact with the Timelink system from Jupyter notebooks
Example:
from timelink.notebooks import TimelinkNotebook tln = TimelinkNotebook() tln.print_info()
Create a TimelinkNotebook instance
Setup of Kleio Server and Timelink database is done here.
Several functions are provided to manage the kleio files and access the database.
- Parameters:
project_name – name of the project. Defaults to the name of the parent directory of the current directory.
project_home – directory where kleio server looks for files; defaults to the parent of the current directory.
db_type – type of database (‘sqlite’ or ‘postgres’). Defaults to ‘sqlite’
db_name – name of the database. Defaults to project name, normalized
drop_if_exists – if True, drop the database if it exists. Defaults to False
kleio_image – docker image for kleio server; defaults to ‘timelinkserver/kleio-server’
kleio_version – version of kleio server. Defaults to ‘latest’
kleio_token – start kleio server with this token. Defaults to None (create a new token)
kleio_update – if True, update the kleio server image. Defaults to False
postgres_image – docker image for postgres server. Defaults to ‘postgres’
postgres_version – version of postgres server. Defaults to ‘latest’
sqlite_dir – directory where sqlite databases are. Defaults to ‘../database/sqlite’
stop_duplicates – if True, stop duplicates when importing files. Defaults to True
**extra_args – extra arguments to pass to the TimelinkDatabase object
- Returns:
A TimelinkNotebook object
- get_file_paths(file_spec, rows, column)[source]
Get the file paths from DataFrame of from a string
TODO: #27 add parameter to convert the paths to absolute local paths
- get_import_rpt(file_spec: DataFrame | str, rows=None, match_path=False, **kwargs)[source]
Show the import report for a given file specification
- Parameters:
file_spec – file specification (DataFrame or string) If a DataFrame, it should have the columns ‘path’ and the arguments ‘rows’ must be present
rows – if file_spec is a DataFrane, the row number to show
match_path – if True, the path is used to retrieve the import report; if false the filename is used (default).
**kwargs – extra arguments to pass to the show_import_rpt method in the TimelinkDatabase class
- get_import_status(data_frame=True, **kwargs)[source]
Get the import status of Kleio Files
See:
timelink.api.database.TimelinkDatabase.get_import_status()- Returns:
A dictionary with the status of the import process
- get_imported_files(data_frame=True, **kwargs)[source]
Get the list of imported files in the database
See the get_imported_files method in the TimelinkDatabase class:
timelink.api.database.TimelinkDatabase.get_imported_files()- Parameters:
data_frame – if True, return a pandas DataFrame; otherwise, return a list of dictionaries
**kwargs – extra arguments to pass to the get_imported_files method
- get_kleio_files(data_frame=True, **kwargs)[source]
Get the list of files in the kleio server.
Alias to
timelink.notebooks.TimelinkNotebook.get_import_status()but returns a subset of the columns.
- get_postgres_databases()[source]
Get the list of postgres databases
- Returns:
A list of postgres databases
- get_sqlite_databases(sqlite_dir=None, **kwargs)[source]
Get the list of sqlite databases
- Parameters:
sqlite_dir – directory where the sqlite databases are located
**kwargs – extra arguments to pass to the get_sqlite_databases function
- Returns:
A list of sqlite databases
- get_translation_report(file_spec, rows=None)[source]
Show the translation report for a given file specification
- Parameters:
file_spec – file specification (DataFrame or string) If a DataFrame, it should have the columns ‘rpt_url’ and the arguments ‘rows’ must be present
rows – if file_spec is a DataFrane, the row number of interest
- print_info(show_token=False, show_password=False)[source]
Print information about the TimelinkNotebook object
- Parameters:
show_token – if True, show the token of the kleio server
show_password – if True, show the password of the postgres server
- update_from_sources(**kwargs)[source]
Update the database from a list of sources
see:
timelink.api.database.TimelinkDatabase.update_from_sources()