input: from typing import Optional
  
  def sql_to_dataframe(sql_query: str, connection) -> Optional[pd.DataFrame]:
      """ Converts a given SQL query into a Python Pandas DataFrame using the provided database connection.
      If the query or connection is invalid, the function returns None.
      >>> sql_to_dataframe("SELECT * FROM book;", conn)
         id   title  author  year
      0   1  'Book1'  'Auth1'  2020
      1   2  'Book2'  'Auth2'  2019
      2   3  'Book3'  'Auth3'  2021
      """
      
      try:
          import pandas as pd
          df = pd.read_sql_query(sql_query, connection)
          return df
      except:
          return None
output:     try:
          import pandas as pd
          df = pd.read_sql_query(sql_query, connection)
          return df
      except:
          return None