API reference¶
dawgtools¶
Tools for DAWG queries and data processing
This script is intended to be run using uv (https://github.com/astral-sh/uv); follow instructions to install if you don’t have it already. Recommended method for macos and linux is
curl -LsSf https://astral.sh/uv/install.sh | sh
dawgtools.main¶
Assembles subcommands and provides top-level script.
dawgtools.db¶
- dawgtools.db.as_dicts(headers: list, rows: list)[source]¶
Converts a list of rows and headers into a list of dictionaries
- dawgtools.db.create_and_load_temp_table(cursor, sql_cmd: str, rows: list)[source]¶
Create and load a temporary table using the provided schema and data files. Rows is a list of dicts.
- dawgtools.db.render_template(template: str, params: dict) tuple[str, list][source]¶
Renders a query template that uses a combination of python string formatting directives and jinja2 expressions using the given parameters. Returns a tuple of the modified template with “?” placeholders and a list of positional parameters.
- dawgtools.db.sql_query(query: str, params: dict | None = None, callback: LambdaType | None = None) tuple[list, list][source]¶
Executes a SQL query using the given parameters.
Uses jinjasql to render the query and perform parameter substitution. Optional callable object ‘callback’ with a single argument ‘cursor’ will be executed before the query.
Returns a tuple (headers, rows)
dawgtools.utils¶
- class dawgtools.utils.MyJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]¶
- default(obj)[source]¶
Implement this method in a subclass such that it returns a serializable object for
o, or calls the base implementation (to raise aTypeError).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return super().default(o)