openaq_engine package

Subpackages

Submodules

openaq_engine.main module

openaq_engine.setup module

openaq_engine.setup_environment module

Setup Environment

Tools for connecting to the database.

openaq_engine.setup_environment.connect_to_db(PGPORT=5432)[source]

Context manager for connecting to a PostgreSQL database.

Parameters:

PGPORT (int, optional) – The port number to connect to (default is 5432).

Yields:

conn (SQLAlchemy Connection) – A connection to the PostgreSQL database.

openaq_engine.setup_environment.get_athena_engine()[source]

Creates and returns a SQLAlchemy engine for connecting to AWS Athena.

Returns:

engine – A SQLAlchemy engine connected to AWS Athena.

Return type:

SQLAlchemy Engine

openaq_engine.setup_environment.get_dbengine(PGDATABASE='', PGHOST='', PGPORT=5432, PGPASSWORD='', PGUSER='', DBTYPE='postgresql')[source]

Creates and returns a SQLAlchemy engine for connecting to a PostgreSQL database.

Parameters:
  • PGDATABASE (str) – The name of the database to connect to.

  • PGHOST (str) – The hostname of the database server.

  • PGPORT (int, optional) – The port number to connect to (default is 5432).

  • PGPASSWORD (str) – The password for the database user.

  • PGUSER (str) – The username for the database.

  • DBTYPE (str, optional) – The type of database, default is “postgresql”.

Returns:

engine – A SQLAlchemy engine connected to the specified database.

Return type:

SQLAlchemy Engine

openaq_engine.setup_environment.run_query(query)[source]

Executes a SQL query on the database and returns the result as a pandas DataFrame.

Parameters:

query (str) – The SQL query to execute.

Returns:

data – A DataFrame containing the results of the query.

Return type:

pandas DataFrame

openaq_engine.setup_environment.test_database_connect()[source]

Tests the database connection by running a simple query.

Raises:

AssertionError – If the query returns fewer than 1 row.

Module contents