ensure_open_sqlite

ensure_open_sqlite(key, *subkeys, url, name=None, force=False, download_kwargs=None)[source]

Ensure and connect to a SQLite database.

Parameters:
  • key (str) – The name of the module. No funny characters. The envvar <key>_HOME where key is uppercased is checked first before using the default home directory.

  • subkeys (str) – A sequence of additional strings to join. If none are given, returns the directory for this module.

  • url (str) – The URL to download.

  • name (Optional[str]) – Overrides the name of the file at the end of the URL, if given. Also useful for URLs that don’t have proper filenames with extensions.

  • force (bool) – Should the download be done again, even if the path already exists? Defaults to false.

  • download_kwargs (Optional[Mapping[str, Any]]) – Keyword arguments to pass through to pystow.utils.download().

Yields:

An instance of sqlite3.Connection from sqlite3.connect()

Example usage: >>> import pystow >>> import pandas as pd >>> url = “https://s3.amazonaws.com/bbop-sqlite/hp.db” >>> sql = “SELECT * FROM entailed_edge LIMIT 10” >>> with pystow.ensure_open_sqlite(“test”, url=url) as conn: >>> df = pd.read_sql(sql, conn)