code: def wandb_export_history(
      *,
      run,
      api=None,
      db_file=None,
      db_table=None,
      db_replace: bool = None,
      history_exclude_prefix=None,
      read_page_size=None,
      write_page_size=None,
  ) -> int:
      api = api or wandb.Api()
      db_file = db_file or DB_FILE
      db_table = db_table or "history"
      history_exclude_prefix = history_exclude_prefix or "system/"
      read_page_size = read_page_size or 1000
      write_page_size = write_page_size or 1000
  
      run = api.run(run)
      keys = run.history_keys.get("keys", [])
      if history_exclude_prefix:
          keys = list(
              filter(
                  lambda x: not x.startswith(history_exclude_prefix),
                  keys,
              )
          )
  
      db_file = db_file
      db = sqlite3.connect(db_file)
  
      history = run.scan_history(page_size=read_page_size)
      if_exists = "replace" if db_replace else "fail"
      written = 0
      for index, rows in enumerate(chunk(write_page_size, history)):
          df = pd.DataFrame.from_records(
              rows, **{} if index else dict(columns=keys)
          )
          written += df.to_sql(
              "history",
              con=db,
              index=False,
              if_exists="append" if index else if_exists,
          )
      return written
  
file_path: wandb/tools/wandb_export_history.py
imports: import argparse
  import sqlite3
  from typing import Dict, Iterator, List
  import pandas
  import wandb
label_desc: Use image node_id 2 for calling a global function with example usage: wandb_export_history() and returns: written